Skip to content

11. Networking and Communications: Angel, Zaina, Elle

Group Assignment

Send a message between two projects.

Overview - Angel

In this week group assignment, we connected my touch sensor to Elle’s servo. We connected servo with XIAO esp32-c3 and connected touch sensor to XIAO rp2040. We used GPIO communication method to make XIAO esp32-c3 and XIAO rp240 communicate with each other. So when we touch the touch sensor, the servo will move. Then we created a new PCB for this week group assignment.

Wiring - Elle

Touch Sensor Individual

For just the touch sensor it is a very basic circut with an LED that lights up when the sensor is pressed. The touch sensor is connected to the GPIO 26. And we are using 5v.

Servo Individual

The other side of the breadbord is the servo. The servo side is also very simple. The important thing with the servo is that it’s plugged in to a 3V. The GPIO that we are using here is 9.

Wiring Together

To wire the two together we decided to do direct through a wire. We siply just connected one wire to GPIO 2 on the RP2040 and the GPIO 2 on the ESP32-C3 together. The other thing that we made sure todo is connect the GNDs together because that is how the two board communicate with each other.

Coding

For the code, we first uploaded code to the RP 2040 and then we uploaded code to the ESP32-C3.

Here’s the code for XIAO ESP32-C3 Servo:

#include <ESP32Servo.h>

Servo servo1;

int servoPin = 9;      // GPIO pin for servo on XIAO ESP32-C3

int inputPin = 2;       // GPIO pin to receive signal from RP2040

int currentPosition = 30; // Track current servo position

bool directionUp = true;  // Direction of servo movement



void setup() {

  // Initialize GPIO

  pinMode(inputPin, INPUT);



  // Initialize serial for debugging

  Serial.begin(115200);



  // Initialize servo

  servo1.setPeriodHertz(50);          // Standard 50 Hz for servos

  servo1.attach(servoPin, 500, 2400); // Min and max pulse width in microseconds



  // Move servo to starting position

  servo1.write(currentPosition);



  Serial.println("ESP32-C3 Servo Controller Ready!");

}



void loop() {

  // Check for input signal from RP2040

  int signalValue = digitalRead(inputPin);



  if (signalValue == HIGH) {

    // Touch detected - move servo

    Serial.println("Signal received - Moving servo");



    // Move the servo

    if (directionUp) {

      currentPosition++;

      if (currentPosition >= 150) {

        directionUp = false;

      }

    } else {

      currentPosition--;

      if (currentPosition <= 30) {

        directionUp = true;

      }

    }



    servo1.write(currentPosition);

    delay(22); // Control speed of movement

  } else {

    // No touch detected - servo stays in current position

    delay(50); // Small delay when no movement needed

  }

}

Here’s the code for XIAO RP2040 Touch Snesor:

// RP2040 Touch Sensor Code with GPIO Communication



#define TOUCH_PIN 26   // Touch sensor input pin

#define LED_PIN 4      // LED output pin

#define OUTPUT_PIN 2   // GPIO pin to send signal to ESP32-C3



void setup() {

  pinMode(TOUCH_PIN, INPUT);  // Touch Sensor

  pinMode(LED_PIN, OUTPUT);   // LED

  pinMode(OUTPUT_PIN, OUTPUT); // Output to ESP32-C3



  // Initialize with signal off

  digitalWrite(OUTPUT_PIN, LOW);



  Serial.begin(115200);  // For debug messages

  Serial.println("RP2040 Touch Sensor Ready!");

}



void loop() {

  int touch = digitalRead(TOUCH_PIN); // Read touch sensor state



  if (touch == HIGH) {

    Serial.println("TOUCH DETECTED!");

    digitalWrite(LED_PIN, HIGH);     // Turn LED ON



    // Send HIGH signal to ESP32-C3

    digitalWrite(OUTPUT_PIN, HIGH);

  } else {

    Serial.println("NO TOUCH DETECTED");

    digitalWrite(LED_PIN, LOW);      // Turn LED OFF



    // Send LOW signal to ESP32-C3

    digitalWrite(OUTPUT_PIN, LOW);

  }



  delay(100); // Short delay for stability

}

PCB - Zaina

Once we tested that everything was working correctly on the breadboard, we moved on to designing and milling the circuit onto a PCB. This helped us create a more compact and durable version of the circuit, with cleaner connections compared to the breadboard.

Here is the 3D view of our board.

Here is the schematic view:

Here’s the PCB view of our board.

Here’s the image of the milled out PCB board.

Next, we soldered headers onto each part of the board to allow the components to be easily removed and reused. This made the setup more flexible. This is especially useful for testing and future projects, since we didn’t have to permanently solder any of the components in place.

Here’s an image of the PCB with everything on.

Here is the video of the PCB working:

AI Usage

You can find the whole conversation here.

File Download

You can find all the files here.


Last update: June 2, 2025