Two ATTINY85s Together With I2C

Hello, I am working on a project where I want to use two ATTINY85's as the brains of it. I plan to do this with I2C connection. I am using Arduino to upload the code. For some reason it's not working and I can't figure out why. I've look around google and I can't seem to find anything clear on how to do it. Below I will have the ATTINY85 master device code, the ATTINY85 slave code, and my wiring diagram. The right ATTINY85 is the slave device and the left is the master. Thank you for your help?

#include <TinyWireS.h>

// Slave ATTINY85
char x;

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

void loop() {
  // put your main code here, to run repeatedly:
}

void checking() {
  while (TinyWireS.available() > 0) {
    x = TinyWireS.receive(); // Use receive() to get the received byte

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

#include <TinyWireM.h>
//ATTIN85 Master Code
void setup() {
  TinyWireM.begin();

}

void loop() {
  TinyWireM.beginTransmission(8);
  TinyWireM.send(atoi("1"));
  TinyWireM.endTransmission(8);
  delay(5000);
  TinyWireM.beginTransmission(8);
  TinyWireM.send(atoi("0")); 
  TinyWireM.endTransmission(8);
  delay(5000);

}

Sorry your wiring picture does not do it for me, lots of details are missing.

What can I add to make this more understandable?

You don't say what core you're compiling with, your wiring diagram has no power source, neither of your ATtiny's have either their Vcc or GND pins hooked up, it appears you want to use PB1 (pin 6) as an output but you have nothing hooked up to it, you have no connections on SDA (pin 5) or SCL (pin 7). And at that point I simply stopped looking.

1 Like

Why not simply draw an annotated schematic inplace of a poor wiring diagram.

I apologize for the lack of information. I'll try and fix every thing in this message.

1: I accidentally had my schematic backwards, so here is an updated one.

2: I'm using Arduino to power the device, and Arduino as ISP to upload the code.

3: I'm using ATTINY Core.

If I'm missing anything else please let me know.
Thank you

You have no ground connection. only the two AT85 GND are connected to eachother.

The pullups are usually 4.7K. I have never used 1K

You should not connect a led without a series resistor.

And now your reset pins are floating. Did you disable them with a high voltage programmer or did you forget about them? How are the fuses in the ATtiny85s set? Are you using the internal oscillator? At what frequency?

I would be surprised if that's the issue. They have internal pullups.

I never use external reset pullups, unless there is a lot of EMF and long PCB traces on the reset pins.

This code in the master sends a numeric value of 1. NOT an ASCII character 1, which has a numeric value of 49 in base 10.

This code in the slave looks for an ASCII character 1, which has a numeric value of 49 in base 10. Which it will never, ever receive.

I forgot to change to diagram to 4.7, but I am using 4.7k resistors. I'll add a resistor to the led, and I'll ground the chips.

I'm gonna change that right now. I didn't realize they were in that format.

I've updated the code and the wiring, and nothing has changed. Here is the new wiring diagram.


Thanks for the help.

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

That is what a schematic looks like. Much easier to follow then the frizzy wire plot. The code will work very will with that design.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.