The obective is to have a Rpi communicate with an arduino via a i2c bus. The arduino then directly controls a eight channel replay module. The interfcae should allow te RPi to turn on and off each relay and query its status. A heart beat signal will allow to maintain the health of the communications.
How Does It Work? Is It Safe?
The Raspberry Pi is running at 3.3 Volts while the Arduino is running at 5 Volts. There are tutorials that suggest using a level converter for the I2C communication. This is NOT needed if the Raspberry Pi is running as “master” and the Arduino is running as “slave”.
The reason it works is because the Arduino does not have any pull-ups resistors installed, but the P1 header on the Raspberry Pi has 1k8 ohms resistors to the 3.3 volts power rail. Data is transmitted by pulling the lines to 0v, for a “high” logic signal. For “low” logic signal, it’s pulled up to the supply rail voltage level. Because there is no pull-up resistors in the Arduino and because 3.3 volts is within the “low” logic level range for the Arduino everything works as it should.
THIS METHOD DID NOT WORK!
Use This method to enable i2c bus on the RPi:
This library allows you to communicate with I2C / TWI devices. 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. 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.
As a reference the table below shows where TWI pins are located on various Arduino boards.
|Board||I2C / TWI pins|
|Uno, Ethernet||A4 (SDA), A5 (SCL)|
|Mega2560||20 (SDA), 21 (SCL)|
|Leonardo||2 (SDA), 3 (SCL)||Due||20 (SDA), 21 (SCL), SDA1, SCL1|