Skip to content

15b. Networking (CLS Adults)

14.5 Group Project- Networking and Communications

This week, our group assignment is to send a message between two projects.

We were interested in testing out the “bus” that Barbara had made with others in the group. Since there was a spot for an additional node on the end of it, we decided to use this bus and try to add one of Nidhie Dhiman’s ATTiny 412 PCB’s. We used an Arduino with the Parent, Child 1, Child 2, and Child 3 merely as a power source. To prove that the Parent board was controlling the others, we uploaded a basic blink code onto the Arduino that was demonstratiing the blinling with the builtin LED.

We uploaded the following code onto her board with no problems.

// Wire Peripheral Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI peripheral device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(6);                // join i2c bus with address #6
  Wire.onRequest(requestEvent); // register event
  Serial.begin(57600);
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hey"); // respond with message of 6 bytes
  // as expected by master
}

The following code is the Parent code we used with our three “children”/nodes:

// Wire Controller Reader
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Reads data from an I2C/TWI peripheral device
// Refer to the "Wire Peripheral Sender" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  PORTB_PIN0CTRL |= PORT_PULLUPEN_bm; 
  PORTB_PIN1CTRL |= PORT_PULLUPEN_bm;

  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(57600);  // start serial for output
}

void loop() {

  Wire.requestFrom(4, 2);    // request 2 bytes from peripheral device #4

  while (Wire.available()) { // peripheral may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);

   Wire.requestFrom(8, 6);    // request 6 bytes from peripheral device #8

  while (Wire.available()) { // peripheral may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);

   Wire.requestFrom(6, 3);    // request 3 bytes from peripheral device #6

  while (Wire.available()) { // peripheral may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

The following code shows what Barbara had uploaded onto her “Child 1”.

// Wire Peripheral Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI peripheral device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
  Serial.begin(57600);
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello"); // respond with message of 6 bytes
  // as expected by master
}

And this is the code that Barbara already had uploaded onto her Child 2 PCB.

// Wire Peripheral Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI peripheral device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(4);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
  Serial.begin(57600);
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hi"); // respond with message of 6 bytes
  // as expected by master
}

We should have seen the following message in the serial monitor: hihellohey. However, we were unable to get Nidhie’s ATTiny412 to send the “hey” message back to the parent.

We knew that classmate, Aaron Logan used an ATtiny1614 PCB for his Networking project, and we asked him to join our group this week and try out his boad where Nidhie’s board was. We had success with Aaron’s board! It was incredibly rewarding to see the bus work and to see my Parent, Child 1 and Child 2 all interacting!

When the message– hihellohey– appeared in the serial monitor, there was a backwards question mark. Nidhie realized later that this backwards question mark was because the Child 1 code (that contatined the response of “hello”) states that it will receive 6 bits. But the word “hello” only contains five bits. So a backwards question mark is where the sixth bit would be if there was one.

We then decided to try out Charlie’s Horvath’s board in the last position on the bus. Charlie used an ATTiny1614 for his work, and we were all getting very well-versed in how to connect and program all of the PCB’s. Charlie’s ATTiny1614 also worked perfectly.


Last update: May 24, 2022