Bluetooth: Sending messages from App inventor to Microbit

Hello everyone, I am currently a middle schooler and I have a question regarding the use of BLE for the mobile app I created. I wanted to use the service uuid and service characteristic to help connect the phone app to my microbit program but it seems that there is a problem with the service which prevents my microbit from recieving the messages I am sending through the phone. It seems as if the message isn’t sent or is sent incorrectly, my prgrams are uploaded below, and I would really appreciate it if you could provide some feedback, suggestions or potential solutions. Thank you!
Pic1: The microbit side of recieving the the string
Pic2: App inventor side of the string writing
Pic3: The error code of the string being sent


bda9837dec7c4818ae5893cc0486d6b

1 Like

Hello Sophia

Well, the error message is straight forward - the UUIDs you are trying to use are not from your Microbit, hence the App fails to connect.
https://lancaster-university.github.io/microbit-docs/ble/profile

I'm not sure if UTF-16 is 'true' for Microbit, I think it uses UTF-8, but there are now two Microbit board specifications available, the Original and, erm, the New.

My fellow Power User @Ghica is the expert on Microbit, so I hope she has time to look at your forum topic.

We would need to see all of your Blocks, there are subtle things to get right for BLE to work, e.g. 'location' must be switched on.

Right-mouse in the Blocks work area and select "Download Blocks as image".

3 Likes

Thank you so much for your very quick response! :blush: I put my entire set of blocks below in both .aia and .png format so that its easier to access, Thank you again for your feedback!
tryout.aia (309.9 KB)

Sofia,
I will look at your .aia later, but my quick impression is that you are trying to use UART just with the BLE extension. I was never able to get that to work. You can use the old micro:bit extension to do it.
Look at my tutorial to find out how: App Inventor, Micro:bit and UART
The second part of the tutorial has an example using some other robot car with a micro:bit.

Thank you so much for taking time to respond to my questions, I have tried your tutorial and sample project I found 2 issues. Can you help me check if I had made a mistake here? 1.) The “call BluetoothLE1 RegisterForByte" function under the "When BluetoothLE1 Connected" block, with that function included my phone app crashes and loses connection and 2.) After removing the “call BluetoothLE1 RegisterForByte" function, my phone app shows the error code attached below when trying to send a message to the microbit, and the message doesn't get through to the microbit.
PS: I am using the microbit with the gold logo


Hi Sofia,
I am a bit lost about what you were trying to do.
Did you install my .hex file on the micro:bit, according to my recommendations? (no pairing required, and not install via chrome?)
What phone do you have, with what version on Android?
It is not surprising that the code does not work without the RegisterForBytes block, because the micro:bit needs it, to know what to do.
Please attach the .aia you are using now.

Hi Ghica,
Thank you for your help. The goal of my project is essentially to connect my phone app to microbit and send commands to the microbit through bluetooth. the ultimate goal is to control the robot car built on the microbit so that it can move and react to commands sent from the phone app. My phone is Vivo S1 pro with Andriod version 10. My problem here is that with the .aia below my phone app quits when it reaches the RegisterForByte function, and that is the reason why I choose to remove it.

Here are the codes I used for App Inventor and Microbit:
microbit-UART_RW.hex (1.5 MB)
BTReadWrite.aia (291.2 KB)

Hi Sofia,
I tried your hex and aia, and they work fine! I have a Moto Vision, also with Android 10.
Some things to try: are you using Windows? I have the micro:bit powered and attached via USB (later if it works, you can use a battery pack), and I use the Companion to test. I have heard that you must allow location permission setting to be on, but probably that is already ok for the companion.
What is different with your setup?

Add: And I load the hex file on the microbit by just dragging the hex file to it in the windows explorer.

Forgot. Screenshot:

Hi Ghica,
Thank you for your assistance to me on my project, it was of great help. Also, I followed your tutorial and tried the program again on my sister's phone, and it worked succesfully (both with and without the RegisterFor Blocks function). :wink:

ps: My sister's phone is also andriod 10 and is a Xiao Mi 10.

I am happy to hear that. Maybe your phone has a strange version of Android, or is it working now?

Hi Ghica,
I tried this again over weekend, my Vivo still cannot work. another phone Huawei Mate 9 with Android 9 can work very well. I have another problem now: There are 2 screens in my App, one screen for AI, one screen for Robotcar Control. when I switch from Car control screen to AI screen, bluetooth will be disconneted. How can I keep Bluetooth connected with Microbit when I switch between different screens in my App?

Hi Sofia, the best way is not to switch screens!
Read about how you can have virtual screens.
If you really must have two screens, then you need to reconnect to your micro:bit every time you switch screens. Search te forums for the best way to do that.
But again, if you can, use only one screen!

2 Likes

Hi! I am trying to create a similar project, and have used the same code Sophia has attached. However, after the microbit and MIT app inventor connect, the app crashes. I am using a Motorola Android version 11 and a V2 microbit. I ran this code about a month ago and it worked just fine. I believe there is a version issue. Could you please help me resolve this issue? Thank you!

Can you post your .aia?
And you could check whether you have the latest version of the BLE extension.

1 Like

Hello Ghica,

Thanks for helping me debug the problem. I am on one time bound project and stuck, looking for ways to debug to complete quickly. All help is appreciated.

I am hoping for my app to serve as a connection between Huskylens, an AI camera by DFrobot and the delivery of an SMS message. I have trained the Huskylens to recognize images of weapons such as guns and knives. When it sees a threat, the Huskylens triggers the Microbit to send a message to my MIT App Inventor App. When MIT App Inventor receives the message, I am programming the app to go to a page which alerts the user and prompts them to click the "False Alert" button, or, if the threat is real, in five seconds an emergency number will automatically be dialed.

Microbit_envoi_smartphone_v3.aia (481.1 KB)
I used the attached code and I am trying to establish a messaging platform with Microbit and my MIT App Inventor app. From there, I want to create a code which sends a SMS text message to a phone number when MIT App Inventor receives the message from the Microbit. However, when I use my Android 11 Motorola moto g fast (Android security update June 1, 2022) to test out the app, the Microbit is able to connect to the app, but after a second, the app itself crashes.

I also tried Beta version of BLE extension for Android 12 but same behavior.

Thank you so much!!

Hi Artist178, I cannot break iron with my hands as they say in my country, and certainly not weapons.
I think there is something wrong with your use of the Timer. I suggest to take the timer handling out for the time being, and when it works without it, you could reinsert it.
If that does not help, then also post the .hex file of your Microbit.
That said, I am wondering how you are going to use this app, because it needs to be on permanently to work in your scenario.

Hi,
I tried using just the Microbit connection file without everything else and it still doesn't work:
TEST.aia (290.8 KB)

The Microbit and the app connect, but then, a moment after connection, the app just crashes.
Here is my hex file which I download to the microbit before running the MIT App Inventor Code.
microbit-test.hex (1.3 MB)

Every other part of my project works fine and I am just trying to get the Microbit and app connection to work.

You can only really judge that by your hair colour - if it is going grey, then yes the Project is on it's way to success :grin: