BLUETOOTH PAIRING OK BUT DATA TRANSMISSIONS NOT MAKING IT TO THE PHONE APP

423 views
Skip to first unread message

nzmicroman

unread,
Jul 4, 2019, 4:08:01 AM7/4/19
to MIT App Inventor Forum
Hi all,

I'm trying to get a simple message transmitted from an Arduino Uno via an HM10 Bluetooth transceiver to display on an Android phone.  The phone is running the MIT Companion App.


The phone and HM-10 Bluetooth are pairing successfully using the functions in the app.

The RX light on the Arduino board flashes in time with the sending of the message, which suggests the message is being sent from the Arduino.

However it never displays on the app on the phone.


I thought I might have wired the HM-10 Bluetooth Transceiver incorrectly, and wondered if the Arduino isn't transmitting on the TX pin, but with the same wiring and another app I am able to send messages successfully from the phone to the Arduino via the HM-10 bluetooth so I know the Arduino RX pin is definitely working.


HM-10 to Arduino Uno Wiring:
RXD = 1 (TX)
TXD = 0 (RX)
GND = GND
VCC = 3.3v

 

My next guess is that there's something wrong in my app code around receiving and displaying the received message.

I have attached some pics and the code (both arduino side and phone app code), can anyone help? Thanks!!!!
Help-MIT-Zeb-HM10-Code.png
Help-HM10-Arduino-Code.png
Help-MIT-HM10-Main-Screen.png
Screenshot_20190702-193533.jpg
Screenshot_20190702-193514.jpg
IMG_20190702_193904.jpg
IMG_20190702_193924.jpg

Chris Ward

unread,
Jul 4, 2019, 4:46:13 AM7/4/19
to MIT App Inventor Forum
Hi nzmicroman

Phew! A comprehensive set of information, helps a lot for us to help you.

Looking at your App Inventor code:

1) You can use BluetoothClient1 (= Classic Bluetooth) to check that the phone's Bluetooth service is enabled via Activity Starter - but that is all you can use it for because HM-10 is a BLE device (Bluetooth Low Energy). So, remove your BT Client Blocks and replace them with the BLE equivalents.

2) The BLE extension you are using should be the latest release 24-11-2018.

3) The minimum Android version on your phone must be v5.0 (Lollipop).

4) Some Smart Phones need Google Locate activated for the BLE to work.

You will find lots of Adunino-App Inventor-Bluetooth info on my Website:

..... so that's a few things to sort out while I study your code a bit more :)





Chris Ward

unread,
Jul 4, 2019, 4:49:12 AM7/4/19
to MIT App Inventor Forum
Hi again

Can't read your App code (Blocks), the image needs to be a scalable PNG:
https://www.professorcad.co.uk/appinventortips#TipsBlocks   How to create an image of your Blocks and add it to your Forum Post

Chris Ward

unread,
Jul 4, 2019, 5:10:53 AM7/4/19
to MIT App Inventor Forum
Right:

Your Arduino script should be fine for the purposes of your test. Be aware that there is a max byte limit for Bluetooth packets of data, so sending a casual test string could cause an issue itself - so in future test with a tiny  string e.g. "Hello".  Now, your App needs to know when the data ends and when there is only one item of data, your test string, sending via  Serial.println(); works. If you were to send more data, you would use Serial.print(); for each data item, then send an empty Serial.println(); to let the App know that's the end of the data stream.

There are other ways to control the speed of the main Loop, but a Delay of 500 milliseconds is more than adequate for your test. There has to be a delay between sends so that the App has enough time to process what it receives. However, although it will receive the same test message many times, you will only witness this once.......

So - waiting for Blocks I can read :)


Ghica

unread,
Jul 4, 2019, 7:58:25 AM7/4/19
to MIT App Inventor Forum
Hi, I am confused. The HM10 is BLE, but can be used with the classic BT component?? Because .ino files for it look rather classic??

Chris Ward

unread,
Jul 4, 2019, 8:02:19 AM7/4/19
to MIT App Inventor Forum
Hi Ghica

Classic BT can be used to check that the phone has BT switched on, via Activity Starter. Then it's BLE for everything else.

Martyn_HK

unread,
Jul 4, 2019, 8:08:33 AM7/4/19
to MIT App Inventor Forum

Ghica

unread,
Jul 4, 2019, 8:24:02 AM7/4/19
to MIT App Inventor Forum
Martyn, That is very helpful! I think ABG should put it in the FAQ.
Cheers, Ghica

ABG

unread,
Jul 4, 2019, 9:18:48 AM7/4/19
to MIT App Inventor Forum
Martyn, That is very helpful! I think ABG should put it in the FAQ.

Already there.

ABG
 

 
HM10.PNG

Ghica

unread,
Jul 4, 2019, 9:23:15 AM7/4/19
to MIT App Inventor Forum
We should look better before replying!
Cheers, Ghica.

nzmicroman

unread,
Jul 4, 2019, 3:12:35 PM7/4/19
to mitappinv...@googlegroups.com
Hi all,

Thanks for all your help, I am trying the suggestions now!

Sorry that the image I uploaded had such small font! Here are the updated images for the MIT app code, I have uploaded them in 4 sections to make it easier to read!

Thanks very much!!!

Zeb



MIT-Code-Block1.png
MIT-Code-Block2.png
MIT-Code-Block3.png
MIT-Code-Block4.png

Chris Ward

unread,
Jul 4, 2019, 3:25:01 PM7/4/19
to MIT App Inventor Forum
Hi Zeb

Your best intentions are appreciated, but dicing-up the code into separate images does not make the flow of the code easier to read.

Follow these very very simple instructions:

nzmicroman

unread,
Jul 4, 2019, 3:41:53 PM7/4/19
to MIT App Inventor Forum
Hi again!

I have changed the Arduino Uno program to transmit "Hello" and have added a 5 second delay.

#include <SoftwareSerial.h>
SoftwareSerial ble(0, 1); // RX, TX
void setup() {
  // Open serial port
  Serial.begin(9600);
  // begin bluetooth serial port communication
  ble.begin(9600);
}
// Now for the loop
void loop() {
  Serial.println("Sending Bluetooth Message...");
  ble.write("Hello");
  delay(5000);
 
}

While changing all the receiving MIT App Block I struck a problem. How do I make the variable "global list" = the received Bluetooth data?

I have attached images of my updated BLE block.

Thanks very much,

Zeb
MIT-Code-BLE.png

ABG

unread,
Jul 4, 2019, 3:53:25 PM7/4/19
to MIT App Inventor Forum
From what I see in the MCurrey sample project 2,
you need to register for strings and have a BLE StringsReceived Event block,
instead of the Clock.Timer.


ABG


nzmicroman

unread,
Jul 4, 2019, 3:59:22 PM7/4/19
to MIT App Inventor Forum
Thanks Chris, will do!

nzmicroman

unread,
Jul 4, 2019, 4:04:07 PM7/4/19
to MIT App Inventor Forum
Hi ABG,

Thanks for your help!

Is this correct? (Image Attached!)

Thanks again,

Zeb
MIT-Code-Strings-Receved.png

Chris Ward

unread,
Jul 4, 2019, 4:31:56 PM7/4/19
to MIT App Inventor Forum
Hi Zeb

No.

That is the Strings Received block, it has the strings (text) received from your Arduino stored in the stringValues parameter. 

Like this:

Receive Strings.png




Chris Ward

unread,
Jul 4, 2019, 4:34:24 PM7/4/19
to MIT App Inventor Forum
Hi Zeb

Where did you get the UUIDs from? 

Chris Ward

unread,
Jul 4, 2019, 4:38:24 PM7/4/19
to MIT App Inventor Forum
... ah, you lifted them from Martyn's example - they should work if your HM-10 is manufactured by jnhuamao China or is an exact copy of that device.
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

nzmicroman

unread,
Jul 4, 2019, 5:25:15 PM7/4/19
to mitappinv...@googlegroups.com
Hi Chris,

Thanks for all your help!!!

I have made the changes in the MIT app but still won't receive / display!

My Arduino code is:
#include <SoftwareSerial.h>
SoftwareSerial ble(0, 1); // RX, TX
void setup() {
  // Open serial port
  Serial.begin(9600);
  // begin bluetooth serial port communication
  ble.begin(9600);
}
// Now for the loop
void loop() {
  Serial.println("Sending Bluetooth Message...");
  ble.write("Hello");
  delay(5000);
 
}

Sorry it would not let me upload an .aia file so I had to screenshot it! (flashed up saying there was an error and to try again later!)

Thanks again Chris!

Zeb
Block1.png
Block2.png
Block3.png
Block4.png

Chris Ward

unread,
Jul 4, 2019, 5:39:27 PM7/4/19
to MIT App Inventor Forum
Hi Zeb

For now (there is more to it)

In your Sketch, comment-out: ble.write("Hello");

Replace  Serial.println("Sending Bluetooth Message...");   with  Serial.println("Hello");

I can see you are confusing Bluetooth Classic (BluetoothClient1)  with BLE. You can, in this case, only use Classic to check that your phone has Bluetooth enabled. That check is performed via Activity Starter.

I'm going to post some App Inventor Blocks and the Project File that should work with your Ardunio Sketch. 






nzmicroman

unread,
Jul 4, 2019, 5:52:17 PM7/4/19
to mitappinv...@googlegroups.com
Hi Chris,

Thank you for your help! I have just updated the Arduino code to:

#include <SoftwareSerial.h>
SoftwareSerial ble(0, 1); // RX, TX
void setup() {
  // Open serial port
  Serial.begin(9600);
  // begin bluetooth serial port communication
  ble.begin(9600);
}
// Now for the loop
void loop() {
  Serial.println("Hello");
  //ble.write("Hello");
  delay(5000);
 
}

Thanks again

Zeb

P.S. That would be amazing if you could provide some sample code!

Chris Ward

unread,
Jul 4, 2019, 6:24:57 PM7/4/19
to mitappinv...@googlegroups.com
Hi Zeb

See the attached sample Project File (BLE_RECEIVE_STRINGS.aia). Save it to your PC, then in App Inventor:

Import Project.png



The Blocks Note, this is fairly crude and incomplete, it is just to get your comms with the Arduino working. Right-mouse click on the image and choose "open link in new Tab" to view the image clearly - you can zoom it with the mouse wheel as required.


Blocks_BLE_Receive_Strings.png



Check that I have got the UUIDs correct!








BLE_RECEIVE_STRINGS.aia

Chris Ward

unread,
Jul 4, 2019, 6:31:38 PM7/4/19
to MIT App Inventor Forum
...past my bedtime now (UK time), clocking out.

Good luck with your App testing Zeb :)
Message has been deleted

nzmicroman

unread,
Jul 4, 2019, 7:30:19 PM7/4/19
to MIT App Inventor Forum
Woohoo! It's working! Thanks so much for sharing all your knowledge and support!!!

Thanks again Chris!

Zeb

ABG

unread,
Jul 4, 2019, 8:13:12 PM7/4/19
to MIT App Inventor Forum
Now that it's working, would you post the
Downloaded Blocks Image here for the next person?
ABG
Message has been deleted
Message has been deleted

nzmicroman

unread,
Jul 4, 2019, 9:28:09 PM7/4/19
to mitappinv...@googlegroups.com
Hi all,

Yes sure ABG!

_________________________________________________________________________________________________

MIT App Receiving Data From HM-10 Connected To Arduino Tutorial

Please note that this code is for the HM-10 Bluetooth Transceiver.

So the Arduino code for sending the message "Hello" is.

#include <SoftwareSerial.h>
SoftwareSerial ble(0, 1); // RX, TX
void setup() {
  // Open serial port
  Serial.begin(9600);
  // begin bluetooth serial port communication
  ble.begin(9600);
}
// Now for the loop
void loop() {
  Serial.println("Hello");
  delay(5000);
}


Download and upload the SoftwareSerial.h Library for Arduino from https://github.com/PaulStoffregen/SoftwareSerial this is a good tutorial for uploading Arduino Libraries https://www.digikey.co.nz/en/maker/blogs/2018/how-to-install-arduino-libraries.

 
Please download and import this .aia file to MIT app inventor. It is the app example code for receiving the message "Hello" from the HM-10 Bluetooth Transceiver that Chris kindly made for me.

Import Project.png

Hope you find this helpful,

Zeb

Chris Ward

unread,
Jul 5, 2019, 4:55:52 AM7/5/19
to MIT App Inventor Forum
Hi ABG

It is actually all on this Topic already, see my almost last post.

ABG

unread,
Jul 5, 2019, 11:27:09 AM7/5/19
to MIT App Inventor Forum


I've attached the AI2 BLE blocks for fast reference.

I wanted to see all sides of the solution together, to see
how the transmitter code changes between
BLE and non-BLE versions.

Aside from a variable named ble,
I saw no difference in the code.

Maybe it's all in the choice of libraries?

ABG
P.S.  Yesterday was Independence Day in the US.
Was it Good Riddance Day in the UK?


blocks.png

Chris Ward

unread,
Jul 5, 2019, 4:00:06 PM7/5/19
to MIT App Inventor Forum
@ ABG  Noooooo!

TimAI2

unread,
Jul 5, 2019, 4:50:54 PM7/5/19
to MIT App Inventor Forum
Good Riddance Day comes on 31st October  ;)

Chris Ward

unread,
Jul 5, 2019, 6:01:09 PM7/5/19
to MIT App Inventor Forum
@ Tim - maybe, but what year? :)
Reply all
Reply to author
Forward
Message has been deleted
0 new messages