# ESP32 Bluetooth transmission problem

**URL:** https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730
**Category:** Electronics (Arduino, etc.)
**Created:** [February 8, 2025, 2:22pm UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730 "2025-02-08T14:22:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 8, 2025, 2:22pm UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/1 "2025-02-08T14:22:20Z")

</div>

Part of the Arduino function is as follows：

```auto
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]);
  }
}

```

```auto
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.

> **[GitHub - Protocentral/protocentral\_openview: GUI for plotting/storing data from ProtoCentral...](https://github.com/Protocentral/protocentral_openview)**
>
> GUI for plotting/storing data from ProtoCentral breakouts

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

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [February 8, 2025, 3:38pm UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/2 "2025-02-08T15:38:38Z")

</div>

Hello @cola,

> [@cola](#):
>
> In my serial port debugging, SerialBT.printf () displays normally, but in processing, no data is received.

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

> **[Standard Serial over Bluetooth on Windows 10](https://community.element14.com/technologies/internet-of-things/b/blog/posts/standard-serial-over-bluetooth-on-windows-10)**
>
> I've recently been doing more work with BLE devices and communicating with them using my Windows PC.  I've mainly been using WebBLE - most recently with the Nicla Sense ME.I've started using MIT App Inventor to create apps for my iOS and Android...

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.

> **[List of terminal emulators](https://en.wikipedia.org/wiki/List_of_terminal_emulators)**
>
> This is a list of notable terminal emulators. Most used terminal emulators on Linux and Unix-like systems are GNOME Terminal on GNOME and GTK-based environments, Konsole on KDE, and xfce4-terminal on Xfce as well as xterm.

`:)`

---

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 9, 2025, 9:40am UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/3 "2025-02-09T09:40:39Z")

</div>

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:

```auto
#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.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/6/d692147ee20960678d9775034e5af14b3e39b7c2.png)

---

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 9, 2025, 9:57am UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/4 "2025-02-09T09:57:31Z")

</div>

I can receive data but the waveform drawn is not ECG

 ![7535a4c538b05b37f17753be90f9a86](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/3/33bc7cc518b350645cf9959220d331395f952098.png)  
🥲

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

---

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 9, 2025, 11:03am UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/6 "2025-02-09T11:03:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 9, 2025, 2:33pm UTC](https://discourse.processing.org/t/esp32-bluetooth-transmission-problem/45730/7 "2025-02-09T14:33:11Z")

</div>

> [@cola](#):
>
> I can receive data but the waveform drawn is not ECG

ECG/esp example

> **[ECG Monitoring system using AD8232 with Arduino or ESP32 IOT Based – Circuit...](https://www.circuitschools.com/ecg-monitoring-system-using-ad8232-with-arduino-or-esp32-iot-based/)**
