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 a ceratin code was sent to his microcontroler over wifi. Heres a block diagram of what that looked like:
The second block diagram focuses on the communication protocol and data flow between the ESP32-S3 and ESP32-C3 microcontrollers. Communication is established via a Wi-Fi network using the TCP/IP protocol, with the ESP32-S3 operating as a TCP client and the ESP32-C3 functioning as a TCP server. This setup ensures reliable, ordered, and error-checked delivery of control messages, which is critical for precise servo operation. Each command sent from the ESP32-S3 contains essential information such as the target servo identifier, the desired servo angle, and synchronization data like timestamps or sequence numbers to maintain command integrity and order. Upon receipt, the ESP32-C3 parses these commands and translates them into physical servo movements through the ESP32Servo library. The system also incorporates acknowledgment mechanisms to confirm successful execution of commands, allowing for robust error handling and retransmission if necessary. Both devices maintain static IP addresses within the same subnet for efficient direct communication, and while security features like encryption are not currently implemented, they are potential future enhancements. This communication framework facilitates seamless coordination between input detection and actuator response, enabling a responsive and interactive system.
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. Heres a block diagram of what it looked like
This block diagram depicts the complete system architecture involving two ESP32 microcontrollers: the ESP32-S3 and the ESP32-C3. The ESP32-S3 serves as the primary controller responsible for reading touch sensor inputs connected to its GPIO pins. Upon detecting user interaction, the ESP32-S3 processes these signals and generates corresponding network commands. Both microcontrollers are connected to the same local Wi-Fi network and have static IP addresses assigned, which allows for stable and direct communication over TCP/IP protocols. The ESP32-C3 acts as the actuator unit, controlling multiple servo motors through its GPIO pins using the ESP32Servo library for precise movement. This modular separation of sensing and actuation ensures scalability, ease of debugging, and real-time responsiveness. Power supplies are managed separately for each device, while physical connections keep input peripherals (touch sensors) and output devices (servos) isolated on their respective microcontrollers. Overall, this architecture provides a robust framework for wireless communication and control between distributed components in the project.
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.