BBC micro:bit with Edge Connector Breakout Board (centre) connected to a Sigfox Wisol Breakout Board (right) powered by two AAA batteries (left). The PCB Antenna for Sigfox (920 MHz for Asia) is at the bottom edge of the box.

Connect BBC micro:bit to Sigfox

Internet of Things (IoT) has become an integral part of our daily lives, operating silently in the background. IoT ensures that our trains, buses and taxis arrive on time. IoT warns us when the air becomes too polluted for us to breathe. (中文版)

Yet few children understand IoT concepts like Sensors and how Sensors are connected into Networks. And the consequences (potentially disastrous) of a faulty Sensor or Sensor Network.

A BBC micro:bit connected to the Sigfox IoT network is the perfect way to help kids understand how Sensors and Sensor Networks operate. The micro:bit is a good representation of a modern battery-powered sensor device, with ample processing power and support for most types of sensors. For education, Sigfox is likely the cheapest option today for experimenting with a city-wide sensor network.

BBC micro:bit transmitting sensor data successfully to the Sigfox network from within the box
Sigfox Backend showing the sensor data received in real time from the micro:bit in the video above. The message data (e.g. 0017 0310 2310 9860) contains the message sequence number (0017), temperature (31.0), light level (231.0), acceleration (986.0)

In this article I’ll walk you through the steps for creating your own BBC micro:bit IoT device connected to the Sigfox network, like in the above video.

The micro:bit IoT device shall be powered by two AAA batteries, so that it will operate anywhere in the city. Free from the power and network constraints that bind many devices to a fixed location.

Like a real IoT sensor, our micro:bit shall transmit real sensor data in real time to the internet cloud. We’ll use the built-in sensors on the micro:bit to transmit the temperature, light level and acceleration.

There’s a high chance that your location is already covered by the Sigfox network that spans 50 countries across the globe. Check your coverage here.

The complete source code may be found in my GitHub repository…

Prepare The Hardware

To build the micro:bit IoT device, we’ll need…

1️⃣ BBC micro:bit with battery holder and two AAA batteries

2️⃣ Edge Connector Breakout Board for the micro:bit. I tested the Kitronik breakout board for this article.

3️⃣ Breakout Board for Wisol Sigfox Transceiver: Our micro:bit will transmit sensor data to the Sigfox network via the Wisol WSSFM10RxAT module.

When browsing Sigfox products, click on the “Zone” box to show only products for your region

To buy the Wisol Sigfox Breakout Board, browse the official list of Sigfox developer kits and click the Zone box to filter by your region (e.g. Sigfox Zone RCZ 1 for Europe, RCZ 2for US).

Choose a breakout board that’s based on Wisol WSSFM10RxAT (where “x” denotes 1, 2, 3 or 4 for the four RCZ zones). And it should be powered by 3.3 volts, not 5 volts.

For example, for Europe you may choose the SNOC BRKWS01. For US, you may choose the Sea Slug Labs Wisol WSSFM10R2 Board.

You may also buy the Wisol Sigfox Breakout Board from the Tindie marketplace. This is the breakout board that I tested for the article…

U.FL antennas — I tested the one at the top

If you’re using the above breakout board, remember to get the right U.FL antenna for your region: 868 MHz for RCZ 1 (Europe and Middle East), 902 MHz for RCZ 2 (US), 923 MHz for RCZ 3 (Japan), 920 MHz for RCZ 4 (Australia, New Zealand, other parts of Asia).

I have tested this antenna for RCZ 4 (the one at the top of the photo).

Important: Always connect your antenna to your Wisol Sigfox Breakout Board before powering on the Blue Pill. Otherwise you may damage the Wisol module!

Connecting the micro:bit to the Wisol Sigfox Breakout Board

Connect The Hardware

Slot the micro:bit into the micro:bit Edge Connector Breakout Board. Follow the above diagram to connect the micro:bit Edge Connector Breakout Board to the Wisol Sigfox Breakout Board…

micro:bit Pin P0 (TX) → Wisol Pin RX   (Blue)
micro:bit Pin P1 (RX) → Wisol Pin TX (Green)
micro:bit Pin 3V → Wisol Pin 3.3V (Red)
micro:bit Pin GND → Wisol Pin GND (Black)

When connected, our IoT device should look like this, powered by the batteries at the left. The U.FL PCB antenna is at the bottom edge. This article explains the functions of the micro:bit pins.

micro:bit connected to the Wisol Sigfox Breakout Board

Fetch The Source Code

Click the link below to open micro:bit MakeCode, the web-based visual programming tool for micro:bit…

1️⃣ Click the Import button at the right.

2️⃣ Click Import URL

3️⃣ Enter the URL:

4️⃣ When the project has been loaded, click Blocks at the top to reveal the visual program (see below).

Our IoT program visualised as Blocks in the MakeCode online editor

Configure The Program

In the Setup Sigfox Block at the top, click the COUNTRY box and select your country. This configures the program to transmit sensor data to the Sigfox network using the right country-specific settings.

The block also specifies the sensor names “tmp”, “lig”, “acl”. These are the sensor values that we will be sending to the Sigfox network.

JavaScript version of our program

Click the JavaScript tab at the top.

You’ll see that the visual program is actually stored as a JavaScript program.

This is a variant of JavaScript known as Static TypeScript, which is optimised for the micro:bit and can be compiled efficiently into machine code.

Click the Blocks tab to switch back to the Blocks view.

“Run In Background” blocks for handling the temperature, light and accelerometer sensors

Read The Sensors

The three Run In Background blocks above are responsible for reading the micro:bit onboard sensors (temperature, light, accelerometer) at regular intervals, also for transmitting the sensor values to the Sigfox network.

The micro:bit is capable of running multiple tasks concurrently in the background. We’re exploiting this capability to handle each sensor with its own processing logic, so we could read each sensor at different intervals, for example.

The Temperature Sensor Block reads the temperature sensor and assigns the value to the tmp variable. The variable is then sent to the Sigfox network via the Send To Sigfox function. The first parameter of the function (“tmp”) identifies the sensor value that we are sending.

The Temperature Sensor Block waits 20 seconds (i.e. 20,000 milliseconds) before repeating the steps in the While block.

The Light Sensor Block and Accelerometer Sensor Block operate the same way, reading the micro:bit’s light and accelerometer sensors and sending their values to Sigfox.

The sensor names “tmp”, “lig”, “acl” should match the parameters of the Setup Sigfox function.

Aggregate Sensor Values

The Sigfox network is dedicated for connecting IoT devices, so it only allows small, infrequent messages to be sent, up to 12 bytes per message, 140 messages per day. To optimise the transmission of Sigfox messages, we combine the three sensor values into a single message, transmitted to Sigfox in 20-second intervals.

Our Sigfox message looks like this…

0017 0310 2310 9860

which contains:

  • message sequence number (0017)
  • temperature (tmp = 31.0)
  • light level (lig = 231.0)
  • acceleration (acl = 986.0)

To see the JavaScript code for aggregating the sensor values, refer to aggregate.ts. To learn more about the aggregation logic, check out the section “Watch Blue Pill Run” in the article Connect STM32 Blue Pill to Sigfox. Instead of the BME280 temperature / humidity / altitude sensors mentioned in the article, we’re using the micro:bit’s temperature / light / accelerometer sensors instead.

Pair The micro:bit

Before downloading our IoT program to the micro:bit, we need to pair the micro:bit with our computer.

1️⃣ Connect the micro:bit to the USB port of your computer.

2️⃣ Click the More icon (the cogwheel icon) at top right. Click Pair Device

3️⃣ In the “Pair Device” box, Click Pair Device

4️⃣ Select your micro:bit in the list that appears. Click Connect

If the micro:bit was not detected, follow the instructions below to upgrade the micro:bit firmware, then repeat the above steps.

Download button at the lower left

Download And Run The Program

To download the program to our micro:bit, click the Download button at the lower left. After downloading, the program starts running.

In a while the Show Console (Device) button appears. Click the button. (Make sure it’s not the Show Console (Simulator) button)

micro:bit Console

Here we see the graphs of the temperature (tmp), light (lig) and accelerometer (acl) sensor values, rendered in real time as our program reads the sensors.

Below the graphs is the debug console. The debug console displays debugging messages that were generated by our program. It’s useful for troubleshooting the program because it shows the sensor values that have been read and their transmission to Sigfox. Take note of the lines….

<< wisol.getID 003FA49D
<< wisol.getPAC B99F7CE054591652

These are the Sigfox Device ID and Porting Authorisation Code specific to your Wisol Sigfox module. You may require them for activating your Sigfox connection. To see a sample debug console log, click here.

Our micro:bit is now flashed with the IoT program. Whenever the micro:bit is powered on via USB or batteries, it will start operating as an IoT device, reading sensor data and transmitting to the Sigfox network.

Disconnect the micro:bit from your computer and switch to battery power. We’ll now check the Sigfox messages transmitted by our micro:bit.

Monitor Sigfox Messages

Sigfox Backend showing the sensor data received in real time from the micro:bit

Follow the instructions provided by the makers of the Sigfox breakout board for activating the Wisol Sigfox module online. You’ll be guided through the steps to create a user account on the Sigfox Backend portal.

Click Device → Messages to check the messages sent by your micro:bit to the cloud. The messages will pop up in real time on that screen as the messages are received from your micro:bit. If you don’t receive any messages, try bringing the micro:bit outdoors or shift it closer to the window.

The message data (e.g. 0017 0310 2310 9860) contains the message sequence number (0017), temperature (31.0), light level (231.0) and acceleration (986.0).

Do you need to visualise the sensor data? Or trigger alerts based on some sensor data rules? That’s all possible with the Sigfox callback feature.

Now you have your very own battery-powered IoT device that will transmit sensor data from anywhere in the city!

Better Living Through IoT

My IoT students at Temasek Polytechnic are about to conduct some experiments on IoT Education for kids — that’s my motivation for creating the code in this article.

As we have seen in this article, it’s easy to create a sensor device for demonstrating sensor networks and IoT, by reproducing real-world sensor applications. With better tools for IoT Education, I hope people around the world will better appreciate the impact of IoT on our daily lives.

Technical Challenges — Serial API

(This section dives deep into micro:bit technical issues that I encountered while creating the code for this article. You may skip to the next section if you’re not into the technical details.)

The creators of the BBC micro:bit (including Lancaster University) did a fantastic job. The micro:bit platform is much richer than I had imagined. Check out the micro:bit platform design.

Since I’m teaching IoT with the Arduino and STM32 Blue Pill platforms, I have difficulty adapting to some of the restrictive features in the micro:bit. The Serial API is one of them…

Normally the Serial I/O is connected to the USB port. So that we may observe the debug messages on the console. For sending commands to the Wisol Sigfox module, I had to redirect the Serial I/O connection to pins P0 and P1…

This causes a contention for the Serial API — I can’t display a debug message on the console while I’m talking to the Wisol module. As a result I have to use a message queue to enforce sequential access to the Serial API. And there is some ugly code that switches between the USB and Wisol connections.


The switching of Serial I/O doesn’t seem to be clean — some garbled data gets sent to the Wisol module. Which causes some Wisol commands to fail and get retried. Compare this with the STM32 Blue Pill, which has separate ports for Serial I/O (i.e. UART1, UART2).

To keep the code simple and educational, I used the serial.readUntil() function to read data from the Wisol module until the end-of-line delimiter \r is found. What happens if the data is garbled? The delimiter may never be found. This causes a backlog of messages in my custom Serial I/O message queue, eventually running out of memory and forcing the micro:bit to reboot.

So you may observe a period with no messages being sent (or truncated messages), followed by a reboot and the message sequence number restarting at 0.

I could implement a “watch dog” task to catch this problem and reboot sooner. But that makes the code harder to understand and maintain. So the code in this article is not meant for use on production IoT devices. Though it got me thinking — what if I could reimplement the micro:bit runtime on STM32 Blue Pill and open-source libopencm3? Could we actually use the MakeCode visual programming tool to create production-ready code for STM32 Blue Pill devices?

If you’re keen to use MakeCode and Static TypeScript for STM32 Blue Pill, drop me a note!

Further Reading

The Sigfox IoT code in this article was ported from C++ to Static TypeScript for the micro:bit. The original C++ code for STM32 Blue Pill and Arduino is explained in my previous article…

Although micro:bit doesn’t support the full set of multitasking functions, I have ported a small subset of the cocoOS multitasking library (for STM32 Blue Pill and Arduino) to the micro:bit…

The micro:bit version of the cocoOS library may be found in task.ts.

More details of the MakeCode in-browser JavaScript compilation and in-browser USB flashing may be found in this research paper.