Low power relays boards are one of the most common interfaces between a Arduino/Raspberry Pi and the outside world. These relay boards provides electrical isolation between the low voltage circuits of the Arduino/Raspberry Pi and the high voltage loads. So why this I2C relay board?

i2c relay boards only requires 4 pins from Arduino/Raspberry pi to control up to 128 relay.

Raspberry Pi i2c

Example of controlling i2c relay board from Raspberry Pi
1 – +5V
2 – GND (common power supply ground)
3 – SDA (i2C data) Physical Pin 3
4 – SCL (i2C clock) Physical Pin 5

Arduino i2c

Example of controlling the relays from an Arduino:
1 – +5V
2 – GND (common power supply ground)
3 – SDA (I2C data) Physical Pin A4
4 – SCL (I2C clock) Physical Pin A5

Support for i2c relay board for zone and boiler control was long due. The relay board control requires this file easyi2c.py

Here is Example Code:

Basic Steps in Python Script to control relay board.

Full datasheet is here if you want to see some of the other features (use delay, read back status etc) see datasheet

Raspberry pi Configuration for i2c

Physical pin for i2c on raspberry pi are 3 and 3 whereas in WiringPi i2c pins are 8 and 9. You can verify the address of connected i2c peripherals with a simple one-line but you to enable i2c from Raspberry pi config menu and install i2c tools.

PiHome Enable i2c interface on Raspberry pi Config Menu

PiHome Enable i2c interface on Raspberry pi Config Menu

PiHome Enable i2c interface on Raspberry pi Config Menu Interface

PiHome Enable i2c interface on Raspberry pi Config Menu Interface

PiHome Enable i2c Interface Confirmation

PiHome Enable i2c Interface Confirmation

PiHome Enable i2c Interface Confirmation

PiHome Enable i2c Interface Confirmation

Once i2c interface is successfully enabled you need to install i2c Tools, to do so run following command

After i2c tools are install successfully run following command to check address for connected i2c devices.

sudo i2cdetect -y 1
— gives current i2c address default is 32

i2c interface address

i2c interface address

Python script to change i2c Address:

sudo i2cdetect -y 1
— gives new i2c address which is 21 for above settings.

Integrating i2c in PiHome

Python can be executed from PHP script (/var/www/cron/boiler.php) to integrate with exiting system. Controlling i2c relay board requires three variables, one i2c address, relay number and command to for on and off.

i2c Address

i2c address is hard coded in boiler.php file and this can be changed if required in the code on following free locations

  • Zone Status
  • Boiler On
  • Boiler Off

Relay Pin

Boiler and Zone already have GPIO Pin numbers options which is used as pin for i2c relay number and these numbers can be modified from GUI under settings.

Zone Status

Boiler On

Boiler Off

 

For previous conversation where i2c started have look at comments on this page