PragmaticPhilBjarke Gotfredsen ☒
Published © GPL3+

Connect to Ubidots IoT Platform with BBC micro:bit + XinaBox

Use Wi-Fi to connect your BBC micro:bit to the Ubidots IoT platform using the XinaBox starter kit

EasyProtip30 minutes43
Connect to Ubidots IoT Platform with BBC micro:bit + XinaBox

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
XinaBox CW01
Wi-Fi Core (ESP8266/ESP-12F)
XinaBox IP01
An interface module equipped to power and program other modules via a USB A connector.
XinaBox BM01
A bridge to connect your XinaBox xChips to a micro:bit
XinaBox XC10
This SKU is a 10 pack - we only need 2 for this project, although I use 3. These are standard uBus connectors.

Software apps and online services

You will need an UbiDots account - Step 1 shows you how to sign up for a free 30 day trial


Read more


Flashing the CW01

Use the xFlasher app provided to flash the binary code provided onto the CW01
Flashingcw01 x87lwc29mt

Editing and Flashing the microbit code

Customise the microPython code - add your Wi-Fi details and Default Token from Ubidots - then flash onto the micro:bit
Editingflashingmicrobitcode quaf5swoas

Assembling the IoT Starter Kit

Connect the micro:bit to the BM01, then connect that to the CW01 / IP01 we assembled in STEP 2.
Assembling iot kit syhuuo8wyy


MicroPython code for the micro:bit

Update this code as detailed in Flashing code onto you micro:bit
from microbit import *
import random
# NOTE: we import random here cos we are going to send a random number to Ubidots

uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=pin20, rx=pin19)
# NOTE: gets the uart (serial / USB) port on the micro:bit ready to write to the CW01

def CW01(parm):
    # NOTE: the variable above called 'parm' must follow this format:
    # start with a '+'
    # then a number 1,2,3 etc. See below
    # then a seperator '@'
    # then a parameter followed by a seperator '@'
    # last parameter is ended with a end symbol '$'
    # Commands:
    # ... '1' for WiFi:             "+1@ssid@secret$"
    # ... '2' for login to MQTT:    "+2@username@password$"
    # ... '3' for MQTT server:      "+3@server@port$"
    # ... '4' for ubidot:           "+4@device@variable@value$" (creates a MQTT publish)
    # ... '5' for MQTT publish:     "+5@topic@payload$"
    # ... '6' for MQTT subscribe:   "+6@topic$" (maximum 1 subscription)
    # always start with "$" just to clean out the serial buffer
    # NOTE: you won't need all the above for the basic stuff in the tutorial, but it will come in useful as you explore and experiment.
    data = uart.readline()
    while(data is None):
        data = uart.readline()
    if int(data[:1]) == 1:     # NOTE: this means that a tick is displayed when data is being transmitted correctly
    elif int(data[:1]) == 0:      # NOTE: this means that a cross is displayed when an attempt to send data fails
    sleep(500)          # NOTE: the square is shown on your micro:bit while it is connecting to Ubidots
uart.write("$")                     # NOTE: Cleans out the serial buffer
uart.write("+9@?$")                 # NOTE: Reboots the CW01
sleep(5000)                         # NOTE: long delay is necessary - we need to give Wi-Fi time to sort itself out.
uart.write("$")                     # NOTE: Clean out Serial buffer, again.

# EDIT GUIDELINES: you MUST enter the name and password of the Wi-Fi network you are trying to connect to in the line above.

# EDIT GUIDELINES: you MUST enter the DEFAULT TOKEN from Ubidots in the line above.

# NOTE: above line tells the micro:bit where to send the data to - its a Ubidots URL - you can leave it as is.

# NOTE: above is an ID for our CW01 - you can leave it as is.

while True:
    CW01("+4@YOURMICROBIT@temperature@" + str(temperature()) + "$")
    CW01("+4@YOURMICROBIT@Random_0to9@"+str(random.randint(0, 10))+"$")
    # NOTE: the lines above tell the micro:bit to send data to Ubidots (to the URL we entered above).
    # EDIT GUIDELINES: you MAY change 'YOURMICROBIT' above - it is just a name that you can assign.  You can leave it as is if you like.
    # EDIT GUIDELINES: the name you enter above is also used in the Ubidots platform.
    # EDIT GUIDELINES: NB - you MUST ensure the name used above and in Ubidots is IDENTICAL.  See STEP 3 (Configuring the Ubidots Dashboard) of the tutorial 


Binary file for CW01

Flash this binary file onto your CWO1 as described in the schematic titled Flashing the CW01
No preview (download only).

XinaBox Uploader for Windows

Use the XinaBox Uploader to flash code from your Windows machine on the CW01
No preview (download only).

XinaBox Uploader for OS

Use the XinaBox Uploader to flash code from your OS machine onto the CW01
No preview (download only).




4 projects • 2 followers
Hobbyist + EdTech consultant
Bjarke Gotfredsen ☒

Bjarke Gotfredsen ☒

3 projects • 9 followers
CEO, Founder and Inventor of the XinaBox tech.


Add projectSign up / LoginAbout BBC micro:bit