ATTiny85 and I2C

Hi Everyone,

I have asked this question in the wrong section and got no interesting answers....Therefore, I'm asking a different (still similar) question:

Could someone provide me a sketch, that would involve an ATTiny85 that would do the following:

Every 5 seconds, send the following number: 123456 over I2C to address 0x04. (I will figure out the rest of the code !)

I have looked at many threads, I could not come up with a solution. I know I'm downloading to my ATTiny85, because I can make an LED flash, but looking at the SCL & SDA on a scope, nothing is happening....

I have tried a couple of libraries, modified a few sketches (most of those sketches were behaving as a slave)....it simply does not work....frustration level is getting pretty high !!!

I was able to do it with a Nano, but sizewise (and costwise) I need an ATTiny85

Can anyone help me ?

Did you try the TinyWireM library on the ATtiny85

Yes I did...

Found TinyWireM and TinyWireS

must be doing something wrong ...

I just tried the sketch below. Using an Arduino Uno as slave it works as expexted.

/* ATtiny85 as an I2C Master. cpu @ 1MHz   
 * ATtiny Pin 5 = SDA 
 * ATtiny Pin 7 = SCK 
 */
#include <TinyWireM.h>                  // I2C Master lib for ATTiny
unsigned long val=123456;
char buf[7];

void setup(){
  sprintf(buf, "%lu", val);
  TinyWireM.begin();                    // initialize I2C lib
  delay (1000);
}

void loop(){
  TinyWireM.beginTransmission(4) ; // setup slave's address (7 bit address - same as Wire)
  for (int x=0;x<=(strlen(buf));x++){
    TinyWireM.send(buf[x]) ;      // buffer up bytes to send - can be called multiple times
  }
  byte someByte = TinyWireM.endTransmission();          // actually send the bytes in the buffer
  delay(1000);
}

Thanks Erni !

it works !