Skip to content

ESP32 Serial Bluetooth loses data while receiving #2577

@JoaquinPine

Description

@JoaquinPine

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.0
IDE name: Arduino IDE? Platform.io IDF component
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 7

Description:

Hi. Im working in a project. I have designed an App in my phone with Processing APDE. It only sends bytes using Bluetooth. The esp32 that im using is supposed to receive this bytes but there are a lot of them that are lost. Im sending an array that contains 5220 bytes from my Phone. Using the example code of SerialBluetooth didn't work so I started to change things in order to fix this problem but i couldn't. This array contains the green color value of an image of 180 x 29 pixels.

When I change the delay time also changes the received data. In the code I put a counter to know how many bytes is receiving de BT and then print the data received. This value changes when the delay is modified. I also tried to use timer functions in order to not block de program but didn't worked.

Anyone knows how to fix this? I have been reading lots of Issues and it seems that there was a problem with some congestion event, but it was fixed some time ago. I think that i have de lastest version of the Arduino Core for ESP32.

Thanks in advance.

The code

#include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino
#include "vfs_api.h"
BluetoothSerial ESP_BT; //Object for Bluetooth

unsigned char incoming[5220];
int i = 0;
int n =0 ;
//hw_timer_t * timer = NULL;
int espera = 1;

/void IRAM_ATTR onTimer(){
espera=1;
}
/

void setup() {
Serial.begin(9600); //Start Serial monitor in 9600
ESP_BT.begin("Nuclex Holographic"); //Name of your Bluetooth Signal
Serial.println("Bluetooth Device is Ready to Pair");
/timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true); // edge (not level) triggered
timerAlarmWrite(timer, 5, true);
timerAlarmEnable(timer); // enable
/

}

void loop() {

if (ESP_BT.available()) //Check if we receive anything from Bluetooth
{

incoming[i] = ESP_BT.read();

i++; //counter bytes
delayMicroseconds(5);}
/if(espera==1) espera=0;
else return;
/

}else if ( i != 0){

Serial.print("bytes:");
Serial.print(i);
Serial.print("\n");
n=0;
for(n=0;n<i;n++){
Serial.println(incoming[n]);

incoming[n]=0;
}
//Serial.println(incoming[5219]);
i=0;
}
}

Serial Monitor Arduino with 5us of delay
bytes:2498
4
4
4
4
4
...
Serial Monitor Arduino with 3us of delay
bytes:1895
4
4
4
4
4
...
Serial Monitor Arduino with 6us of delay
bytes:2141
4
4
4
4
4
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions