This tutorial will show you how to send data over NB-IoT from a micro:bit using the Telenor EE-NBIOT-01 module. The EE-NBIOT-01 is a developer kit we’ve made to lower the barrier for experimenting with NB-IoT. It is a breakout board to the u-blox SARA-N210 radio module with a Telenor Norway SIM-card, an antenna, and a voltage regulator. The guide also relies on our self service NB-IoT Developer Platform. See our separate tutorial on how to setup a device in the NB-IoT Developer Platform. As of 1st October 2018 the platform is only enabled for Telenor Norway.
The micro:bit has 3.3V power on the I/O (input/output) pins, which is a perfect match for the EE-NBIOT-01. However, if you power the micro:bit from a battery, be aware that the battery needs to have at least 3.1V - which means that two fully charged AA batteries is not enough.
Connect the jumper wires between the following pins:
|3V - red||3v3|
|GND - black||GND|
|P0 - yellow||RXD|
|P1 - orange||TXD|
The recommended method to connect a micro:bit to EE-NBIOT-01. Make sure the LEDs on the micro:bit are pointing upwards when you insert it into the edge connector.
See image in full resolution
If you don’t have an edge connector nearby and don’t have time to wait for one, check out this guide. Or improvise using what you have available.
Before we start prototyping, we need the IMEI and IMSI and register the device in our NB-IoT Developer Platform:
Drag-n-drop blocks from the menu to reproduce the blocks below:
In the block editor, every chain of blocks starts with an event (something happened). All the blocks inside of it will be executed in order from top to bottom.
“on start” is only run once, when the micro:bit starts. So here you typically add blocks that should be run before any other code and only need to run once. For the NB-IoT extension to work, we need to tell it what pins on the micro:bit it is connected to and what server IP and port to send data to.
“on nbiot connected” is run once, when the device is successfully connected to the NB-IoT network has gotten an IP address from our NB-IoT Development Platform. If the device is not registered on the platform (see steps above), you’ll not get an IP address and will not be able to connect.
Run this sketch the same way you did the one for getting the IMSI and IMEI. Once we’re connected, we first show a heart in the LED display to indicate that we are connected, then we send the text string «Hello World!». If you still have the browser tab from the NB-IoT Developer Platform open (see Register Device), you should see that some data has arrived. If it shows up as «SGVsbG8gV29ybGQh», you need to tick the «Decode base 64 payload» checkbox to show it as text.
Sending a hard-coded text isn’t that useful other than to check that everything works as it should. The fun really begins when we start connecting the physical world with the digital. So try to send some sensor data (like temperature), or send a message when something happens (like when a button is pressed or the micro:bit moves). The micro:bit has a few sensors built in, but if you feel adventurous you can also add other sensors by connecting to one of the pins (definitely get an edge connector breakout board for that). Remember that NB-IoT is meant for small data amounts, so try to keep the size of the data small and don’t send too frequently (no more than once per minute).
Here are some examples of what you can do:
Log data at a regular interval. Make sure you don’t send too much data too often, or you might run out of data quota.
To reduce power and data consumption, you can choose to only send data when something happens. You read a sensor value and send an alert when the value is not within the expected range. What sensor to use depends of the use-case, but you can connect almost any sensor that runs on 3.3V to the micro:bit, and many of the most popular ones have a micro:bit extension already.
Say you have a fridge or freezer with food worth a lot of money in a building you don’t visit that often. If the fridge/freezer suddenly stops working you’d like to know as soon as possible. Here is one way that could be solved.
See the GitHub repository for full API documentation for the micro:bit extension