Week 11 Networking and Communications
This week, I had to make two microcontrollers communicate wirelessly. I chose the Xiao ESP32C3 because these microcontroller are very easy to network.
Board
I wanted to create a new board this week, housing two different circuits that are not connected physically. I wanted one board to have an input, and the other to have an output. For the input device, I chose a pushbutton, and for the output, I chose an LED.
Board Design

I created this simple board in Kicad. As you can see, the two microcontrollers and their input/output device are not connected to the other microcontroller.
Gerber and Drill Files
Click Here to download the Edge Cut Gerbers
Click Here to download the Front Copper Gerbers
Click Here to download the Drill Holes
Milling
I used the Carvera Milling Machine, the same machine I have used to mill all my other boards. For the front copper traces, I used a 0.3mm bit. For the Edge Cuts and Drill Holes, I used a 0.8mm Corn Bit.

As you can see, some of the traces are cut very well, and the others are not. On the first milling job, I set the traces depth to 0.1mm. Some of the traces didn't cut all the way through. After that, I made a toolpath that only milled the important traces to save time. This time, I set the trace depth to 0.2mm. As you can see, it worked well.
Soldering and Populating

This is the board after soldering and populating. Overall, my soldering wasn't to bad. For the header pins connecting the ESP32s to the board, I only soldered the necessary connection points and some other points for stability. I did this because not all the pads milled out properly like I mentioned before and it is hard to solder without pads.
Board Setup and Coding
Because I was new to this process, I used ChatGPT to help me. First, it told me I needed to find the MAC address of the reciever board (The board with the LED attached to it). To do this, I plugged in the ESP32 into my computer and uploaded this code to it in Arduino IDE.
Click Here to download ChatGPT's response
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.println(WiFi.macAddress());
}
void loop() {}
After uploading, the board responded with it's MAC Address in the Serial Monitor.

This is what it looked like.
Now that I had to MAC Address, ChatGPT told me to upload this code to the Sender ESP32.
#include <WiFi.h>
#include <esp_now.h>
#define BUTTON_PIN 4
uint8_t receiverMAC[] = {0xE4, 0xB3, 0x23, 0xC5, 0x91, 0x5C};
typedef struct {
bool buttonState;
} Message;
Message msg;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
return;
}
esp_now_peer_info_t peerInfo = {};
memcpy(peerInfo.peer_addr, receiverMAC, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
esp_now_add_peer(&peerInfo);
}
void loop() {
msg.buttonState = (digitalRead(BUTTON_PIN) == LOW);
esp_now_send(receiverMAC, (uint8_t *)&msg, sizeof(msg));
delay(100);
}
As you can see, the code contains the MAC address of the reciever ESP32.
I also had to code the reciever board. ChatGPT told me to use this code.
#include <WiFi.h>
#include <esp_now.h>
#define LED_PIN 2
typedef struct {
bool buttonState;
} Message;
Message msg;
void onReceive(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&msg, incomingData, sizeof(msg));
digitalWrite(LED_PIN, msg.buttonState ? HIGH : LOW);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
return;
}
esp_now_register_recv_cb(onReceive);
}
void loop() {}
Reciever Code Description:
The receiver Seeed Studio XIAO ESP32C3 listens for incoming ESP-NOW messages and turns an LED on GPIO2 on or off depending on whether it receives a “pressed” or “not pressed” signal from the sender.
Sender Code Description:
The sender Seeed Studio XIAO ESP32C3 reads a pushbutton on GPIO4 and continuously sends its state (pressed or not pressed) wirelessly using ESP-NOW to a specific receiver identified by its MAC address.
Testing
As you can see when I press the button, The LED lights up. The code works!
Reflection
I put this week off for a long time. Infact, I completed this week during week 14. I thought this week would be a very difficult week, since I was new to networking. However, I ended up completing the individual assignment in a single day.