The ESP cannot read the sensor values in the 8 channels through UART

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?

Can someone help me? :cry:I don't know why ESP32 not receive a string of eight five-character characters plus seven ':'

what happens if the XIAO transmits 8 values? e.g. some characters lost?
what happens if you have a delay after the Serial1.printf() in the XIAO code? does the ESP then receive 8 values?
avoid use String class - it is probably doing a realloc call every time you add a character which can fragment memory - use a char array of lenegth suitable to hold the maximum length of your data text

ESP32 no data was received, not a single character. console output is empty

so when the XIAO transmits 6 values the ESP displays OK whn you transmit 8 nothing is displayed?
are you sure the XIAO is transmitting the 8 values OK?
try putting some Srial.println() in the loop to check the program flow
what happens if you reduce the baud rate?

rather than transmitting text try raw binary in a byte array ?

I looked up the XIAO pinout and found this:

It looks as if Serial1 is using A6 as TX and A7 as RX ?!?

What happens if you change the seventh analogRead() from A6 to A8 and the eighth from A7 to A9?

I tried serial1.begin (1000000,SERIAL_8N2); There is no improvement effect. However, Xiao can give PC 8 channels of data, but ESP32 cannot receive it. If lowered to 6 channels, both ESP32 and PC can receive data

Oh I'm sorry! ESP32 is broken, we will fix this BUG when the new delivery arrives

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.