App Inventor, Micro:bit and UART

App Inventor, Micro:bit and UART

Somehow, communicating with a micro:bit via UART is more difficult than it should be. For now, using the extensions as indicated in this tutorial, will ensure that everything works.

This tutorial is intended to show how to use Bluetooth Low Energy (BLE) to send messages to a micro:bit. This can be used to control a toy robot car or any device that uses a micro:bit as its brain.

This first part will only cover the basic communication with a micro:bit via BLE. A follow up tutorial will cover controlling a robot car, for example the Ring:bit car v2 or the DFRobot Maqueen, both available for less than 30$, not including a micro:bit, which should cost less than 20$ for a v2 version.

The micro:bit is an electronics board, intended for schoolchildren, to learn programming and simple electronics. It is also nice to use as the heart of a little robot. To be able to control this robot via App Inventor we need UART communication, which is not so easy to do.
Snap25
Here is a pdf with the text of the tutorial:
microbitUART.pdf (1.6 MB)
Here are the links you need:
com.bbc.microbit.profile.aix (100.7 KB)
BTstarter.aia (191.3 KB)
BTReadWrite.aia (291.2 KB)
microbit-UART_RW.hex (1.5 MB)

Due to changes in the permission systen for Android, there is an updated BLE extension, at this moment still in beta:
edu.mit.appinventor.ble-20230223-beta.aix (200.0 KB)
Here is the app, updated with the newer extension:
BTReadWrite_2.aia (295.4 KB)
You will need this version when your phone is running Android 12 and up. Be sure also to have Location set to on in the settings of your phone.

5 Likes

No funciona, ya descargué, será algún permiso en el celular, o la versión de la micro??? no escanea, no muestra nada

Josefina,
Let me get this straight:
You downloaded microbit-UART_RW.hex ?
Then you put this hex file on your micro:bit, using a USB cable? (By the way, I used a v2 micro:bit, but it should not make a difference I think. Leave it connected, or power the micro:bit with a battery pack.
Then you started http://ai2.appinventor.mit.edu/ and loaded
BTReadWrite.aia
Then, you started the AI Companion on your phone and connected to App Inventor?
Then, you saw the Scan button on your phone?
And then you see nothing?
If that is the case, your phone does not have Bluetooth on.
Switch it on in the settings of your phone and try again.

If that is not the problem, you should see a list of devices, including a device with BBC Microbit in the text. Stop scanning, select that device and click connect. Now you can send text from your phone, that is displayed on your micro:bit.
You will have to be more precise what the problem is!

image
image

Al dar escanear no escanea

image

¿Qué significan estos dos bloques?

Is Bluetooth on your phone turned on??

Those two blocks have the UUID's for UART. Everything using BLE needs a UUID, or a Univerally Unique ID. Do not worry about it. They are used in the next part.

Hello, I have tried with BTReadWrite.aia and microbit-UART-RW.hex using a USB cable but the App cant see the micro:bit (Scan doesnt show anything).
The phone (the Android bluetooth manager) can see it and even pair but if I try to send text it tells me to connect, and connect gives an error.

What did you do or see next?

Yes.

Yes. I also use a v2.

I see the scan button; I press it and it says scanning but nothing more happens.

Also I can find the micro:bit with the "normal" bluethooth connection; I can connect to it and the smiley face apears. But not with the AppInventor.

Are you using the companion to run your app?
What should happen when you press Scan, is that you get a list with devices near your telephone, and one of those should be your micro:bit (it should have power, either via usb or via a battery pack.
If you do not see that, I can think of two reasons: either Bluetooth is not on on your phone, or you did not load the app into the companion but you are using an emulator on the PC, this does not work with bluetooth.

Yes.
I also tried installing the app and the result is the same.
The Bluetooth on my phone is on (It can see the micro:bit and connect just not with App Inventor).

The question was, if you press scan, do you see a black list with BT devices near your phone, which should also show your micro:bit on the list.?

No, It doesnt show anything on the list.
But I have tested with another phone and it works :smiley:
So the problem is with my samsung phone. with a cheapo alcatel I can connect and send messages.

1 Like

If you have a phone with a really recent Android system, that may be the problem. Somehow the app does not have the right permissions then. There are ways to solve it, but I have a rather old phone myself. Maybe someone else knows how to do that.

I think I got it. After I turn on location (GPS) everything works :smiley:
Thank you for the great tutorial!

Great! Thank you.

Hi Ghica,
I have followed the steps as you mentioned above but my app is crashing. My Microbit version is 1.5
and I'm using "BTReadWrite.aia" which you have given above. Is there any way to solve the problem can you help me with this?

Hi Augustin, what exactly are the symptoms of your crashing app?
And I am wondering about the version 1.5 of your micro:bit. I thought they were either v1 or v2, but maybe not.
If possible at all, try to buy or borrow a micro:bit v2.

I also have a app crashing problem after i pressed the connect button. The microbit does connect with the app yet it crashed right after connection made or right after the button pressed. Yet, no matter the app crashed or not the tick sign of microbit will come out after a while.