T3W1: Micro:bit and MakeCode
Welcome to the Lowell STEMapalooza elective class, Term 3! For the first class we will dive in to learning how to program a micro:bit microcontroller board using MakeCode, a visual programming language. Everyone will get a board, which can plug in to your Chromebook over USB. The boards serve as the brains for a small two-wheeled robot which we will introduce next week.
The micro:bit board is small but it packs in a bunch of outputs and sensors, so you can do interesting stuff without needing to hook anything else up.
Here is a picture of the front of the board:
The front has a 5x5 array of red LEDs and two button switches (A and B) for program inputs. The micro:bit logo is also touch sensitive for a third user input. The bottom of the board has a row of connections that will allow us to control a two-wheeled robot module. It also has bigger holes for putting together circuits with alligator clips.
The back of the board has all the circuitry, which is labelled to show some of the features:
From top to bottom there is:
USB port for power and data
Connector for battery power
CPU with Bluetooth Low Energy radio and antenna
Accelerometer for tilt and motion sensing
Compass for magnetic field sensing
When you first plug in a new micro:bit board it will run a demo program to show off some features. Here is information on the "out of box experience" program that runs. You can download the program and save it to your board if it has been overwritten. Follow the instructions below to save the .hex file to your micro:bit board.
We will be programming our micro:bit boards with MakeCode, which is easy to learn but has some powerful and convenient features. MakeCode is a visual programming language like Scratch that is developed by Microsoft and lets you run your programs on a bunch of different microcontroller boards. MakeCode lets you write programs by arranging graphical blocks instead of typing program code into a text editor. It includes an on-screen emulator of the device you are working with so you can try out your code before downloading it to the device.
The right side of the MakeCode window holds your program code diagram. The column of blocks in the middle holds the statements and functions you can add to your code. The section on the left is an emulator for your micro:bit board that lets you test and debug your programs before they get downloaded to the real hardware. At the bottom of the window, the Download button lets you send your program to the micro:bit board.
To download a MakeCode program to your micro:bit board, first make sure the board is connected to your Chromebook using a USB cable. The micro:bit board should show up as a flash disk drive called "MICROBIT" when it is plugged in. When you first plug it in you might get notifications about a "Removable device detected". You can dismiss the notification by clicking on the "X", or you can open the ChromeOS Files app to see what is in the micro:bit flash memory.
To start the download, press the pink [Download] button at the bottom of the MakeCode window. ChromeOS will automatically save it in your Downloads folder on the Chromebook. To install the program on the micro:bit board you need to open the ChromeOS file browser and drag the file you just downloaded (you can find it in the "Recents" tab if needed) onto the MICROBIT drive listed at the bottom left. Dragging the file onto the MICROBIT drive will automatically download it to the micro:bit board. You should see the yellow-green LED flashing as the program is transferred. Once it's done the board will start running your program.
The micro:bit website has information on using WebUSB to download programs directly to the micro:bit from MakeCode. I can't test this in advance but we will try it in class, it could make downloading programs much easier!
For the rest of the class time, try running some of the MakeCode tutorials - they will step you through the features and menus of the MakeCode environment. In the MakeCode home page, look under the "My Projects" section for the "Tutorials" section, and click on the first project called "Flashing Heart".
The tutorials are pretty short so you should be able to do a bunch during class time. The goal is to get familiar with the MakeCode environment and learn how to transfer your programs to it.
Project: Graphical Dice
If you have time, try a micro:bit project to make an electronic dice (or die) that when shaken will pick a random number and display it as spots lit up on the LED matrix: