MicroBlocks is a free, Scratch-like programming language specifically designed for microcontrollers. With MicroBlocks, scripts run immediately right on the micro:bit without downloading, which means you can explore blocks and easily test your code.  The code continues to run when the micro:bit is disconnected from the computer, making MicroBlocks perfect for for creating projects with the Hummingbird Bit!

Setup

To use MicroBlocks with the Hummingbird Bit, you will need a computer – Windows, Mac, Chromebooks, and Linux are all supported. Start by downloading and installing MicroBlocks from this page.

Insert a micro:bit into the Hummingbird and connect the micro:bit to the computer with the USB cable.

Next, open MicroBlocks. Click the Settings icon and choose update firmware on board. Choose OK when MicroBlocks asks you for permission. Your computer may pop up a window that says the micro:bit has been disconnected. Don’t worry, this is normal.

If you are on a Chromebook, the app cannot install the file automatically. Follow the instructions in the app to download the file onto your micro:bit and connect.

Once MicroBlocks has been installed on the micro:bit and your Hummingbird is connected, you will see a green circle by the Connect button.

Next, click the + sign by Libraries and choose [] Other. Select Hummingbird.ulib and then click Open.

Now you will see a Hummingbird menu in MicroBlocks that contains the blocks you will use to control the Hummingbird.

Using MicroBlocks

To try out MicroBlocks, connect a single color LED to LEDS port 1 on the Hummingbird. The colored wire should be connected to ‘+’ and the black to ‘-.’

In MicroBlocks, you can click on blocks to run them, just like you can in Scratch. For example, drag a Hummingbird LED block into the work area and set the % parameter to 100. if you tap on this block, the LED that you connected will light up.

As you write programs, they are automatically downloaded to the micro:bit. As an example, this program makes the LED blink 10 times when button A on the micro:bit is pressed. All the yellow blocks can be found on the Control menu. Run this program once, and then disconnect the USB cord from the micro:bit. You can still press button A to run the program! Please note that the Hummingbird still needs power, so it will need to be plugged in to the battery pack or power adapter.

To change your program, reconnect the USB cord. Make sure that the Connect icon turns green in MicroBlocks to indicate that the robot is connected.

Hummingbird Blocks

The table below contains brief descriptions of all the Hummingbird blocks in MicroBlocks. You can also use the blocks on the Output and Input menus to write programs that use the LEDs and sensors of the micro:bit in the Hummingbird. Don’t use the blocks on the Pins menu when writing programs for the Hummingbird. The pins are used by the Hummingbird, so these blocks may cause unexpected behavior.

Hummingbird Block Description
Sets a single color LED on LEDS port 1, 2, or 3 to a brightness value from 0% to 100%.
Sets a tri-color LED on TRI-COLOR port 1 or 2 to the color specified by red, green, and blue brightness values. The values range from 0% to 100%.
Sets a position servo on SERVOS port 1, 2, 3, or 4 to an angle from 0° to 180°.
Sets a rotation servo on SERVOS port 1, 2, 3, or 4 to a rotation speed from -100% to 100%.
Reads the value of the sensor on SENSORS port 1, 2, or 3. Readings for the distance sensor are given in cm. All other readings range from 0 to 100 (no units).
Reads the value of the battery in milliVolts. Power to servos may shut off at values below 4200 mV.

Example Program

Since programs written in MicroBlocks are automatically downloaded to the micro:bit, it is an excellent choice for creating mobile robots, robots that can be disconnected from the computer to roam their environment. Try building a rover to use with MicroBlocks!

To create a basic program to move and avoid obstacles, use the distance sensor to detect when the rover is near a wall or another obstacle. If the rover detects an obstacle, it should back up and turn. Otherwise, the rover should drive forward. Basic code for this is shown here. Note that two rotation servos on the rover point in opposite directions. This means that to move the rover forward, the two servos must move in opposite directions.

After you have a basic rover program working, try adding headlights and making your driver steer. Then modify your rover and program to try something new!