micro:bit and the blue micropython
One of the more interestng parts of the micro:bit is the bluetooth module. With this its possible to, amongst over things, flash the device and also control external bluetooth devices.
However due to various technical reasons this built-in Bluetooth functionality is not available when using micropython. However its possible to sidestep this issue by using an external module. In this project a 'Hello World' message will be sent over the airwaves to a waiting mobile phone.
The HC-0x Bluetooth Modules
These inexpensive modules are availiable from multiple sources. The main types in use in the maker community appear to be the HC-05 and HC-06 types. Both types are identical apart from the following points:
-
The HC-05 module can build a connection to other modules. E.g. a Robot being a master and connecting to slave bluetooth module. Or in slave mode to make a wireless bridge to a notebook.
-
The HC-06 module only can be a slave. This makes it only useful for say connecting a notebook as a master to a robot with a slave module e.g. for a wireless serial bridge.
1
Wiring up the device
The HC-06 module is quite happy running on 3.3v that is supplied from the the micro:bit and the message data can be sent via Pin 0 to the Rx pin on the HC-06.
The micropython code
from microbit import *
uart.init(baudrate=9600, bits=8, parity=None, stop=1,tx=pin0)
while True:
if button_a.was_pressed():
uart.write('Hello World!') #send hello world
elif button_b.was_pressed():
uart.write(bytes([0x0A])) #new line
sleep(100)
Reading the Bluetooth connection
With the code flashed and the micro:bit happily sending the message via Bluetooth a way of reading this output is required. This was achieved using a Bluetooth serial terminal app from the Google Play store.
Once this app was installed and paired with the module, the 'Hello World!' message was displayed when button A on the micro:bit is pressed.
Resources: