UART with Micro:bit and App Inventor

Yes, you are correct. I did have before. Put it back, little bit of progress in that the original error is reported (Using the MB “JustWorks” setting:

Error 9011 in extension BluetoothLE: Unknown Characteristic

Interestingly, there isn’t a 9011 in the App Inventor list of errors - that must be a recent change. However, MB needs to work with the Service and Characteristic Uuids. There must be a way to do it, I can’t find any mention though. I have numerous MB links on my website by the way:

https://www.professorcad.co.uk/appinventortips#TipsMicroBit

The difference between now and last year seems to be that App Inventor’s BLE Extension does not want to work with the “JustWorks” or “No pairing required” modes supported by MicroBit - they are both of course insecure.

https://lancaster-university.github.io/microbit-docs/ble/profile

Final try, I reset my MB to the verbatim original, via the latest Lancaster University Hex file. However, the Characteristic Uuid is still rejected :upside_down_face:
Perhaps it is slightly wrong - I cannot find any reference to the actual Uuids the MB has by default, only the Characteristics supported.

Let’s see how Evan gets on with the MicroBit Extension this weekend - if he has time, he is going to look into reinstating the Uart Blocks.

@Do_Choi_STEM

Here's an updated extension with a new component, Microbit_Uart_Simple (download). This version returns a single string rather than a list of bytes, and it automatically subscribes to the TX characteristic so you don't have to manage that any more. This is still a work in progress, so please let me know how things go with it.

The way BLE typically works is that when you pair with something the system records the characteristics that were advertised at that point in time and saves them. On future connections, rather than querying the device again it reuses the cached values. With the micro:bit and other programmable things, this has the unfortunate side effect of allowing you to change the characteristics without the device realizing that something is different. Sometimes turning the Bluetooth off and on clears the cache. If not, I sometimes use the BLE Scanner app (which I believe calls a private Android API) to refresh the devices.

Dear @ewpatton
I test with new simple Microbit Extension (com.bbc.microbit.profile-20200518.aix ), I can send a string from APP inventor to Microbit, but it does successfully for the first time, the second time Microbit receive a string " " ( maybe space letter )

For example, I create a textbox on App Inventor, and get the string from this textbox, send to Microbit. text is "data"
Result: 1st time: string can be sent to microbit successfully, and Microbit show "data" on LED 5x5.
2nd time, Microbit show " "
If I reset the Microbit, it repeat again, 1st time is successful, 2nd, 3rd , 4th time ... is failed.

Micro:Bit Hex File (Duplicate of Do Choi STEM's) blocks for someone to test with the .aia posted above:
microbit-MoreStrings.txt (655.4 KB)

I made a similar hex file and used Evans "new" UART extension. Same problem as DoCho. It is sent only once and I never see the massage sent event.
As I bought a new little robot with a micro:bit, I really would like the UART to work. Last summer I had a shaky version that could steer the other robot I had around, but I would like to improve on it this time!
Cheers, Ghica.

2 Likes

Here is a setup that works:
Use the old micro:bit extension that can be found here:
http://iot.appinventor.mit.edu/assets/resources/com.bbc.microbit.profile.aix
And a .hex file (no pairing required, it receives a message via UART and it sends a message back with a sequence number.
Here is the .aia for it:
MQUart5.aia (272.6 KB)
After connecting, if you press the send button, it sends Hello and it displays what it recieves back in a label.
I receive a string of numbers back that clearly say: Hello1 etc. but as a list of numbers that I should convert. I did not find out yet how to do that.
Hope it helps someone. It would be sooo nice if someone solved the UART problems for the SimpleMicrobit extension!
Cheers, Ghica.

1 Like

The problem with these blocks is that you should use BytesReceived instead of StringsReceived,
component_event (1)
Then it works fine. However, you get a list of ASCII characters (numbers) and I did not find an easy way to convert these to a string.
Cheers, Ghica.

Ah, I though we were only sending strings.

There is an easy to convert a received list ASCII character numbers to a string, just look-up each number in a List:

ASCII_NUM2CHAR.aia (8.0 KB)

You are sending strings, but receiving ascii bytes.
This translation table of course works. I made a JS solution but the problem with that is that the WebViewer replies asynchronously, which makes it not very flexible.
I am hoping for a more elegant solution, like something for the math blocks, or an option in quite a few of the ble blocks to do this for you.

This is the JS solution:

blocks (43)
Where the first line of the join reads:
window.AppInventor.setWebViewString(String.fromCharCode(

Cheers, Ghica.

2 Likes

nice work Ghica, it works fine great. I have question here.
is there any way to receive number value from microbit?. The makecode progrma is reading the distance between microbit and objects using Ultrasonic, i would lik the distance to be sent to app inventor every 1 second or when A button pressed.

What you could do is convert your number to text on the microbit


and then send it to App Inventor. AI is rather good to interpret strings as numbers again.

1 Like

thank you :+1:

And by the way, your App Inventor app cannot work in the background, so if you think that the app will wake up when you press a button on the micro:bit, that will not work.

I cannot find the Microbit_Uart1 so I don't have these blocks available. Where are they?
What have you added in Designer that I haven't??? I'm mystified!

Hello Greg

did you download this older extension?

Tried that. It didn't work. When I went to import extension, a message box appeared saying simply Import Extension Failed!

Did you already have a Micro:bit extension installed? The old and the new are incompatible.

Aha. Nicely spotted, Chris. Having removed the other, I've now installed the version that offers the UART service!
Some progress. I now have the MicroBit showing up in a listView object on the AI2 app. When I select it, I get an error in the emulator "Error 9011 in extension BluetoothLE: Unknown Characteristic" and the MicroBit flashes an unhappy face , 0, 2, :frowning: , 0, 2, :frowning: 0, 2