Appearance
Week 11 - Networking and Communications
Group Assignment
- Send a message between two projects
Group work
Communication between two XIAO-ESP32C3 with wire UART connection
Assignment: Send a message between two projects. This section I and Xu have tried to send a message between two ESP32-C3 broad with UART connection. One board (Master) sends a message "ON"
to the other board (Slave), which turns on an LED upon receiving the command.
Materials Needed
- 2× ESP32-C3 boards
- 1× LED
- 1× Resistor (220Ω recommended)
- Breadboard and jumper wires
- USB cables (for both boards)
- Arduino IDE
Circuit Setup
Slave Board (Receiving Side):
- Connect LED anode (longer leg) to GPIO 2 through a resistor
- Connect LED cathode to GND
Wiring Between Xiao-ESP32 Boards: - Master TX → Slave RX
- Master RX → Slave TX
- Master GND → Slave GND
Master Code (Sender - Board 1)
void setup() {
Serial1.begin(9600, SERIAL_8N1, 20, 21); // RX=20, TX=21(D7, D6)
}
void loop() {
Serial1.write('a'); // led on
delay(4000);
Serial1.write('b'); // led off
delay(4000);
}
Slave Code (Receiver - Board 2)
#define led1 D2
// #define led2 9
// #define led3 10
void setup() {
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, 20, 21); // RX=20, TX=21(D7, D6)
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
}
void loop() {
while (Serial1.available()) {
char c = Serial1.read();
Serial.print("Received: ");
Serial.println(c);
if (c == 'a') {
digitalWrite(led1, HIGH);
Serial.println(c);
delay(1000);
} else {
digitalWrite(led1, LOW);
delay(1000);
}
}
}
Steps to Execute
- Connect the Boards: Use jumper wires to connect TX of Master to RX of Slave, and GND to GND.
- Upload Master Code: Connect Master board to PC and upload the master sketch.
- Upload Slave Code: Connect Slave board to PC and upload the slave sketch.
- Power the Boards: You can power both via USB or an external power source.
- Observe the Result: The LED on the Slave board will blink once every 2 seconds upon receiving the "ON" command from the Master.
Video 2025
The result is shown as video below.