I want to make my Attiny85 and my Arduino UNO communicate together with I2C protocol. Since Attiny do not support Wire library, I use TinyWire by lucullusTheOnly and Wire on the Uno.
The Attiny is sending data as the master to the Uno, the slave.
Here is my code:
Master
#include <TinyWire.h>
byte slave_address = 10;
void setup() {
// config TinyWire library for I2C master functionality
TinyWire.begin();
}
void loop() {
TinyWire.beginTransmission(slave_address);
TinyWire.send('c');
// endTransmission sends the bytes in the buffer to the slave and returns 0 if there was no error
TinyWire.endTransmission();
delay(500);
}
Slave
#include <Wire.h>
void setup() {
Wire.begin(10); // join i2c bus with address #10
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
I connect the pin like this :
Arduino --> Attiny
SCL ---- PIN 7
SDA ---- PIN 5
I try to pull-up the clock and data line with 2.2k resistors but nothing happened, I receive nothing on the Uno from the Attiny. Any idea ? Thanks !