Importing bluetooth module in micropython

Hi @microzirtik ,

MakeCode doesn’t provide access to customize Bluetooth advertising or to create custom services, but you can use the provided services. And rather than a custom service, you can use the UART service to exchange messages and do custom things. Many mobile apps that interact with micro:bits use this approach and can often be easily used to interact with the micro:bit in applications the app wasn’t originally meant for. There are some examples of that elsewhere in this forum, like the discussion at: Android app/Discord - #8 by bsiever

You can control advertising and characteristics via C/C++ and through MakeCode via C++ based extensions.

I wrote MakeCode BLE HID blocks that control the advertising and create services (here). It provides some examples of how to customize advertising.

I’ve also written a bluetooth service to retrieve the datalogger data (here). There’s a corresponding JavaScript library/webpage to retrieve the data from a computer here (source) or a more user-friendly prototype website at https://2024-ui-sp.github.io/Micro-bit-ble/ (source) . This work may be a better example of writing a custom service than the BLE HID blocks.

Hope that helps a bit,
Bill

P.S. According to the docs, the other version of Python, micropython, doesn’t support BLE for anything other than flashing. See https://microbit-micropython.readthedocs.io/en/v2-docs/ble.html.

3 Likes