Print

Programming Your Hummingbird with MicroBlocks

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 creating projects with the Hummingbird Bit!

Programming Language

MicroBlocks

Subjects

Programming Tutorials

Grades

4-5, 6-8, 9-12

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 Bit. Connect the Bit to power (battery pack or AC power adapter), and connect the micro:bit to the computer with the USB cable.

Next, open MicroBlocks. Click the Connect button at the top of the screen.

Click on the serial port of the Hummingbird Bit. If you see multiple serial ports, it may be helpful to unplug all USB devices except the Bit.

If you haven’t used MicroBlocks before with this micro:bit, you will be asked to install MicroBlocks on the micro:bit. Click Yes. If you are using a Chromebook, this prompt may not appear. Click with two fingers to the left of the Connect button and select install MicroBlocks on board.

Click BBC micro:bit and wait approximately 30 seconds for MicroBlocks to be installed. 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 drag 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 Hummingbird.ulib. Then click Okay.

 

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. Also, to change your program, you will need to reconnect the USB cord and click Connect in MicroBlocks.

 

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 below. 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!