11. Networking

Overview

This week I had my input week and output week microcontrollers talk to each other. To do this I had it be so that when the input device was high, it sent a signal to a digital pin on my output board which then started the walking sequence. For my group work I

Group Work

This week for group work, me and my partner Noah Smith combined our projects microcontorlers to send a signal from one to another using a input and output device to prove the action was taking place. To do this, we took my esp32s3 with its servo in it and ran a wire to his esp32c3 connected to a stepper motor. The goal was to have the servo respond when the acceleromotor dected motion.

Planing

For this week, I wanted to try and implement my plan for the interactive portion of my final project. This would include using one of the touch inputs on the esp32s3 to send a signal to a servo causing it to move. This was later going to be used as a tail moving mechanism in the dog.

Code

The ESP32-S3 Sender Code is designed to detect a touch event on GPIO pin 2. When the touch value exceeds a threshold of 100,000, the ESP32-S3 connects to the ESP32-C3 over Wi-Fi and sends a “START” signal. This signal tells the ESP32-C3 to begin moving a servo. The code continuously checks the touch input and sends the signal whenever the threshold is crossed.

Heres the code for the ESP32S3

#define TOUCH_PIN T3      // GPIO 15

#define SIGNAL_PIN 10     // GPIO 10 (output to C3)

#define THRESHOLD 100000  // Adjust based on your readings

void setup() {
  Serial.begin(115200);
  pinMode(SIGNAL_PIN, OUTPUT);
}

void loop() {
  uint32_t touchValue = touchRead(TOUCH_PIN);
  Serial.print("Touch Value: ");
Serial.println(touchValue);

digitalWrite(SIGNAL_PIN, touchValue > THRESHOLD ? HIGH : LOW);
delay(100);
}

And heres the code for the ESP32C3

#include <ESP32Servo.h>

#define SIGNAL_PIN 7  // GPIO 7 (input from S3)

#define SERVO_PIN 4   // Servo control pin

Servo myServo;
bool direction = true;
unsigned long lastMove = 0;

void setup() {
Serial.begin(115200);
pinMode(SIGNAL_PIN, INPUT);
myServo.attach(SERVO_PIN);
}

void loop() {
if (digitalRead(SIGNAL_PIN) == HIGH) {
  unsigned long now = millis();
if (now - lastMove > 500) {
  myServo.write(direction ? 0 : 180);
  Serial.println(direction ? "Servo → 0" : "Servo → 180");
  direction = !direction;
  lastMove = now;
    }
  }
}

Video

Breadboard Test

Final Result

Reflection

This week was a bit tricky since origanlly I tried to send it over wifi but I had some difficulties with connecting the microcontrollers. After I made it a wired connection though it became a lot easier and I was able to get the the servo to respond to the touch.