Fab Academy 2025

@ Fab Lab Rwanda, Kigali

Embedded Networking and Communications

Embedded Networking and Communications


Week 11 - Getting Two Boards to Talk

What we had to do

This week we needed to send a message between two projects. Sounds simple enough, right?
Well, it took us a few tries to get it working properly, but we figured it out in the end!

Our two XIAO boards finally talking to each other Serial monitor showing the communication

What we decided to build

We wanted to make something pretty cool - press a button on one board and have LEDs light up on BOTH boards. The idea was to use two XIAO RP2040 boards and make them communicate using serial communication (UART). We thought this would be easier than trying to do wireless stuff, and honestly, we were right!

How we made them talk - UART Serial

Instead of going with WiFi or Bluetooth (which seemed complicated), we decided to use good old UART serial communication. It's basically like having a conversation between two boards using just two wires. Pretty neat actually!

First XIAO board
Board 1 - This one sends the message
Second XIAO board
Board 2 - This one receives and responds

How UART works (in simple terms)

Think of it like walkie-talkies, but with wires:

Building the hardware

We used our custom XIAO RP2040 boards from previous weeks. Each one already had an LED and button wired up, which made things easier.

All the wires connecting our boards
The wiring between our two boards (it's messier than it looks!)
How we connected everything
Our connection diagram - the X-pattern is key!

How we wired everything

Board 1 Pin Board 2 Pin What it does
TX (Pin 0) RX (Pin 1) Board 1 talks to Board 2
RX (Pin 1) TX (Pin 0) Board 2 talks back to Board 1
GND GND Shared ground (super important!)
LED on D2 LED on D2 LEDs that light up
Button on D3 Button on D3 Buttons to press

Writing the code

The programming part was actually pretty straightforward once we figured out the logic. Both boards run almost the same code, just with tiny differences.

The basic setup stuff

#define LED_PIN D2
#define BTN_PIN D3
// These were the same on both boards
Uploading code to first board
Getting the code onto Board 1
Uploading code to second board
And onto Board 2

Setting up the communication

Serial1.begin(9600);  // Start talking at 9600 baud
// We tried other speeds but 9600 worked best

Sending the message

if (digitalRead(BTN_PIN) == LOW) {
  Serial1.println("LED_ON");  // Tell the other board to turn on its LED
  digitalWrite(LED_PIN, HIGH); // Turn on our own LED too
}

Listening for messages

if (Serial1.available()) {
  String message = Serial1.readString();
  if (message.indexOf("LED_ON") >= 0) {
    digitalWrite(LED_PIN, HIGH); // Turn on LED when we get the message
  }
}

Testing (and debugging!)

Let's be honest - it didn't work the first time. We had to debug a few things:

  1. First attempt: forgot to cross the TX/RX wires (oops!)
  2. Second try: had different baud rates on each board
  3. Third time: forgot the common ground connection
  4. Fourth attempt: SUCCESS! Both LEDs lit up when we pressed either button
Our final working setup
Final setup that actually worked
Testing the button press
The moment of truth - pressing the button!

The big demo!

When we finally got it working, it was pretty satisfying. Press one button, both LEDs light up almost instantly. The communication was fast and reliable.

Our working demo - both LEDs responding to one button press!

What we discovered

Things that worked really well:

Important lessons we learned:

Why we chose UART over other options

Communication Method Good stuff Not so good stuff
UART (what we used) Simple, reliable, fast, low power Need wires, short distance only
ESP-NOW No wires, works far apart Way more complicated, need ESP32 boards
I2C Can connect many devices More complex addressing system
SPI Super fast Need more wires, overkill for our project

What we learned

This project taught us a lot about communication between microcontrollers:

Overall, this was a really fun project! We managed to get two boards talking to each other using serial communication. It might not be as fancy as wireless, but it's reliable and easy to understand. Plus, seeing both LEDs light up when you press one button never gets old!

Pro tip: Always check your wiring twice before blaming the code. We learned this the hard way!

Instructor

Contacts

  • Map
  • +250 781 187 555