Blog Post

Educator Developer Blog
2 MIN READ

Connecting a BBC micro:bit to the internet

Jim Bennett's avatar
Jim Bennett
Icon for Microsoft rankMicrosoft
Jul 16, 2020

The BBC micro:bit is a fantastic little device. It's small, relatively cheap for a device of its capabilities, has coding tools for developers of all abilities, and has a huge ecosystem of tutorials and projects to do. Young kids use them to code with block-based coding with Microsoft MakeCode, older kids will use Python or JavaScript in MakeCode. They have some sensors and LEDs built in, and you can connect to a whole ecosystem of add-ons from sensors to robots. 

 

A BBC micro:bit

What it can't do is connect to the internet. At least not directly...

 

I recently put together a 'smart garden ornament' project as part of our JulyOT month of IoT - the idea being to add sensors to bird boxes, gnomes and other such garden ornaments and bring this sensor data together in an on-line dashboard using IoT Central. This project is designed for families or schools to work on together, gathering data from your neighborhood or school. These sensors would be powered by BBC micro:bits and coded using blocks. The problem came with getting this data to the cloud.

 

My solution to this took advantage of two things - the radio and the USB connection. The micro:bit has a radio that can broadcast data to other micro:bits in the vicinity (the range in clear air is about 70m). It also has a USB port that can not only be used for power and programming, but you can also send data along it.

 

This means I can connect a micro:bit to a device with an internet connection (such as a Raspberry Pi) via USB and send messages from the micro:bit to the Pi. The Pi then listens on the serial port for the messages, then sends them on to IoT Central. This forms my central 'Hub'.

 

My sensor micro:bits then need to send radio messages with the data they want to send to the cloud, these are detected by the 'Hub' micro:bit, routed through the Pi and send to IoT Central.

 

 

There is a size limit on radio messages of 19 characters. This meant I had to send encoded messages - using things like a single character for the telemetry type (e.g. 't' for temperature) and a single character for the device ID. The Pi then decodes these to the actual values and sends them on.

 

You can read more on how I did this, see the code and learn how to build this yourself by checking out the project on GitHub:

 

github.com/jimbobbennett/smart-garden-ornaments 

 

 

Updated Jul 16, 2020
Version 2.0
No CommentsBe the first to comment