// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
analogReadResolution(16);
SerialUSB.begin(9600);
}
void loop() {
int i;
float voltage;
int sensorValue;
unsigned long elsp=millis();
for (i=0;i<10000;i++)
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
}
Serial.println(millis()-elsp);
Serial.println("waiting...");
delay(10000);
}
Code return 1150ms, it means 9,695 samples per second.
If Serial bytes are transmitted to the ESP32 by UART and then the ESP32 sends the Serial bytes over Bluetooth, the sampling rate drops to 230 times per second...
Who can tell me how to achieve efficient transmission and avoid lowering sampling frequency as much as possible?
@DrDiettrich@UKHeliBob
I did not define the data format, I tried to increase it to 1000000 baud rate, but the packet loss was serious. I changed the baud rate configuration for SERIAL_8N2, SERIAL_8E2
Serial1.begin(1000000,SERIAL_8E2);
No significant improvement, any tips on keeping baud rates high and not losing packets?
I intend to implement ESP Bluetooth to send at least 1000 samples per second with a 6-channel sensor,in practice, however, ESP was poor at receiving sensor data
The Serial port baud rate on the ESP needs to be at least as fast as the Serial1 baud rate, otherwise you will be overrunning the Serial1 input buffer while waiting for Serial. You appear to be getting a lot of 5-digit numbers from the analog ports, that can potentially be 36 characters for each set of samples. At 1000 samples per second, that is 36,000 characters, and with 8N2 (11 bits/character), 396,000 bits/second. 115200 baud is only capable of 11,520 characters/second at the standard 8N1.