# sudo i2cdetect -y 1 명령을 통해 I2C 인터페이스가 인스톨되어 사용할 수 있는지 체크
# 아래의 명령을 통해 데모코드 파일을 만들고 아래의 데모소스를 복사한 후 실행가능한 권한을 부여
# nano relay.py
# chmod +x relay.py
# 파일 실행하여 테스트
#! /usr/bin/python
import smbus
import sys
import getopt
import time
#bus = smbus.SMBus(0) Rev 1 board
bus = smbus.SMBus(1) # New Rev 2 board
address = 0x20 # I2C address setting
bus.write_byte_data(0x20,0x00,0x00) # Set all to output
# Handle the command line arguments
def main():
a = 0
delay = 1
while True:
# 4 - 8 is the binary number (1111 0000) that attached relay
for x in range(4,8):
bus.write_byte_data(address,0x09,1 << x) # Turn relay on in turn
time.sleep(delay) # 1 second delay
bus.write_byte_data(address,0x09,0) # Turn relay off
if __name__ == "__main__":
main()