Hello! I need help with a coding project. I'm trying to get an XIAO RP2040 to send a message to another RP2040 through serial, and then have the receiving RP2040 display a message on the serial monitor. I need the code to be in Arduino CPP, not Micropython.
ChatGPT said: Hey! I’ve got you covered. Here's a basic example of how to set up serial communication between two XIAO RP2040 boards using Arduino C++.
🧩 What You’ll Need: Two XIAO RP2040 boards
Common ground connection
TX from sender to RX of receiver, and vice versa (optional if unidirectional)
✅ Sender Code (Transmitter) This XIAO RP2040 sends a message through the Serial1 port:
void setup() {
// Start Serial1 for TX/RX communication
Serial1.begin(9600);
}
void loop() {
// Send a message
Serial1.println("Hello from Sender!");
delay(1000); // send every second
}
✅ Receiver Code (Receiver) This board reads from Serial1 and displays it via the USB Serial monitor:
void setup() {
// Start USB Serial for debug output
Serial.begin(9600);
// Start Serial1 for receiving messages
Serial1.begin(9600);
}
void loop() {
if (Serial1.available()) {
String msg = Serial1.readStringUntil('\n');
Serial.println("Received: " + msg);
}
}
🔌 Wiring Notes
Pin Sender Receiver
TX (D6) → RX (D7)
GND ↔ GND
TX (Sender) → RX (Receiver)
Make sure the voltage levels match (they do on RP2040s).
Use Serial1 which maps to D6 (TX) and D7 (RX) on the XIAO RP2040.