Two ATTINY85s Together With I2C

I don't know why people make things so hard for themselves and anyone trying to help them.

There's a perfectly serviceable Wire library in ATTinyCore. With perfectly serviceable examples of how to write master and slave sketches. There's no need for 3rd party libraries.

And honestly, is it so hard to put together a legible schematic? You'd think they were being asked to reproduce the Mona Lisa. It's like 10 minutes work, tops.

This code, this wiring, works.

Master

#include <Wire.h>

//ATTINYV85 Master Code

void setup() {
   Wire.begin();
}

void loop() {
   Wire.beginTransmission(8);
   Wire.write('1');
   Wire.endTransmission();
   delay(5000);
   Wire.beginTransmission(8);
   Wire.write('0'); 
   Wire.endTransmission();
   delay(5000);
}

Slave

#include <Wire.h>

// Slave ATTINY85

char x;

void setup() {
   pinMode(1, OUTPUT); // Use pin 1 as an output
   Wire.begin(8);
   Wire.onReceive(checking);
}

void loop() {
   delay(100);
}

void checking(int howMany) {
   while( Wire.available() > 0 ) {
      x = Wire.read(); // Use read() to get the received byte

      if (x == '1') {
         digitalWrite(1, HIGH);
      } else if (x == '0') {
         digitalWrite(1, LOW);
      }
   }
}

Schematic

Wiring

1 Like