Skip to content

11. Networking and communications

For this week’s group assignment, we had to send a message between two projects.

Since we already made some boards during the previous weeks, we decided to try to establish an I2C communication between Mkhitar’s ATTINY3216 and Zhirayr’s Xiao RP2040 boards.

Setup

In order to have a reliable communication bwetween two microcontrollers, we have to connect our boards with 3 wires:

  • Grounds
  • SCL pins (clock)
  • SDA pins (data)

Furthemore, SDA and SCL need to be pulled up. Since we didn’t think that we would use I2C communication before making our boards, we didn’t integrate pull up resistors in our boards. So we used a breadboard to pull up both lines to 3.3V.

Primary Code

We used the ATTINY3216 as Primary and it will also be the one sending the messages:

#include <Wire.h>

void setup() {
  Wire.begin();  // Initialize I2C as master
  Serial.begin(9600);  // Initialize Serial Monitor
}

void loop() {
  if (Serial.available()) {
    String message = Serial.readStringUntil('\n');  // Read from Serial Monitor
    Wire.beginTransmission(0x08);  // I2C address of ESP32-S3
    Wire.write(message.c_str());  // Send the string over I2C
    Wire.endTransmission();
    Serial.println("Message sent: " + message);  // Log the message
  }
  delay(100);  // Prevent spamming
}

In our case, the address of the Secondary is 8 (in decimal) or 0x08 (in hexadecimal). This code sends the input from the Serial to the Secondary.

Secondary code

Result


Last update: April 9, 2025