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.
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).
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!
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.
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
After connecting you must use this block, only once, like this:
This tells that you want to recieve messages. In my example app, the micro:bit would only reply to incoming messages, and I found out later, that you have to sent RegisterForBytes only once, otherwise you will get the message many times. But in your case you never send it at all, and therefore there is no message when you press A.
For reference I attach here the example files from my tutorial.
microbitRW_2.aia (304.6 KB)
microbit-MB_RW_2.hex (1.5 MB)
And maybe you have to ask permission if you are using Android > 10.
I can't agree more, ChrisWard!
I tried the .aia and .hex files you attached and I enabled all permissions:
However, I still keep running into the following problem:
What you still can try is to load the .hex file in makecode and set no pairing required in the settings and then try again.