Micro:bit Extensions: Add extra sensors and devices

I have been using the BBC Micro:bit modules (~$20) with our kids to teach them basic hardware and software. The platform offers a block programming interface (very much like Scratch) and Python programming. The interesting thing is that the interface will toggle seamlessly between the two programming languages.

To add functionality to your projects Micro:bit supports extensions. This feature allows Arduino and Raspberry Pi sensors and devices to be connected to the basic module.

In this blog I wanted to:

  • Show a extensions example with deviices that are not directly available in the basic list
  • Comment on some limitations
  • Document how to add Micro:bit parts in Fritzing wire drawing tool

An Extension Example

Use the Extension menu item to add a new set of functionality to your Micro:bit’s project.

For this example I wanted to use some devices/sensors that I was using on my Arduino projects. These devices included:

It is important to note that the extension may not be readily available from the Microbit web page. For my project I did an Internet search to find the required github links. Once you have the URL it can be pasted into the Extension’s page:

Below is a picture of the Micro:bit with the three added devices

The Micro:bit logic used an on_start block to setup the pins for the TM1637 4-digit display, and initialize the OLED display.

The forever block:

  • queried the DHT11 sensor (on Pin 0)
  • showed the humidity on the Micro:bit display
  • showed the temperature on the TM1637 display
  • showed both the temperature and humidity on the 0.91″ OLED
  • cycled every 5 seconds

The block code can be viewed (or edited)in Python:

"""

Devices:

DHT11 Temperature/Humidity Sensor 

TM1637 4-Digit Display 

I2C 9.91" OLED Display

Show Temperature on TM1637

Show Humidity on Microbit screen

Show both Temperature and Humidity on the the OLED

"""
tm = TM1637.create(DigitalPin.P13, DigitalPin.P14, 7, 4)
MuseOLED.init()

def on_forever():
    dht11_dht22.query_data(DHTtype.DHT11, DigitalPin.P0, True, False, True)
    basic.show_string("H: " + str(dht11_dht22.read_data(dataType.HUMIDITY)) + " %")
    tm.show_number(dht11_dht22.read_data(dataType.TEMPERATURE))
    MuseOLED.clear()
    MuseOLED.write_string("Temperature: " + str(dht11_dht22.read_data(dataType.TEMPERATURE)) + " C")
    MuseOLED.new_line()
    MuseOLED.write_string("Humidity: " + str(dht11_dht22.read_data(dataType.HUMIDITY)) + " %")
    basic.pause(5000)
basic.forever(on_forever)

Limitations

Some of the limitations that I found were:

  • Not all Arduino sensors and devices were supported
  • Not all Arduino functionality is available with Micro:Bit. For example fonts on OLED devices.
  • Finding the correct extension can be tricky. For example searching 0.91 OLED doesn’t return any hits.
  • Some devices were supported in software, however they required 5V. A good example of this is the 2×16 LCD display

Documenting Wiring in Fritzing

Fritzing is an excellent free tool for wiring drawings (Note: for some platforms a donation might be required).

To add some Micro:bit parts to Fritzing see:

Once a parts file is downloaded it is imported into a “My Parts” grouping.

Summary

By adding extension you can greatly extend the usability of Micro:bits.

I found that for many simple projects block programming was quicker to create than Python, but it nice that the Python code gets autogenerated.