Bluetooth
Bluetooth implementation on the micro:bit
Overview
The micro:bit processor has an on-board Bluetooth transceiver. This is combined with a PCB trace aerial and other minor components alongside a software stack that gives the micro:bit a certified and credible Bluetooth capability.
Bluetooth software stack
V1 Nordic Semiconductor Soft Device S110.
V2 Nordic Semiconductor Soft Device S113.
SoftDevice is the Nordic Bluetooth Software Stack, and different versions of the SoftDevice provide different Bluetooth capabilities for different Nordic chips.
Using Bluetooth, you can connect to other devices and send and receive data from and to the micro:bit.
Bluetooth is distinct from the micro:bit to micro:bit radio feature, which has been built by Lancaster University on top of the ShockBurst proprietary protocol from Nordic.
BBC micro:bit Bluetooth Profile
The micro:bit supports Bluetooth via a single, custom-developed, BBC micro:bit profile. This profile allows it to communicate with other BLE capable devices.
CODAL
A pre-compiled hex file is available to download for V2 that enables all Bluetooth services.
The source for this can be found in the microbit-v2-samples repository.
DAL
The BBC micro:bit V1 Bluetooth profile is defined in the DAL.
You can flash one of two pre-compiled Hex files to the micro:bit V1 that enable bluetooth services. As Bluetooth is memory intensive, these are supplied as either ‘without Magnetometer Service’ or ‘without DFU Service’:
The DAL contains the C++ source for the BLE service files.
There are also some example programs in the microbit-samples repository:
The micro:bit has a V2Bluetooth 5.0/V1Bluetooth 4.1 stack with Bluetooth Low Energy (BLE) and supports the GAP Peripheral Role by default in DAL/CODAL and can support GAP Peripheral and Central device roles by modifying DAL/CODAL to use a different SoftDevice.
It operates in the ISM (Industrial Scientific Medical) band, as per all Bluetooth devices. This starts at 2.4GHz and ends at 2.41GHz. BLE divides the frequency band into 50 x 2MHz bands of which 40 are used. These are called channels and numbered 0 to 39. Channels 37, 38 and 39 are used for “advertising”.
When devices are connected, they use the other channels in a particular sequence controlled by a feature called adaptive frequency hopping. This helps reduce the impact of congestion from other radio users.
Data transfer rates will only be a few hundred Kilobytes per second at best, and throughput depends on how your application uses the Bluetooth features. Throughput depends on the proportion of system protocol overheads to application data. Lots of small packets containing - for example - temperature data would have a lower data transfer rate than using the UART service.
There are some useful advanced configuration options in the micro:bit runtime code.
Challenge
It would be possible for anyone with the appropriate knowledge to define and implement other Bluetooth profiles.
We are seeking collaborators to help us define the new profile elements that expose some of the V2 features.
Further information
-
Martin Woolley’s Bluetooth Blog has a range of information on using Bluetooth with micro:bit
-
BittySoftware has a range of Bluetooth enabled software for the micro:bit
-
Original micro:bit “Out of the Box” experience, including some of the attributes in the Bluetooth Profile
-
Full profile with the display unused. If you want to write to the display over bluetooth then you should use this file instead of the ‘Out of the Box’ hex, which uses the display.
Bluetooth and the micro:bit software
The DAL/C++ reference documentation lists the adopted and custom features available within the profile.
The processor also has several non-bluetooth, proprietary modes of operation upon which the micro:bit radio protocol is based. This protocol works only between micro:bits and is defined as ‘Micro:bit Radio’ in the DAL/CODAL or ‘radio’ in MakeCode and MicroPython.
Bluetooth in MakeCode
There is a “Bluetooth” extension in Microsoft MakeCode that can be used to instantiate individual services from the micro:bit Bluetooth profile, as well as events for connection and disconnection. It is mutually exclusive to the “Radio” extension.
These services can then be used in conjunction with things like the micro:bit web components to interact with the micro:bit over Bluetooth.
As an example, the tools at ML Machine have been built with this extension in MakeCode.
Note: on micro:bit V1, there is very limited memory available when also using the Bluetooth extension.
Here is an example of how to add and use the Bluetooth extension in MakeCode:
Apps
- Android App facilitates pairing and flashing programs to the micro:bit
- iOS App faciliates pairing and flashing programs to the micro:bit
- Swift Playgrounds contains a Playground Book available in the Swift app and a micro:bit Swift API to develop further resources
- Scratch supports using a range of micro:bit Bluetooth services via the Scratch Link software and a custom built pairing .hex