Networking and Communications#

Group Assignment#

For our group assignment, we interfaces our two ATTiny 3216 boards, and passed messages via I2C. If the temperature is over 24.0 ºC, the main boards send a signal of 1 to the secondary, if the temperature is below 24.0 ºC, a signal of 0 is being send.

The secondary board interprets these signals to turn an LED ON of OFF.

The main board also used an OLED on the same I2C bus do display the temperature from the I2C temperature sensorl

Main Board#

  • ATTiny 3216
  • I2C OLED on 0x3C
  • I2C Temperature Sensor on 0x48
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_ADT7410.h"

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// temp sensor address
#define TEMP_ADDRESS 0x48

// Create the ADT7410 temperature sensor object
Adafruit_ADT7410 tempsensor = Adafruit_ADT7410();

// secondary address
#define SECONDARY_ADDRESS 0x09

void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // setup temp sensor
  if (!tempsensor.begin(TEMP_ADDRESS)) {
    Serial.println("Couldn't find ADT7410!");
    while (1);
  }

  Wire.begin();
}

void loop() {
  // sending signal to secondary board
  if (tempsensor.readTempC() > 24.0) {
    Wire.beginTransmission(SECONDARY_ADDRESS);
    Wire.write(1);
    Wire.endTransmission();
  } else {
    Wire.beginTransmission(SECONDARY_ADDRESS);
    Wire.write(0);
    Wire.endTransmission();
  }

  // display
  display.clearDisplay();
  display.setTextSize(3);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.println("Temp:");
  display.print(tempsensor.readTempC());
  display.display();

  // update every 2 seconds
  delay(2000);
}

Secondary Board(with LED)#

Define microchip ID as 9, it shows on I2C scan by main board as 0x09.

img

  • ATTiny 3216
  • Chip LED
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <Wire.h>

int LEDA = 0; // PA4
int receivedValue = 1;

void setup() {
  pinMode(LEDA, OUTPUT);
  Serial.begin(9600);
  Wire.begin(9); // secondary ID #9
  Wire.onReceive(dataReceive);
}

void loop() {
  Serial.println(receivedValue);
}

void dataReceive(int num) {
  if (Wire.available()) {
    receivedValue = Wire.read();
    if (receivedValue == 1) {
      digitalWrite(LEDA, HIGH);
    } else if (receivedValue == 0) {
      digitalWrite(LEDA, LOW);
    }
  }
}