I use two board: ESP32 DEVIKIT V1 and Seeeduino XIAO.
XIAO is arduino hardware, code:
void setup()
{
analogReadResolution(16);
SerialUSB.begin(9600);
Serial1.begin(1000000);
while (!Serial1){};
}
// arduino设置16采样位,采样8通道的传感器数值
// ESP通过uart接收采样数据,然后传到蓝牙的TX参数发送notify
void loop()
{
int i;
unsigned long elsp = millis();
for (i = 0; i < 50; i++)
{
// read the input on analog pin 0:
Serial1.printf("%d:%d:%d:%d:%d:%d:%d:%d", analogRead(A0), analogRead(A1), analogRead(A2), analogRead(A3), analogRead(A4), analogRead(A5),analogRead(A6),analogRead(A7));
Serial1.println();
}
Serial1.printf("XIAO Time: %d \n", millis() - elsp);
Serial1.println(Serial1.availableForWrite());
SerialUSB.println(millis() - elsp);
SerialUSB.println("waiting...");
delay(5000);
}
ESP32 code:
void setup()
{
Serial.begin(1000000);
Serial1.begin(1000000, SERIAL_8N1, 16, 17);
while (!Serial)
{
};
Serial.println("Set Serial1 ok!");
}
String xiao = "";
void loop()
{
unsigned long elsp = millis();
if (Serial1.available() > 0)
{
if (Serial1.peek() != '\n')
{
xiao += (char)Serial1.read();
}
else
{
Serial1.read();
Serial.println(xiao);
xiao = "";
}
}
}
Only by reducing arduino's Analogread () to 6 can ESP read the value of the 6-channel SENSOR of UART:
I tried adding program headers to amplify the buffer:
#define SERIAL_TX_BUFFER_SIZE 4096
#define SERIAL_RX_BUFFER_SIZE 4096
But the ESP couldn't receive it and could only read the 6-channel sensor, while the Arduino serial computer could read the 8-channel sensor
Is it UART restriction or something? How can I solve the problem?