UART (Serial1) communication between XIAO ESP32C3 and Raspberry Pi Pico (RP2040), in Arduino framework.

This exercise show UART (Serial1) communication between XIAO ESP32C3 and Raspberry Pi Pico (RP2040), in Arduino framework.


Connection:
    Pico TX GP0 (pin 1) <-----> XIAO ESP32C3 RX GPIO20 (pin 8)
    Pico RX GP1 (pin 2) <-----> XIAO ESP32C3 TX GPIO21 (pin 7)
    Pico GND                  <-----> XIAO ESP32C3 GND



Code:

The main issue for this exercise is how to handle Serial1.begin() for XIAO ESP32C3.
Ref: https://wiki.seeedstudio.com/XIAO_ESP32C3_Pin_Multiplexing/#serial---uart

There is no Serial2 for XIAO ESP32 C3. Also If you need to use Serial1, you must define the pins; otherwise, it may not receive data.

For XIAO ESP32 series, use Serial1 as follows:
    Serial1.begin(115200, SERIAL_8N1, RX, TX);

rp_SerialPassthrough_115200_8N1.ino
/*
  UART/Serial1 exercise run on Raspberry Pi Pico (rp2040)/Arduino Mbed OS RP2040 Boards 4.1.5
  Modified from from Arduino Examples > Communiction > SerialPassthrough
*/

void setup() {
  delay(500);
  Serial.begin(115200);
  while(!Serial){};

  Serial.println("===========================================================================================");
  Serial.println("UART/Serial1 exercise run on Raspberry Pi Pico (rp2040)/Arduino Mbed OS RP2040 Boards 4.1.5");
  Serial.println("===========================================================================================");
  Serial.println("SERIAL1_TX:\t" + String(SERIAL1_TX));
  Serial.println("SERIAL1_RX:\t" + String(SERIAL1_RX));
  Serial.println();

  Serial1.begin(115200);  

}

void loop() {

  if (Serial.available()) {        // If anything comes in Serial (USB),
    Serial1.write(Serial.read());  // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {       // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());  // read it and send it out Serial (USB)
  }

}


XIAOC3_SerialPassthrough_115200_8N1.ino
/*
  UART/Serial1 exercise run on XIAO ESP32C3/arduino-esp32 3.0.4
  Modified from from Arduino Examples > Communiction > SerialPassthrough
*/

void setup() {
  delay(500);
  Serial.begin(115200);
  delay(1000);

  Serial.println("=============================================================");
  Serial.println("UART/Serial1 exercise run on XIAO ESP32C3/arduino-esp32 3.0.4");
  Serial.println("=============================================================");
  Serial.printf("TX: %d\n", TX);
  Serial.printf("RX: %d\n", RX);
  Serial.println();

  //Serial1.begin(115200);  
  /* 
  In my test on XIAO C3 and arduino-esp32 3.0.4,
  this code not work, even it make the board un-recognized by PC.
  To program it again, have to make it in BOOTLOADER by holding the BOOT button and press the RESET button.
  ref:
  https://wiki.seeedstudio.com/XIAO_ESP32C3_Pin_Multiplexing/#serial---uart
  */

  Serial1.begin(115200, SERIAL_8N1, RX, TX); // RX, TX
}

void loop() {

  if (Serial.available()) {        // If anything comes in Serial (USB),
    Serial1.write(Serial.read());  // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {       // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());  // read it and send it out Serial (USB)
  }

}


Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.