Andrew's Fab Academy Journey

Embedded Networking and Communications Assignment

Embedded Networking and Communications

Introduction

This project focuses on embedded networking and communications, involving both group and individual assignments. The group assignment demonstrates wired communication between two Seeed Studio XIAO-RP2040 development boards on a breadboard, using UART to send a signal from Node 1 (sender) to Node 2 (receiver) to control an LED and an SG90 servo motor. The individual assignment involves designing and building the receiver node using the Seeed Studio XIAO-RP2040 microcontroller, with an SG90 servo motor and an LED as outputs, controlled via the wired network (UART), and programmed using the Arduino IDE. The node was designed in KiCAD and assembled on a custom PCB.

EDA Tool Used: KiCAD
Microcontroller Chosen (Individual Assignment): Seeed Studio XIAO-RP2040

XIAO RP2040

1. Group Assignment: Send a Message Between Two Projects

Objective: Set up two XIAO-RP2040 development boards on a breadboard to communicate via a wired network (UART) and send a signal from Node 1 (sender) to Node 2 (receiver) to control an LED and an SG90 servo motor.

Message Transmission Demonstration

  • Setup: Assembled two XIAO-RP2040 boards on a breadboard, connected via UART (wired communication). Node 1 acts as the sender, and Node 2 as the receiver. LED
    • Wiring: Node 1 TX (D6) to Node 2 RX (D7), Node 1 RX (D7) to Node 2 TX (D6), common GND between both boards.
    • Node 2 has an LED on D10 with a 220Ω resistor to GND, and an SG90 servo motor on D9 (signal), with VCC to the soldered 5V pin on Node 2’s XIAO-RP2040.
  • Code Snippet (Sender - Node 1):
    void setup() {
        Serial1.begin(9600); // UART communication on D6 (TX) and D7 (RX)
        Serial.begin(115200); // For debugging on Serial Monitor
    }
    
    void loop() {
        // Send command to turn on LED
        Serial1.println("LED_ON");
        Serial.println("Sent: LED_ON");
        delay(2000);
    
        // Send command to move servo to 90 degrees
        Serial1.println("SERVO_90");
        Serial.println("Sent: SERVO_90");
        delay(2000);
    
        // Send command to turn off LED
        Serial1.println("LED_OFF");
        Serial.println("Sent: LED_OFF");
        delay(2000);
    
        // Send command to move servo to 0 degrees
        Serial1.println("SERVO_0");
        Serial.println("Sent: SERVO_0");
        delay(2000);
    }
                            
  • Code Snippet (Receiver - Node 2):
    #include 
    
    Servo myservo;
    const int ledPin = 10; // D10 (GPIO 10) for LED
    String message = "";
    
    void setup() {
        Serial1.begin(9600); // UART communication on D6 (TX) and D7 (RX)
        Serial.begin(115200); // For debugging on Serial Monitor
        myservo.attach(9); // D9 (GPIO 9) for servo
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, LOW);
        myservo.write(0); // Start at 0 degrees
    }
    
    void loop() {
        while (Serial1.available()) {
            char incomingChar = Serial1.read();
            if (incomingChar == '\n') {
                if (message == "LED_ON") {
                    digitalWrite(ledPin, HIGH);
                    Serial.println("LED turned ON");
                } else if (message == "LED_OFF") {
                    digitalWrite(ledPin, LOW);
                    Serial.println("LED turned OFF");
                } else if (message == "SERVO_90") {
                    myservo.write(90);
                    Serial.println("Servo moved to 90 degrees");
                } else if (message == "SERVO_0") {
                    myservo.write(0);
                    Serial.println("Servo moved to 0 degrees");
                }
                message = "";
            } else {
                message += incomingChar;
            }
        }
    }
                            
  • Result: The Serial Monitor on Node 2 displayed messages confirming the received commands (e.g., "LED turned ON", "Servo moved to 90 degrees"). The LED on Node 2 turned on and off as commanded, and the servo moved between 0 and 90 degrees.

Group Work Page Documentation

Documented the breadboard setup, wiring, code, and results on the group page.
Link to Group Work Page

Individual Reflection

Learned about wired communication using UART between XIAO-RP2040 boards. Collaboration was effective, but we faced issues with cross-talk between the UART lines, which were resolved by ensuring a solid common ground and reducing the baud rate to 9600.

2. Individual Assignment: Design, Build, and Connect Node(s)

Objective: Design and build the receiver node using the Seeed Studio XIAO-RP2040 microcontroller, with an SG90 servo motor and an LED as outputs, controlled via a wired network (UART) from a sender node, programmed using the Arduino IDE.

Node Design and Build

  • Designed the receiver node using the XIAO-RP2040 with an SG90 servo motor and an LED as outputs. The schematic and PCB layout were created in KiCAD.
  • Schematic of the Node: li>
  • Assembled the node on a custom PCB, with a pin soldered to the XIAO-RP2040’s 5V pin for the servo’s power.
  • Components Used:
    • SG90 Servo Motor: To control a mechanical output.
    • SG90 Servo
    • LED: To provide visual feedback.
  • Fabrication Check:
    • Design Rule Check (DRC): Ran DRC in KiCAD; found 3 spacing violations between traces near the I2C header (J2).
    • Adjustments: Increased the spacing between traces and rerouted the I2C lines to resolve violations.
    • Gerber Files: Gerber Files
    • Screenshot: Below is the PCB layout confirming fabrication readiness.
    • PCB Layout

Network/Bus Configuration

  • Configured the XIAO-RP2040 as the receiver node in a wired network using UART communication.
  • Connected the receiver node (Node 2) to the sender node (Node 1) via UART: Node 1 TX (D6) to Node 2 RX (D7), Node 1 RX (D7) to Node 2 TX (D6), common GND between both boards.
  • The sender node sends commands (e.g., "LED_ON", "SERVO_90") to the receiver node to control the LED and servo motor.

Local Input/Output Integration

  • Integrated UART input from the sender node (Node 1) via the wired network, receiving commands to control the LED and servo.
  • Integrated an SG90 servo motor to move to the specified angle (e.g., 0 or 90 degrees), connected to D9 (GPIO 9) on the J5 header for the signal, with VCC to the soldered 5V pin on the XIAO-RP2040.
  • Integrated an LED to turn on or off, connected to D10 (GPIO 10) on the J5 header with a 220Ω resistor to GND.

Code Snippet

The code below configures the XIAO-RP2040 as the receiver node to control the servo and LED based on UART commands from the sender node.

#include 

Servo myservo;
const int ledPin = 10; // D10 (GPIO 10) for LED
String message = "";

void setup() {
    Serial1.begin(9600); // UART communication on D6 (TX) and D7 (RX)
    Serial.begin(115200); // For debugging on Serial Monitor
    myservo.attach(9); // D9 (GPIO 9) for servo
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);
    myservo.write(0); // Start at 0 degrees
    Serial.println("Receiver node initialized");
}

void loop() {
    while (Serial1.available()) {
        char incomingChar = Serial1.read();
        if (incomingChar == '\n') {
            if (message == "LED_ON") {
                digitalWrite(ledPin, HIGH);
                Serial.println("LED turned ON");
            } else if (message == "LED_OFF") {
                digitalWrite(ledPin, LOW);
                Serial.println("LED turned OFF");
            } else if (message == "SERVO_90") {
                myservo.write(90);
                Serial.println("Servo moved to 90 degrees");
            } else if (message == "SERVO_0") {
                myservo.write(0);
                Serial.println("Servo moved to 0 degrees");
            } else {
                Serial.println("Unknown command: " + message);
            }
            message = "";
        } else {
            message += incomingChar;
        }
    }
}
                

Node Code File: Node Code

Result

The XIAO-RP2040 receiver node successfully received commands via the wired network (UART) from the sender node. The LED turned on and off as commanded (e.g., "LED_ON" turned it on, "LED_OFF" turned it off). The SG90 servo motor moved to the specified angles (e.g., "SERVO_90" moved it to 90 degrees, "SERVO_0" moved it to 0 degrees). The Serial Monitor on the receiver node displayed messages confirming the actions (e.g., "LED turned ON", "Servo moved to 90 degrees").

Documentation

  • Challenges: Initially attempted to use a water flow sensor and LCD, but both failed (reported on April 10, 2025). Switched to using an SG90 servo motor and an LED for the individual assignment. Powered the servo at 3.3V initially, which resulted in reduced torque; soldered a pin to the XIAO-RP2040’s 5V pin, improving performance. Faced issues with UART communication due to noise on the breadboard; resolved by ensuring a solid common ground and using a lower baud rate (9600).
  • Hero Shot:
    • Hero Shot of Development Board
    • Description: This image shows the fabricated receiver node with the XIAO-RP2040 microcontroller (center), the SG90 servo motor connected to the soldered 5V pin, an LED on D10, and pin headers (J5) for UART connections to the sender node.
  • Link to Group Assignment Page: The group assignment demonstrated wired communication using UART, which informed the individual assignment’s approach. Link to Group Work Page

Conclusion

This project provided valuable experience in embedded networking and communications. The group assignment demonstrated wired communication between two XIAO-RP2040 boards using UART, successfully controlling an LED and servo motor. The individual assignment built on this by designing and building the receiver node, which integrated the SG90 servo motor and an LED as outputs, controlled via the wired network. Key takeaways include implementing UART communication, controlling multiple outputs, and troubleshooting wired connections on a breadboard. Future improvements could involve adding more complex commands or integrating additional sensors for input.