Serial data through bluetooth HC-05 \ 06 to display

Thanks for checking this post out! I’m creating a healthcare product that takes information from a force sensor, sends it over a Bluetooth HC-05 to the HC-06. It works GREAT using the serial monitor only OR using a Bluetooth to phone app. Once I add the LED code however, both the LED & serial monitor readings are a mess. If I use just the LED to try to read the serial sensor data, that doesn’t work either & it displays random numbers. Is there some sort of rate mismatch, poor coding or other difficulty in reading Bluetooth serial data & sending it to a display ?

Reward for the solution if in the USA
Thanks!! Mike

Heres the HC-06 receive code where I used // to remove the serial monitor code to no avail

#include <TM1637Display.h>
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX

const int CLK = 2; //Set the CLK pin connection to the display
const int DIO = 3; //Set the DIO pin connection to the display

TM1637Display display(CLK, DIO);  //set up the 4-Digit Display.
 
void setup() 
{
//  Serial.begin(9600);
 // Serial.println("Enter AT commands:");
 
  BTSerial.begin(9600);  
  
 display.setBrightness(0x0a);  //set the diplay to maximum brightness
}
 
void loop()
{
 
  // Keep reading from HC-06 and send to Arduino Serial Monitor
  if (BTSerial.available())
 display.showNumberDec(BTSerial.read());
  delay(1000);
  
  // if (BTSerial.available())
 //   Serial.write(BTSerial.read());
    
}

tunaman4u2:
It works GREAT using the serial monitor only OR using a Bluetooth to phone app.

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
(CLK, DIO);  //set up the 4-Digit Display.

void setup()
{
//  Serial.begin(9600);
// Serial.println(“Enter AT commands:”);

It might pay to list carefully what you have succeeded in doing so far and what you really want to do from here. A good starting point would be to confirm or otherwise that you have managed to have the two bluetooth modules connect to each other.
Then re-post the code that reflects the intention, and omit the probably spurious junk that is not part of your intention.

BTSerial.read() returns a single char. A char is essentially a 8-bit number that represents an ASCII character. You will need to write the characters to a buffer and then convert that buffer to a numeric value. If this seems unclear to you, please post your sending code too (for the arduino with the sensor).

cyber__creeper: BTSerial.read() returns a single char. A char is essentially a 8-bit number that represents an ASCII character. You will need to write the characters to a buffer and then convert that buffer to a numeric value. If this seems unclear to you, please post your sending code too (for the arduino with the sensor).

Thanks for the response. The code as written works perfectly for the Bluetooth module & the serial monitor for the correct 3 digit numbers... Are you saying that I need to use something different than BTSerial.read() for the Tube LED display?

No, BTSerial.read() is correct. Look, when you print to the serial monitor your program does this:

  • A char (first digit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the first char, it is printed to the serial monitor
  • Your loop() code finishes and restarts (you are at the beginning of the loop again)
  • Another char (seconddigit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the second char, it is printed to the serial monitor
  • The loop() code finishes again

So what you have to do is read all characters - you could use while(BTSerial.available()) {}. When all digits have been read, you have to convert them to the correct number type - for any 3-digit integer that would be atoi() (converts a string to an integer). So your loop code should look like this:

byte buf[4] = "";
byte count = 0;
while(BTSerial.available() && count < 3) {
  buf[count] = BTSerial.read();
  count++;
}
if(buf[0] != '\0') {
  buf[3] = '\0';
  display.showNumberDec(atoi(buf));
}

If this doesn´t work, please post the code that reads from the sensor and sends the data to your second arduino.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

cyber__creeper:
No, BTSerial.read() is correct. Look, when you print to the serial monitor your program does this:

  • A char (first digit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the first char, it is printed to the serial monitor
  • Your loop() code finishes and restarts (you are at the beginning of the loop again)
  • Another char (seconddigit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the second char, it is printed to the serial monitor
  • The loop() code finishes again

So what you have to do is read all characters - you could use while(BTSerial.available()) {}. When all digits have been read, you have to convert them to the correct number type - for any 3-digit integer that would be atoi() (converts a string to an integer). So your loop code should look like this:

byte buf[4] = "";

byte count = 0;
while(BTSerial.available() && count < 3) {
  buf[count] = BTSerial.read();
  count++;
}
if(buf[0] != ‘\0’) {
  buf[3] = ‘\0’;
  display.showNumberDec(atoi(buf));
}




If this doesn´t work, please post the code that reads from the sensor and sends the data to your second arduino.

I’ll give this a try when I get home, thanks.
As of now the screen will only give me 48 & 56 as numbers for some reason & the serial monitor only gives me odd digits as well (when trying to use both). It almost appears as if the Arudino isn’t able to handle the data
When I use just the app or the serial monitor. 3 digit data is perfect! Go figure.

cyber__creeper:
No, BTSerial.read() is correct. Look, when you print to the serial monitor your program does this:

  • A char (first digit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the first char, it is printed to the serial monitor
  • Your loop() code finishes and restarts (you are at the beginning of the loop again)
  • Another char (seconddigit) arrives - BTSerial.available() is true
  • BTSerial.read() returns the second char, it is printed to the serial monitor
  • The loop() code finishes again

So what you have to do is read all characters - you could use while(BTSerial.available()) {}. When all digits have been read, you have to convert them to the correct number type - for any 3-digit integer that would be atoi() (converts a string to an integer). So your loop code should look like this:

byte buf[4] = "";

byte count = 0;
while(BTSerial.available() && count < 3) {
  buf[count] = BTSerial.read();
  count++;
}
if(buf[0] != ‘\0’) {
  buf[3] = ‘\0’;
  display.showNumberDec(atoi(buf));
}




If this doesn´t work, please post the code that reads from the sensor and sends the data to your second arduino.

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

…R

No luck with the code from CyberCreeper. The data numbers did change but were only 2 digits & not accurate to the sensor data. Again the HC-05 & HC-06 give PERFECT data to the serial monitor & the Android app, I just cant get it to put the same data on the Tube LED

REWARD IS STILL AVAILABLE TO ANYONE WHO CAN HELP

I’m gonna try a more serial friendly screen in the meantime. Maybe the TM1637 isn’t playing nice

Maybe SoftwareSerial isn’t playing nice & somehow not transmitting data through CLK & DIO well either.

I just cant get it to put the same data on the Tube LED

Well, I have no idea what you mean by put "the same data" on "the Tube LED", so I guess I won't be qualifying for any reward, even though I do live in the US.

Post your current code. Post some sample data sent to the Arduino from the Serial Monitor or Android app. Describe what "the Tube LED" means. Then, maybe, we can help.

PaulS: Well, I have no idea what you mean by put "the same data" on "the Tube LED", so I guess I won't be qualifying for any reward, even though I do live in the US.

Post your current code. Post some sample data sent to the Arduino from the Serial Monitor or Android app. Describe what "the Tube LED" means. Then, maybe, we can help.

Thanks for responding Paul: The Tube LED is the 4 bit TM1637 display in the right of the picture TM1637 at GearBest

The data is the 0-400 readings that come from the force sensor in the left of the picture

Code is in the 1st post

Code is in the 1st post

But, it has been pointed out that that code (or the code that WAS in the 1st post) is wrong.

Can you display anything to the "Tube LED" device?

That link is useless, as there are NO details about the device.

PaulS: But, it has been pointed out that that code (or the code that WAS in the 1st post) is wrong.

Can you display anything to the "Tube LED" device?

That link is useless, as there are NO details about the device.

The code as written is PERFECT for the serial monitor & the Android app. The problem is that the code doesnt transmit to the TM1637 correctly, yes it does display random 2 digit numbers, nothing like the actual sensor data though. Im starting to think that SerialSoft is not playing nice with the additional TM1637 program because it also affects the serial monitor data if I have that running. Take out the TM1637.h & things work fine. I may need to use AltSerialSoft or a different LED that doesnt need the extra program. I read somewhere last night that Serialsoft has a hard time with too much data relay.

As for the info on the TM1637, its all I got bud, sorry, its a cheap ass display.

Im starting to think that SerialSoft is not playing nice

Is that any relationship to SoftwareSerial?

You are trying to debug a very complex application all at once. Give yourself a break.

Take ONE Arduino with the tube thing connected, and get it to display numbers, from 0 to 9999 for one second at a time. Yes, you can use delay().

ONLY when you KNOW that the display is working should you attempt to incorporate it in the project.

PaulS: Is that any relationship to SoftwareSerial?

You are trying to debug a very complex application all at once. Give yourself a break.

Take ONE Arduino with the tube thing connected, and get it to display numbers, from 0 to 9999 for one second at a time. Yes, you can use delay().

ONLY when you KNOW that the display is working should you attempt to incorporate it in the project.

The TM1637 works perfectly fine when Im not using SoftwareSerial or sending information over the bluetooth of course.

The TM1637 works perfectly fine when Im not using SoftwareSerial or sending information over the bluetooth of course.

Of course. That was perfectly obvious to anyone in the room with you.

Spoke to SparkFun about their 7 Segment Serial LED. They recommended trying UART for that so hopefully I can get that running tonight if not...

THE REWARD IS A $50 Amazon Gift Card by the way

Any help is greatly appreciated.

UART serial LED worked great, data is spot on with the serial monitor now that the TM1637 code is out! Only thing is I have the data connected from the Bluetooth directly to the Serial 7 segment display so the data scrolls.

So… I simply need the right code now to get the 0 to 3 digit data to display statically. I’m not sure how to get the incoming Bluetooth data onto another pin so I can add that code either but this seems like a pretty easy task.

Again, appreciate any help! Thanks!

Heres the new simplified code

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
 
void setup() 
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(9600);
}
 
void loop()
{
 
  if (BTSerial.available())
Serial.write(BTSerial.read());
 
  
}

tunaman4u2: Again, appreciate any help! Thanks!

The help I offered in Reply #5 seems to have been entirely ignored.

...R

So... I simply need the right code now to get the 0 to 3 digit data to display statically. I'm not sure how to get the incoming Bluetooth data onto another pin so I can add that code either but this seems like a pretty easy task.

The bluetooth data is NOT coming in on the same pins as the tube device.

The problem is that you read from one set of pins, and immediately write that another set of pins.

Read the data. Store it, until the end of data marker arrives. THEN, display the stored data/value.

Robin2: The help I offered in Reply #5 seems to have been entirely ignored.

...R

PaulS: The bluetooth data is NOT coming in on the same pins as the tube device.

The problem is that you read from one set of pins, and immediately write that another set of pins.

Read the data. Store it, until the end of data marker arrives. THEN, display the stored data/value.

I've read all your posts, I researched everything you guys said. Its clear I don't know what the hell I'm doing :stuck_out_tongue_closed_eyes: . I'm a physical therapist way out of his element trying to make a product for my patients.

So I agree with Read, store, display but I don't know the code to get this data from the SoftwareSerial input pin through the Arudino and to an output pin.