ESP32 Bluetooth transmission problem

Part of the Arduino function is as follows:

void sendDataThroughUART(void){

  DataPacket[0] = ecgFilterout;
  DataPacket[1] = ecgFilterout >> 8;
  DataPacket[2] = resWaveBuff;
  DataPacket[3] = resWaveBuff >> 8;

  DataPacket[4] = globalRespirationRate;
  DataPacket[5] = globalRespirationRate >> 8;
  DataPacket[6] = globalHeartRate;
  DataPacket[7] = globalHeartRate >> 8;
  DataPacket[8] = 0;

  //send packet header
  for(int i=0; i<5; i++){

    SerialBT.write(DataPacketHeader[i]);
  }

  //send 30003 data
  for(int i=0; i<DATA_LEN; i++) // transmit the data
  {
    SerialBT.write(DataPacket[i]);
  }

  //send packet footer
  for(int i=0; i<2; i++){

    SerialBT.write(DataPacketFooter[i]);
  }
}
void loop() {
  if (SerialBT.connected()) {
      ads1292OutputValues ecgRespirationValues;
      boolean ret = ADS1292R.getAds1292EcgAndRespirationSamples(ADS1292_DRDY_PIN,ADS1292_CS_PIN,&ecgRespirationValues);
    
      if (ret == true)
      {
        ecgWaveBuff = (int16_t)(ecgRespirationValues.sDaqVals[1] >> 8) ;  // ignore the lower 8 bits out of 24bits
        resWaveBuff = (int16_t)(ecgRespirationValues.sresultTempResp>>8) ;
        SerialBT.printf("ECG: %d, Resp: %d\n", ecgWaveBuff, resWaveBuff); // 打印原始数据
        if(ecgRespirationValues.leadoffDetected == false)
        {
          ECG_RESPIRATION_ALGORITHM.ECG_ProcessCurrSample(&ecgWaveBuff, &ecgFilterout);   // filter out the line noise @40Hz cutoff 161 order
          ECG_RESPIRATION_ALGORITHM.QRS_Algorithm_Interface(ecgFilterout,&globalHeartRate); // calculate
          respFilterout = ECG_RESPIRATION_ALGORITHM.Resp_ProcessCurrSample(resWaveBuff);
          ECG_RESPIRATION_ALGORITHM.RESP_Algorithm_Interface(respFilterout,&globalRespirationRate);
        }else{
          ecgFilterout = 0;
          respFilterout = 0;
        }
    
        sendDataThroughUART();
      }
  } 
}

In my serial port debugging, SerialBT.printf () displays normally, but in processing, no data is received. How can I debug this? I don’t know if it’s because of a problem with Bluetooth transmission or something else. I did not modify any transmission protocol, I just converted the serial port transmission to Bluetooth to see if it is feasible. Below is the serial port protocol connection.

I hope someone can provide debugging suggestions, thank you very much! :smiling_face_with_tear:

Hello @cola,

Do you serial over Bluetooth set up correctly on your PC?

Try some simple code and just send a single character and try to receive that on Processing or any other terminal emulator that connects to a serial port.

You must select correct COM port, BAUD rate, etc.

:)

I used a simple example to test Bluetooth transmission, and everything worked fine. I think this may be related to the fact that serialBT.write() does not have its own delimiter when writing, because the data I see on the serial monitor is continuous.
The example to test Bluetooth transmission code:

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

// define deviceName
const char *deviceName = "ESP32_BT_Example";

// counter
int count = 0;

void setup() {
  Serial.begin(115200);
  
  // initial Bluetooth
  if (!SerialBT.begin(deviceName)) {
    Serial.println("Bluetooth initialization failed!");
    while (1);
  }
  
  Serial.println("Bluetooth is activated, waiting for connection...");
  Serial.print("deviceName:");
  Serial.println(deviceName);
}

void loop() {
  // waiting for connection
  if (SerialBT.connected()) {
    // send data 
    String message = "Hello World #" + String(count++);
    SerialBT.println(message);
    
    Serial.println("sendmessage:" + message);
    senddata();
  } else {
    Serial.println("waiting for connection...");
  }

  delay(1000);  
}
void senddata(){
  const char DataPacketHeader[5] = {0x01, 0x02, 0x03, 0x04, 0x05};
  for (int i = 0; i < 5; i++) {
      SerialBT.write(DataPacketHeader[i]);
  } 
  SerialBT.write(0x0A); 
}

In addition, I also saw that the transmission packet on the Bluetooth transmission serial port complies with the transmission protocol.
This may be back to the previous transmission protocol problem.

I can receive data but the waveform drawn is not ECG


:smiling_face_with_tear:

And the data receiving speed is much slower than the serial port output.

The redundant delay added during my Bluetooth transmission caused data transmission problems. Thanks for your answer, I solved my problem! :flushed:

1 Like

ECG/esp example

2 Likes