const byte MY_ADDRESS = x; // where x is whatever unique address you like
byte RxByte[32] //32 byte buffer
void setup() {
//insert unique ddress
Wire.begin(MY_ADDRESS);
// this line allows the arduino to listen for i2c broadcast at address 0
TWAR = (MY_ADDRESS << 1) | 1;
//set up a receive handler
Wire.onReceive(receive_data);
then call
Wire.beginTransmission (0) //transmit broadcast so all devices will receive
Wire.write( address of destination) // make the first byte the destination
Wire.endTransmission ();
then you need a receive handler
void receive_data() {
//use a buffer to temporarily store the data
for ( int d = 0; Wire.available() > 0 ;d++){
RxByte[d] = Wire.read();} // READ WIRE BUFFER UPTO 32BYTES, INTO AN ARRAY
datareceived = 1;
//then test if it was for this device
if (RxByte[0] == MYADDRESS){ do somthing with RxBytes[1-31];}
else {}
I use this extensively its very handy and works well I have a complex transmission table which has a 4 byte header and the rest of the bytes can be used as data send
destination, myaddress, a command, and how many data bytes to follow
Addendum to Original answer. below is a complete working example.