sending a string with ATTiny85 over I2C

Hi everyone,

I need to do the following:

  • take a known 3 digits string, and add it to a random 6 digits string.(total 9 characters, all numbers)
  • whenever an certain input is High, send that string over I2C to address 0x04

that pretty simple, isn’t it ?!

I have done it successfully, using a Nano as the sending device, but for cost reason, I want to use an ATTiny85.

I can’t figure out how to do it…I have downloaded the TinyWireM library, but I can’t seem to figure out how to use it !

Everytime I try to compile, I get a “Error compiling” without any hint on what is wrong !

Can someone help me on that one ?

#include <TinyWireM.h>
#include <USI_TWI_Master.h>

int NewCode = 3; 
long Value=0;
char charBuf[10];
String MyString = "";
boolean I2C_Flag = 0;
String StationCode = "254";

void setup()  {
  TinyWireM.begin();  
  pinMode(NewCode,INPUT);  
  delay(250);
}

 void loop() {
   if (I2C_Flag ==0){
     if (digitalRead(NewCode) == 1){
      GenerateRandomNumber();
      AddStationNumber();
      ConvertStringToChar();
      TransmitOverI2C();
      I2C_Flag = 1;
     }
   }
   if (I2C_Flag ==1){
      if (digitalRead(NewCode) == 0){ 
       I2C_Flag = 0;
      }
   }
   delay(25);
 }

void GenerateRandomNumber(){
      Value = random(100000,999999); 
      MyString = String(Value);
}
void AddStationNumber(){
  MyString = StationCode + MyString;
}
void ConvertStringToChar(){
      MyString.toCharArray(charBuf,10);
}
void TransmitOverI2C(){
  TinyWireM.beginTransmission(0x04);
  TinyWireM.send(charBuf[0]);
  TinyWireM.send(charBuf[1]);
  TinyWireM.send(charBuf[2]);
  TinyWireM.send(charBuf[3]);
  TinyWireM.send(charBuf[4]);
  TinyWireM.send(charBuf[5]);
  TinyWireM.send(charBuf[6]);
  TinyWireM.send(charBuf[7]);
  TinyWireM.send(charBuf[8]);
  TinyWireM.endTransmission();    
}
String MyString = "";

On a Tiny? Yeah, right.

beside your sarcasm, is there anything of interest in your comment ?

Jasmin