Cannot send text over HC06 bluetooth module to the App

Hi, I am facing issue with my project. I need to read and and send to the App, datas from a potentiometer linked to my Arduino UNO card. Datats are send using a HC06 bluetooth module.

Following picture are the App's bloks and Arduinos code I made. The problem is I can't get values, only 0s remains but I know the circuit and potentiometer works. It seems I can't send the values I obtain even if I can connect the App to the blutooth module....

If someone have an idea of what I do wrong.


Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Ok I changed the DelimiterByte to 10 as you recommanded it and also check the clock timer.
Still not working so I guess it is about something you say here :

"

"

The problem is don't understand a thing... sorry ( I am a mechanical engineer and this kind of work is a first for me).

  • What is a "comma" ?
  • Didn't I already split my variables ? In the Arduino code you can see "," between each string

By the way, thank you for your help

The advice I gave is all boiler plate, common advice for all people new to this problem, so it is more broad in its advice than your current experience level.

A comma is the punctuation symbol ',' that on my PC keyboard appears between the "m" and '.' keys.

Yes, you already split your variables.

However, it would be wise to also display your incoming data stream in its unsplit form, in case of surprises.

For example, you are using two print streams,

  • Serial, and
  • HC06

I see in your sketch you are indeed doing a println() in your Serial data stream, but not in your HC06 print stream.

From your symptoms (no incoming data over BlueTooth), I'm going to guess that the HC06 print stream is the one that needed the Line Feed characters to trigger END OF MESSAGE processing in the AI2 BlueTooth Client component.

Here is some more boiler plate with a BlueTooth blocks set ...

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

These blocks can be dragged directly into your Blocks Editor.

1 Like

All right, thank you a lot. I'll test all of this

Arthur, your Sketch has nothing to do with a potentiometer reading?

Take a look at this example set-up:

Things we need to know to get the App and Arduino singing the same song:

  1. Arduino Model and Version
  2. HC-06 Baud Rate
  3. Android Device Make, Model, Bluetooth Version
  4. Photo of your Arduino setup where we can clearly see pin numbers, module IDs etc.

Also, the Android device must have Location switched on (Google Security Measure) and Bluetooth Switched on, before the App is run (we can do those settings from within the App too, but best to keep it simple first).

1 Like

Hi ChrisWard, the potentiometer is only here to simulate a measure device.

  1. The card is an ELEGOO UNO R3 (similar to an Arduino UNO one)
  2. Baud Rate of the bluetooth module set to 9600
  3. Android device : oppo Reno (model CPH2109) and blutooth 5.1
  4. Arduino set up :




Thank you for your time

For the Arduino set up, I take the following model :

For know, the source power come from the computer with the USB cable and the temperature reader device (black element with 3 pins) is changed with my potentiometer.

That is actually the module, not just set in the Sketch?

Can you verify the volts and amperage of the USB source. Most computers have some USB ports where amps are too low to power anything and your UNO needs about 300mA @ 9v (12v max)

Dear @Arthur,
the hints from @ChrisWard and @ABG are fundamental, but I would suggest you, in order to be sure that the Arduino side is OK, to load on your Android device an app like "Serial BT Monitor". By using such very basic app, you can verify whether the connection to your Arduino is working fine. In this way you avoid any uncertainty on Android side, since the Serial BT Monitor will work for sure.
Once confident that the Arduino board is sending correctly the data to the Android device, you can then investigate deeper in your app.
Best wishes !

3 Likes

The rs/tx Pins look correct, but in the Sketch, setup(), pinMode() is missing.

//06/06/2022 12:55:06
//ELEGOO UNO R3, Classic BT using HC-06 module

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
#define ANALOGPIN A0

SoftwareSerial HC06(rxPin, txPin); // Rx, Tx Bluetooth HC-05

unsigned long lgUpdateTime;

void setup()
{
               pinMode(rxPin, INPUT);
               pinMode(txPin, OUTPUT);
               Serial.begin(9600);
                 HC06.begin(9600);

               lgUpdateTime = millis();
}

void loop()
{
	           if(millis() - lgUpdateTime > 6000)      //Loop approx every 6 seconds
               {
                         lgUpdateTime = millis();


                         //Get values here


                         //To PC Arduino Serial Monitor via USB
                         Serial.print(Average);
                         Serial.print("|");
                         Serial.print(Range);
                         Serial.print("|");
                         Serial.print(SEM,2);
                         Serial.print("|");
                         Serial.print(MyTime);
                         Serial.println();

                         //To Android App via Bluetooth
                         HC06.print(Average);
                         HC06.print("|");
                         HC06.print(Range);
                         HC06.print("|");
                         HC06.print(SEM,2);
                         HC06.print("|");
                         HC06.print(MyTime);
                         HC06.println();
               }
}

Note, you cannot send labels or other decoration, Bluetooth data packets are small. There is no need to convert to a string either, the App will simply read the data as a string if you use a string specific block. 'Time' is a Keyword, so give that var another name.

That's right, 9600 is set for the modul at first when I did the configuration

Ok yes indeed it is working fine with a Serial BT Monitor.

I guess the problem come from the command I wanted to input. In fact, without ON/OFF buttons, the app and arduino works fine together and I receive well datas on my phone.

But with RUN/Stop buttons, this doesn't work anymore. I checked on the serial monitor and well receive the comand "A" or "B" when I click on them but the Arduino don't seem to run (The LED which usually bright when the Arduino works remain turned OFF).

Here is my new Arduino's code (just the loop part) :

And here are my blocks :

As I said, if I leave "Command" stuffs, all works fine with your clue (and I am thanksfull for that)

What is the var 'cmd' type? I'd use an integer, 1 run 0 stop.

I can't see how your loop has a time interval applied - this is required for the App to have time to receive and process data and should be as long as is practical for the task.

Change your If to

If [input]

 cmd xxxxx

else [output]

  data xxxxx

Sorry, I am not sure to understant :

  • I should use intergers 1 and 0 instead of "A" and "B" ?
  • About the time interval, I set a delay of 400ms so indeed the app have the time to read and process datas (I made test and it works well like that).
  • At least, I don't understand this point :

image

Hi Arthur

Are you displaying the values in the App? If so, 400ms is too fast for most eyes :thinking: The App time interval needs to be approx 20% shorter than the Elegoo time interval to avoid data over-run. Ideally, we would not use a delay() as that stop-starts everything, whereas a time elapsed loop does not.

Can you post your Sketch File here? Change it's extension from .ino to .txt

The purpose of the modification to 'If' is to prevent send-receive at the same time, since you only have one channel between App and Elegoo.

You don't have to, it's common practice that's all. (1 = True, 0 = False).

Yes sure, here is my App sketch :
Last_Version_V3_with_on_off_buttons.aia (207.1 KB)

And here is my Arduino sketch :
sketch_Water_level_ON_OFF_V2.txt (2.0 KB)

For the delayI definitely miss something. Indeed 400ms is really hight for us but the App seem to be very slow if I put 500ms or more. On the clock in the App I input a delay of 100ms.

Oh ok I see