Networking and Communications

In this week’s assignment, we explored how micro-controllers can communicate with each other using wired serial communication protocols. This is essential for building distributed systems where nodes must share data or execute tasks collaboratively. The assignment was divided into a group and an individual.

Group Assignment: Individual Assignment: In this project I have made Two-Way UART Communication Between Two Seeed XIAO RP2040 Boards on UART network protocol where breadboard act as a switch.

Objective of the project

Establish a UART-based communication link between two Seeed XIAO RP2040 micro-controllers, where

Required Components

Wiring Diagram
Board Lesotho Pin Board Rwanda Pin
D6 (TX) D7 (RX)
D7 (RX) D6 (TX)
GND GND

TX of one board goes to RX of the other and vice versa. They must share the same Ground for UART to work.
Lesotho board is on COM11 and Rwanda on COM6.

Code Explanation

Each board runs nearly identical code, with the only difference being the sender name ("Lesotho" or "Rwanda").

Example Code for Rwanda Board

// Declare a string variable to store user input from the Serial Monitor
String inputMessage = "";

void setup() {
  // Initialize the USB Serial interface for communication with the Serial Monitor
  Serial.begin(9600);

  // Wait for the Serial Monitor to be opened before proceeding
  while (!Serial);

  // Initialize Serial1 (UART) for communication between RP2040 boards
  // On Seeed XIAO RP2040, Serial1 uses
  // TX = D6 (physical pin 6), RX = D7 (physical pin 7)
  Serial1.begin(9600);

  // Notify the user that this board is ready to send messages
  Serial.println("Rwanda ready.");
}

void loop() {
  // Check if there is input available from the Serial Monitor (USB serial)
  if (Serial.available()) {
    // Read the entire input line (until newline character)
    inputMessage = Serial.readStringUntil('\n');

    // Send a formatted message over UART (Serial1) to the other board
    Serial1.print("Rwanda says: ");
    Serial1.println(inputMessage);

    // Print the same message locally on this board’s Serial Monitor
    Serial.print("Sent: ");
    Serial.println(inputMessage);
  }

  // Check if a message has been received from the other board over UART (Serial1)
  if (Serial1.available()) {
    // Read the full received message (until newline character)
    String msg = Serial1.readStringUntil('\n');

    // Display the received message in this board’s Serial Monitor
    Serial.println(msg);
  }
}

  

For Board Lesotho

Used the same code, but changed "Rwanda says: " to "Lesotho says: " wherever applicable.

Testing the Communication


Code file to test
Lesotho board
Rwanda board