PragmaticPhilBjarke Gotfredsen ☒
Published © GPL3+

Simple Wi-Fi-Based IoT on BBC micro:bit with XinaBox

Get started with Wi-Fi based IoT on your BBC micro:bit. Share two-way data with an IoT Platform using the simple XinaBox IoT starter kit.

EasyProtip30 minutes137
Simple Wi-Fi-Based IoT on BBC micro:bit with XinaBox

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
XinaBox CW01
IoT Starter Kit 1: The Wi-Fi Core (ESP8266/ESP-12F)
XinaBox BM01
IoT Starter Kit 2: micro:bit bridge. Connect any xChip to a micro:bit using this bridge
XinaBox XC10
IoT Starter Kit 3: 2 xbus connectors to connect the CW01 to the BM01, and the CW01 to the IP01
XinaBox IP01
IoT Starter Kit 4: USB Programming Interface (FT232R) - provides power to the circuit and is used to flash code onto the CW01


Read more


Flashing the CW01

Follow these steps to connect your IP01 to the CW01 and then flash the provided code onto the CW01
Flashing the cw01 htyidcnlei

Flashing the micro:bit

Follow these steps to edit the Python code provided and to flash it onto your micro:bit
Flashing the microbit 11z4t4pgjq

Assembling the IoT Starter Pack

Connect the IP01 / CW01 circuit with the BM01 and the micro:bit
Assembling starter kit c5bzbu0orp

Connecting to an IoT Platform

Follow these steps to connect the circuit you have built in earlier steps to the HiveMQ IoT platform
Connecting to iot platform kegyrh82t6

Pulling it all together (1)

Some tips and handy info for after you've worked through the first 4 instruction sheets
Pulling it together 1 rl2cncnims

Pulling it all together (2)

Some tips on what to look for in the Hive dashboard and how to send a message to your micro:bit
Pulling it together 2 juejetgps1


Python Code for Microbit

Flash this code onto your micro:bit as described in the instruction section "Flashing the Microbit"
from microbit import *
uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=pin20, rx=pin19)

def CW01(parm):
    # NOTE: 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

    data = uart.readline()
    while(data is None):
        data = uart.readline()

    if int(data[:1]) == 1:
    elif int(data[:1]) == 0:
    # NOTE: You can't use the print command - it becomes input to the CW01 (its a uart thing)
    # NOTE: If you get an error in the code above it means you are not connecting to Wi-Fi (it fails the 'cast' to int if not connected)
    # NOTE: When its working properly, the code above will show a TICK every time data is correctly sent via Wi-Fi

uart.write("$") # Clean out Serial buffer
uart.write("+9@?$") # Reboot CW01
uart.write("$") # Clean out Serial buffer
# EDIT guidelines - Don't change the sleep durations above - at least not until you are connecting succesfully - some need to be long.

# EDIT guidelines - You MUST change the code above - enter your Wi-Fi name and password.
# EDIT guidelines - be careful to ensure you don't edit the @ or $ signs - just change "WIFINAME" and "WIFIPASSWORD"

# EDIT guidelines - In the line above the bit "/v1.6/devices/" is an identifier you will need to use in the IoT platform.  
# EDIT guidelines - DON'T change "/v1.6/devices/" - change YOURNAME later in this code to personalise your dashboard
# EDIT guidelines - when setting up a subscription in HIVEMQ you will click ADD NEW TOPIC SUBSCRIPTION
# EDIT guidelines - in the Topic field you will need to enter /v1.6/devices/YOURNAME/  - ensure this is identical, including the forward slashes

while True:

    CW01("+4@YOURNAME@temperature@" + str(temperature()) + "$")
    # EDIT guidelines - you can edit the line above to send other data to the IoT platform
    # EDIT guidelines - Above we are naming the micro:bit YOURNAME.  You need to enter this into the Hive dashboard
    # EDIT guidelines - Change the word YOURNAME to something - just make sure you change it in all 3 places above and ONLY change YOURNAME
    # NOTE: You will need to hold down a button for a while for it to register in the IoT platform - check the code to see if you can see why!

Binary file for CW01

Flash this code onto the CW01 module (see instructions section "Flashing the CW01")
No preview (download only).

XinaBox Uploader for windows

Use this executable on a windows machine to flash code onto the CW01. See instructions section "Flashing the CW01".
No preview (download only).

XinaBox Uploader for MacOS

Use this executable on an Apple machine to flash code onto the CW01. See instructions section "Flashing the CW01".
No preview (download only).




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

Bjarke Gotfredsen ☒

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


Add projectSign up / LoginAbout BBC micro:bit