
– I2CScanner.ino - Turn Arduino into I2C bus scanner ( github repo) Below is an Arduino sketch “I2CScanner.pde” that turns an Arduino into an I2C bus scanner.

Conceptually it’s very similar to a network “ping”. But newer I2C devices have fully programmable addresses, leading to cases of not knowing what address a device is at.įortunately, there’s a technique one can use to “scan” an I2C bus and determine these addresses. Older devices have a fixed address, or a “choose one-of-four” approach. I check the data for consistency so it isn’t really a problem. I've modified the Arduino TWI interface code to timeout and give me a timeout reason, but it isn't timing out anywhere. I think this may be due to clock stretching on the Arduino which the driver on the Pi can’t cope with. It looks like the transfer from the slave just stops at random points in the buffer (32 bytes). I am getting an approximate 10% failure rate in the communications. The cable between the two units is about 10cm long. I guess the weak pull ups are helping the Arduino as the code is working – most of the time. The ATMEGA 328 datasheet says the SDA and SCL lines need a minimum of 0.7*VCC (5V) as a logic high. The Arduino code is enabling its weak (20K – 50K according to the datasheet) internal pull ups on the SDA and SCL lines.

The Pi has fixed on board pull-ups (3.3K) on the SDA and SCL pins.

The Pi is an I2C MASTER, the UNO is a SLAVE.
