multiple Arduino Pro mini through i2c

hi Guys:
I am trying to get multiple Arduino pro mini to work communicate through i2c. I add 10k ohm as pull up resistor, but there is no way for me to see the data transfer backforware in Serial Monitor. Does anyone know how to deal with this issue? I attached my wiring on breadboard.

MikeLuo:
hi Guys:
I am trying to get multiple Arduino pro mini to work communicate through i2c. I add 10k ohm as pull up resistor, but there is no way for me to see the data transfer backforware in Serial Monitor. Does anyone know how to deal with this issue? I attached my wiring on breadboard.

Try the attached sketch, I modified Wire to allow multiple Wire.write’s in the onRequest event.
The ‘master.ino’ sketch is both a master and slave I2C that bounces data packets back and forth.

Chuck.

master.ino (7.41 KB)

Wire.zip (19.7 KB)

MikeLuo: hi Guys: I am trying to get multiple Arduino pro mini to work communicate through i2c. I add 10k ohm as pull up resistor, but there is no way for me to see the data transfer backforware in Serial Monitor. Does anyone know how to deal with this issue? I attached my wiring on breadboard.

You could put blinki lights or plug in a I2C LCD.

Chuck.

Thank you so much, but I still have some questions. The example that's provided by arduino.cc is not working at all, right? and what is the differences between the i2c library you attached and the original i2c library?

MikeLuo: Thank you so much, but I still have some questions. The example that's provided by arduino.cc is not working at all, right? and what is the differences between the i2c library you attached and the original i2c library?

This is the list of changes 1. repeated onRequestEvent() callbacks, this allows over 32bytes to be sent in Slave Read mode 2. Timeouts in endTransmission(), requestFrom() incase bus is hung 3. extend error reporting 4. multiple Wire.write() statements in onRequestEvent(), fixes bug that only transmitted last Wire.write() 5. Added I2C_anthing template from Nick Gammon 6. Modified write(long),write

you might be getting caught by #2, If the I2C clock (SCL) is held low by any device, the original Wire Library will hang forever waiting for the SCL line to recover. I added timeouts to return an error if this happens. Open the source files and search 'chuck' this will list every change I implemented. you can compare the origional code in Program Files\Arduino\hardware\arduino\arv\libraries\Wire for differences.

The original Wire library works, but there are some limitations that have to be considered. in a onRequestEvent() callback, only the last Wire.write() call is effectively executed, each call to Wire.write() overwrites anything previously written. so, if your onRequestEvent() is for example:

void onRequestEvent(void){
Wire.write(1);
Wire.write(2);
Wire.write(3);
Wire.write('A');
char ch[]= "Now is the time";
for(uint8_t i=0;ch[i]!=0,i++){
  Wire.write(ch[i]);
  }
}

/* if the requesting I2C master issues requestFrom(slaveid,19);
 * you would expect to receive a sequence of 0x01,0x02,0x03,"ANow is the time".
 * you would actually receive 'e' followed by 18 0xff
 */

The biggest 'problem' changes were the onRequestEvent() handling and the bus error timeouts. The origional Wire.write() had a Wire.write(uint16_t) that only sent the lowByte, not both bytes.

Chuck.