
MEGA 2560 board has pull-up resistors on pins 20 - 21 onboard. Please refer to the examples for more informations. Please note that a pull-up resistor is needed when connecting SDA/SCL pins. However the addresses from 0 to 7 are not used because are reserved so the first address that can be used is 8. shift the value one bit to the right), yielding an address between 0 and 127. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. The Wire library uses 7 bit addresses throughout. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. There are both 7- and 8-bit versions of I2C addresses. Because of this, send() and receive() have been replaced with read() and write().

The Arduino Due has two I2C / TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.Īs a reference the table below shows where TWI pins are located on various Arduino boards.Īs of Arduino 1.0, the library inherits from the Stream functions, making it consistent with other read/write libraries. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. This library allows you to communicate with I2C / TWI devices. Wire.Reference Language | Libraries | Comparison | Changes Wire.endTransmission(true) //true=send stopĪrduino addresses are 7 bit (excluding RW bit), so I2C byte address 0x40 needs to be changed to 0x20 for arduino functions.Ĭlock Speed tClock(100000) //100000 = standard mode 0=success, 1=tx buff overrun, 2=NACK on address tx, 3=NACK on data tx, 4=other error If (Wire.endTransmission(false) = 0) //false=send restart (IMPORTANT-THIS ENDTRANSMISSION DOES NOT SEND STOP!). No need to send stop as done automatically Uint8_t BytesReceived = Wire.available() //The slave can send less than was requested Wire.requestFrom(0x5a, 2) //Address, no of bytes

Result: 0=success, 1=tx buff overrun, 2=NACK on address tx, 3=NACK on data tx, 4=other error Uint8_t Result = Wire.endTransmission(true) //true=send stop

Seems to be 7 bit value with bit0=lower bit (not I2C RW bit), so left shifted by 1 when sent over the wire.
