Skip to content

13. Networking: Kabir and Ryan

For networking, the group assignment was to send a message between two projects. For our group project, we used I2C to send a message from Ryan’s networking board to Kabir’s ATTiny412 board in order to toggle the LED on the board. We connected the +5V, ground, and SCL and SDA pins between the two boards:

Kabir’s code (node):

#include <Wire.h>

void setup() {
  Wire.onReceive(toggleLED);
  Wire.begin(0x08);
}

void loop() {
  delay(100);
}

int led = 0;

void receiveDataWire(int16_t numBytes) {      // the Wire API tells us how many bytes
  for (uint8_t i = 0; i < numBytes; i++) {    // were received so we can for loop for that
    char c = Wire.read();                     // amount and read the received data
  }
  // toggle LED
  led = led + 1;
  led %= 2;
  digitalWrite(PIN_PA7, led);
}

Ryan’s code (master):

#include <Wire.h>

#define SLAVE_ADDRESS 0x08

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

void loop() {
  Wire.beginTransmission(SLAVE_ADDRESS); // Start communication with slave
  Wire.write('A'); // Send a signal
  Wire.endTransmission(); // Stop communication
  Serial.println("Signal sent to slave");
  delay(1000); // Wait for a second before sending next signal
}

The video:

The video shows that the ATTiny board was synchronized with the messages being sent through the serial monitor also printing messages from Ryan’s board simultaneously with the I2C messages, showing that it received the messages.


Last update: June 20, 2024