Fab Academy 2026

Week 11: Networking and Communications

Exploring communication protocols and integrating biometric sensors using I2C communication.

Main Protocol

I2C communication

Main Hardware

ESP32-C6 and MAX30102

Main Goal

Establish communication between embedded devices and sensors.

Assignments

Group Assignment

Individual Assignment

Group Assignment

Group Assignment – Networking and Communications

During the group assignment we explored different communication protocols commonly used in embedded systems and IoT projects.

We analyzed how each protocol works, its advantages, limitations and possible applications depending on the project requirements.

Understanding these protocols helped me decide which communication method was the most suitable for my wearable biometric project.

Communication Protocols

Different communication protocols offer different advantages depending on speed, distance, power consumption and system complexity.

During this week I researched and tested several common protocols used in embedded systems and IoT applications.

Different standard communication protocols

MonoFab PCB

Wiring

Connect the two boards like this:

  • Controller (SDA) to Target (SDA)
  • Controller (SCL) to Target (SCL)
  • Controller GND to Target GND
  • 4.7 kOhm pull-up from SDA to 3.3 V
  • 4.7 kOhm pull-up from SCL to 3.3 V

Main code steps

Controller

  • Include Wire.h.
  • Start I2C with Wire.begin(SDA_PIN, SCL_PIN, frequency).
  • Send data using Wire.beginTransmission(address) and Wire.write(...).
  • Finish transmission with Wire.endTransmission().
  • Request data from the Target using Wire.requestFrom(...).
  • Read the response using Wire.read().

Target

  • Include Wire.h.
  • Create a receive callback using Wire.onReceive(...).
  • Create a request callback using Wire.onRequest(...).
  • Start slave mode with Wire.begin(address, SDA_PIN, SCL_PIN, frequency).
  • Store received data in a variable.
  • Return data when the Controller requests it.

When to Use I2C

I2C is recommended in situations where you need to connect multiple low-speed devices using only two wires (SDA and SCL). It is especially useful in embedded systems where pin availability is limited.

  • When connecting multiple sensors or modules to a single microcontroller.
  • When you need a simple communication bus between a controller and several target devices.
  • When wiring simplicity is important, since I2C only uses two communication lines.
  • For short-distance communication on the same PCB or within the same device enclosure.
  • When devices support addressing, allowing many components to share the same bus.

I2C is not ideal for high-speed or long-distance communication. In those cases, protocols like SPI or UART may be more suitable.

Workflow Overview

1. PCB Design

Design one board in KiCad with a button, an LED and a XIAO ESP32-C3.

2. Two Boards

Make the same PCB twice, one for each side of the conversation.

3. MAC Addresses

Read the MAC address of each ESP32-C3.

4. Morse Code

Send letters from one board to the other using ESP-NOW.

5. Testing

Check that both boards can send and receive.

PCB Design

First, I designed a PCB in KiCad. It has two 330 ohm resistors, a button, an LED and a XIAO ESP32-C3.

Since the goal this week was to make two projects talk to each other, I made the same board two times. Each board has its own microcontroller, so each one works as an independent node.

Input

A button to write the Morse code.

Output

An LED to show the message.

Resistors

Two 330 ohm resistors.

The 2 boards ready to use.

Getting the MAC Addresses

Before using the main code, I needed the MAC address of each ESP32-C3. ESP-NOW uses it to know exactly which board should receive the message.

So I uploaded this short sketch to each board and read the address in the Serial Monitor.


#include <WiFi.h>

void setup() {
  Serial.begin(115200);
  delay(2000);                 
  WiFi.mode(WIFI_STA);         
  Serial.print("MAC: ");
  Serial.println(WiFi.macAddress());
}

void loop() {}

Morse Code with ESP-NOW

The two boards communicate using ESP-NOW. Each board detects when I press the button.

Short Press

A quick press is a dot.

Long Press

Holding the button is a dash.

Pause

If I stop pressing for a while, the letter is complete.

When that pause happens, the ESP32-C3 understands the letter and sends it to the other board. The other board receives the letter directly.

This is the final code I used on both boards:



#include <WiFi.h>
#include <esp_now.h>
#include <esp_wifi.h>

const int BUTTON_PIN = D0;   

uint8_t MAC_A[] = {0xAC, 0x27, 0x6E, 0x7E, 0xCC, 0x24};
uint8_t MAC_B[] = {0xAC, 0x27, 0x6E, 0x80, 0xFD, 0x10};

const uint8_t WIFI_CHANNEL = 1;

const unsigned long DEBOUNCE_MS   = 40;
const unsigned long DASH_MIN_MS   = 250;   // it waits 250 ms or more to consider the press a dash
const unsigned long LETTER_GAP_MS = 800;   // if I stop pressing for this long, the letter is done
const int MAX_SYMBOLS = 7;

uint8_t peerAddress[6];

struct MorseEntry {
  const char *code;
  char letter;
};

const MorseEntry table[] = {
  {".-", 'A'},   {"-...", 'B'}, {"-.-.", 'C'}, {"-..", 'D'},  {".", 'E'},
  {"..-.", 'F'}, {"--.", 'G'},  {"....", 'H'}, {"..", 'I'},   {".---", 'J'},
  {"-.-", 'K'},  {".-..", 'L'}, {"--", 'M'},   {"-.", 'N'},   {"---", 'O'},
  {".--.", 'P'}, {"--.-", 'Q'}, {".-.", 'R'},  {"...", 'S'},  {"-", 'T'},
  {"..-", 'U'},  {"...-", 'V'}, {".--", 'W'},  {"-..-", 'X'}, {"-.--", 'Y'},
  {"--..", 'Z'},
  {"-----", '0'}, {".----", '1'}, {"..---", '2'}, {"...--", '3'}, {"....-", '4'},
  {".....", '5'}, {"-....", '6'}, {"--...", '7'}, {"---..", '8'}, {"----.", '9'}
};

char decodeMorse(const char *code) {
  for (const auto &e : table) {
    if (strcmp(code, e.code) == 0) return e.letter;
  }
  return '?';
}

char symbols[MAX_SYMBOLS + 1] = "";
int  symCount = 0;

bool lastState = HIGH;       // HIGH means the button is not pressed
unsigned long lastChange = 0;
unsigned long pressStart = 0;
unsigned long lastRelease = 0;

#if ESP_ARDUINO_VERSION_MAJOR >= 3
void onDataRecv(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
  const uint8_t *src = info->src_addr;
#else
void onDataRecv(const uint8_t *src, const uint8_t *data, int len) {
#endif
  if (memcmp(src, peerAddress, 6) != 0) return;   // ignore anything that is not from its brother

  char code[16];
  int n = min(len, 15);
  memcpy(code, data, n);
  code[n] = '\0';

  Serial.print(decodeMorse(code));
}

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  esp_wifi_set_channel(WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE);

  // Check which board this is, so I know who to send to
  uint8_t myMac[6];
  WiFi.macAddress(myMac);

  if (memcmp(myMac, MAC_A, 6) == 0) {
    memcpy(peerAddress, MAC_B, 6);
  } else if (memcmp(myMac, MAC_B, 6) == 0) {
    memcpy(peerAddress, MAC_A, 6);
  } else {
    while (true) delay(1000);   // if the MAC address is unknown the code stops here
  }

  if (esp_now_init() != ESP_OK) while (true) delay(1000);

  esp_now_register_recv_cb(onDataRecv);

  esp_now_peer_info_t peerInfo = {};
  memcpy(peerInfo.peer_addr, peerAddress, 6);
  peerInfo.channel = WIFI_CHANNEL;
  peerInfo.ifidx   = WIFI_IF_STA;
  peerInfo.encrypt = false;
  if (esp_now_add_peer(&peerInfo) != ESP_OK) while (true) delay(1000);
}

void loop() {
  bool state = digitalRead(BUTTON_PIN);

  if (state != lastState && millis() - lastChange > DEBOUNCE_MS) {
    lastChange = millis();
    lastState = state;

    if (state == LOW) {                 // button pressed
      pressStart = millis();
    } else {                            // button released
      char s = (millis() - pressStart >= DASH_MIN_MS) ? '-' : '.';
      if (symCount < MAX_SYMBOLS) {
        symbols[symCount++] = s;
        symbols[symCount] = '\0';
      }
      lastRelease = millis();
    }
  }

  // After a long pause the letter is finished, so I send it
  if (symCount > 0 && lastState == HIGH && millis() - lastRelease > LETTER_GAP_MS) {
    esp_now_send(peerAddress, (const uint8_t *)symbols, symCount + 1);
    symCount = 0;
    symbols[0] = '\0';
  }
}

Testing the Boards

After uploading the code, I tested both PCBs and confirmed that both of them work.

In this video you can see the two boards communicating with each other at the same time.

Downloadable Files