use command below to enable I2C interface (in menu "2 Interface Options" -> "P5 I2C").
sudo raspi-config
Below command could be used to check I2C address
sudo i2cdetect -a -y 1
Example code in Python
python test code for raspberry pi EP-0099 4 channel relay module.PNG (Size: 13.21 KB / Downloads: 21)
Output:
sudo raspi-config
Below command could be used to check I2C address
sudo i2cdetect -a -y 1
Example code in Python
Code:
import time
import smbus
import sys
DEVICE_BUS = 1
DEVICE_ADDR = 0x10
bus = smbus.SMBus(DEVICE_BUS)
while True:
try:
for i in range(1,5):
print("\nturning on %d" % i)
bus.write_byte_data(DEVICE_ADDR, i, 0xFF)
time.sleep(2)
print("turning off %d" % i)
bus.write_byte_data(DEVICE_ADDR, i, 0x0)
time.sleep(3)
except KeyboardInterrupt as e:
print("Quit")
sys.exit()
python test code for raspberry pi EP-0099 4 channel relay module.PNG (Size: 13.21 KB / Downloads: 21)
Output:
Code:
pi@raspberrypi:~ $ python3 test_relay.py
turning on 1
turning off 1
turning on 2
turning off 2
turning on 3
turning off 3
turning on 4
turning off 4