HC-05 Bluetooth module - laggy transmition

Hello!

I'm working on a project which consists in a bluetooth pulseoximeter using Arduino Nano, HC-05 BT module and GY-MAX30100 pulseoximeter sensor.

When I want to receive the infos through BT connection on serial monitor, the screening is very laggy. So laggy that it is merging the strings into one as you can see in the following photo. The info that I should get is " BPM: x.xx SpO2: x%". Does anybody know what should I do? Reporting period is set to 1000 ms, baud rate of serial monitor is set to 1152000 and baud rate of bluetooth pins is 9600. I tried tons of combinations of baud rate and reporting periods but nothing helped.

I have to mention that on USB connection it works perfect!

You can find the code here:

#include <Wire.h>
#include <SoftwareSerial.h> 
#include <LiquidCrystal_I2C.h>  
LiquidCrystal_I2C lcd(0x27,16,2); 
#include "MAX30100_PulseOximeter.h"  
SoftwareSerial blue(2,3); 

#define REPORTING_PERIOD_MS 1000  


PulseOximeter pox;   
uint32_t tsLastReport = 0;   

void onBeatDetected()  
{
Serial.println("Beat!");
}

void setup()
{
Serial.begin(115200);  
blue.begin(9600);     
lcd.init(); 
lcd.backlight();
lcd.home(); 
Serial.print("Initializing pulse oximeter..");



if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); 

pox.setOnBeatDetectedCallback(onBeatDetected);


}

void loop()
{
Serial.println("what"); 

pox.update();  
if (millis() - tsLastReport > REPORTING_PERIOD_MS)  
                                                   
{


"
blue.print("BPM: ");    
blue.print(pox.getHeartRate());
//blue.println("\n");


blue.print(" SpO2: ");
blue.print(pox.getSpO2());
blue.print("%");
blue.println("\n");


lcd.clear();
lcd.setCursor(0,0);
lcd.print("BPM: ");
lcd.print(pox.getHeartRate());

lcd.setCursor(0,1);
lcd.print("SpO2: ");
lcd.print(pox.getSpO2());
lcd.print("%");

tsLastReport = millis();

}


}

Thank you in advance!

Where is your code?
Where is your description of the hardware side?

do yourself a favour and please read How to get the best out of this forum (use code tags and provide necessary documentation of your ask).

Hello!
I am sorry, this is my first time on this forum and also my first time using Arduino. Now I uploaded the code and the hardware info you can find in the beggining of the post.

Thank you!

Have you timed how long this takes ?

(Same for the other call)

Please post the code which gives the output you posted. There is no serial printing in the code shown.

I think that you should only call the two .get reading functions once at the start of loop, and use the values you get for both bluetooth and lcd printing.

You don't need the repeated calls

No, I haven’t, that is literally the code uploaded to the board

This is the code uploaded to the board. That’s all. I am very newbie in this and I don’t know how to do it

Run a simple code and time how long it takes to get the readings.

See my loopTimer class for a simple loop timer which prints max and average loop times.
LCD prints can be slow.

I bet you are blaming the wrong thing. Bluetooth is printing virtually nothing, and half of what it is printing is redundant anyway. Much the same can be said for the LCD, but the real problem may be in the way you actually get the data. The fact that you are calling the same data twice, AND printing redundant data, AND clearing the LCD each trip round the loop ALL put you at a disadvantage - particularly the last, and that quite apart from any sluggishness in the sensor, which I know nothing about. You say it works with USB, so if you just cut out all the LCD stuff, you may find it will go like a rocket with Bluetooth, and thus prove the point. The code looks incomplete. You might check to see if it what you posted actually compiles, I would be surprised if it does. Also, you might spare us of some of the unnecessary whitespace.

All I see is a total absence of data, which is probably more to the point.

That’s kinda my point. Seems the sensor - assuming it works and is connected in the right way - does not return anything and may be it’s just a timeout thingy that creates the delay.

At this stage it’s not even about the loop speed or making things more complicated… there are more fundamental issues here…

OP see.s to use MAX30100_PulseOximeter.h and her/his code does not match the syntax of the examples..

That is the code that I am actually running. I took it from the internet because this is my first code ever. The device should run on bluetooth at the end of the day so I can not give up on it.
I get infos from the sensor, it works very well, in the printscreen i have shown you i did just an example of how i get the transmition on the serial monitor. I get good results if I put my finger on the pulseoximeter sensor. My problem are those united strings "BSpO2". I will make a demo video in the next post.

Sorry if I'm not explaining very well, this is my first contact ever with Arduino.

I find that difficult to accept.
Where is the word "what". It should be printed every loop.

How do you get the serial monitor to show both the blue.print messages and the lcd.print messages?

I have to mention that on USB connection it works perfect!

Please post the code which works perfectly with USB.

The code running perfectly on usb is basically this code but without the LCD part because i haven't purchased it at tat time.

#include <Wire.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include "MAX30100_PulseOximeter.h"

 
 
#define REPORTING_PERIOD_MS     1000
 
 
PulseOximeter pox;
uint32_t tsLastReport = 0;
 
void onBeatDetected()
{
    Serial.println("*");
}
 
void setup()
{
    Serial.begin(9600);

  
    Serial.print("Se initializeaza pulsoximetrul");
  
 
  
    if (!pox.begin()) {
        Serial.println("Esuat!");
        for(;;);
    } else {
        Serial.println("Succes!");
    }
     pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    
    pox.setOnBeatDetectedCallback(onBeatDetected);
 
  
}
 
void loop()
{
    
      pox.update();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Serial.print("Ritm cardiac");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");
 
        tsLastReport = millis();
        
        
    }
 
 
}

This code also had the same behaviour on bluetooth.

I really don't know

Thanks. Now you are giving us someplace to start from.

This code also had the same behaviour on bluetooth.

Correct. The HC05 can be connected to the hardware serial pins 0 and 1 after the code is loaded to the board, and output will be seen on both the phone and the serial monitor. Input can come from the phone only.

This is an acceptable way to run bluetooth output from a program.

It appears that you want to have output on a lcd as well as the phone and the serial monitor. Is that correct?

How do you want to modify the working program you posted?

I want the bluetooth to run on a computer so serial monitor is just fine. I don't use a phone app. I want the info to be shown both on serial monitor via bluetooth and on lcd.

But the USB working program has the same problem on bluetooth, the same laggy screening

Thank you! And I'm sorry again for my poor knowledge.

If the USB Serial program works correctly, but when the output is from the HC05 to some bluetooth adaptor/dongle or internal pc bluetooth module the issue maybe on the pc side.

Do you have an Android phone yo can use for testing purposes? A basic Serial Bluetooth Terminal https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US&gl=US app is all you need.

If we can show that the HC05 output to a phone is fast and not laggy, (similar to the usb output to the monitor), but different from the HC05 output to the pc bluetooth you will know that the issue is on the pc side.

I have only a Huawei available but it is not supporting google services. I will search for one tomorrow and I will come back with a reply. I will also check this code on another PC.

Thank you for your help!