It’s not possible to program the Bluetooth module using MicroPython therefore I will use Microsoft’s PXT block editor to create a hex file. I will show you how the file was created step by step then I will show you an app that can be downloaded to control the Bit:Bot.
This tutorial will concentrate on using the Bluetooth UART service. There are other tutorials on the internet regarding this subject however most of them use other Bluetooth services and not the UART service. Once you understand how to use the UART service you can do lots of cool stuff through Bluetooth.
Hopefully this will mean that any serial app from the app store or any terminal program (Must be BLE bluetooth 4.0 compatible) can be used to communicate with Bit:Bot. This can be very useful in the robotics world allowing us to pass telemetry data wirelessly via Bluetooth and not have to worry about platform specific issues.
This code was made with Microsoft’s PXT toolset. It can be found at the below link;
The code will listen for Bluetooth commands when it receives a “F” it will set the pins to make Bit:Bot go forward, when it receives a “L” the pins will be set to go left and so forth.
There are two ways to achieve this, the above way or you can use the GAMEPAD library (not sure if its called this!). I chose to do it this way because I wanted to use the UART functionality and I wanted to control Bit:Bot using a generic serial terminal app. If you would like to see how to achieve the same thing using the gamepad service the following link shows you how;
Please be aware that the above example needs a paid app from Bitty Software to work.
Getting the Serial Software to work
To get the above code to work you will need to download serial Bluetooth Terminal Software. This software must be BLE (Bluetooth 4.0) compatible. If its only Bluetooth 2.0 it will not work. The software I used can be found at the below link;
You could also download BLE terminal software for your laptop and control Bit:Bot from your laptop instead. Once you have the above software installed select the device (ensure that you have Bluetooth LE selected at the top of the devices menu, no pairing required), connect to your Bit:Bot and try typing in different commands to make Bit:Bot work. The commands are;
- F = forwards
- B = backwards
- L = left
- R = right
- S = stop
All commands are case sensitive. You could design your own app to control Bit:Bot in the same way that Bitty Software has if you wanted.
During this example we have created code that will allow you to control Bit:Bot using your BLE enabled phone, tablet or laptop. You can use these techniques to send any command data to your Micro:Bit and your Micro:Bit can send telemetry data back to you. The software i suggested above has buttons that can be pre-programmed making controlling your Bit:Bot easier. If you find better terminal programs please let me know in the comments section. Most of the apps I found was only compatible with Bluetooth 2.0 and would not work.
The below file is the hex file of the above example.