Master transmitter I2C

From Pinguino
Jump to: navigation, search


Example for functions: Wire.begin Wire.beginTransmission Wire.writeS Wire.endTransmission

// Master as transmitter
void setup() {
  Wire.begin(0,I2C_100KHZ); // 0=master mode and 100=100 KHz as bus speed   
}

u8 I2C_address = 0x2C; 
u8 x=0;
u8 message[3]= {'H','i','!'};

void loop() {
u8 convd[3];
  Wire.beginTransmission(I2C_address);
  Wire.writeS(message,3);
  Sprintf(convd,"%3d",x); // to convert a number to a string
  Wire.writeS(convd,3);
  Wire.endTransmission(1);
  x++;
  delay(5000);
}