CM Home technical documentation Buy
Features:
GPIO used
import RPi.GPIO as GPIO
import time
RL1=21
RL2=22
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RL1,GPIO.OUT)
GPIO.setup(RL2,GPIO.OUT)
for i in range(5):
GPIO.output(RL1,GPIO.LOW)
GPIO.output(RL2,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(RL1,GPIO.HIGH)
GPIO.output(RL2,GPIO.LOW)
time.sleep(0.5)
GPIO.output(RL1,GPIO.LOW)
GPIO.output(RL2,GPIO.LOW)
gpioset $(gpiofind GPIO21)=1
gpioset $(gpiofind GPIO21)=0
gpioset $(gpiofind GPIO22)=1
gpioset $(gpiofind GPIO22)=0
List all GPIO chips, print their labels and number of GPIO lines.
$ gpiodetect
gpiochip0 [pinctrl-bcm2711] (58 lines)
gpiochip1 [brcmvirt-gpio] (2 lines)
gpiochip2 [raspberrypi-exp-gpio] (8 lines)
Print information about all lines of the specified GPIO chip
$ gpioinfo pinctrl-bcm2711
line 0: "ID_SDA" unused input active-high
line 1: "ID_SCL" unused input active-high
line 2: "SDA1" unused input active-high
line 3: "SCL1" unused input active-high
line 4: "GPIO_GCLK" unused input active-high
line 5: "GPIO5" unused input active-high
line 6: "GPIO6" unused input active-high
...
Turn on and off the relay RL1 each seconds
import gpiod
import time
chip=gpiod.Chip('gpiochip0')
line = gpiod.find_line("GPIO21")
lines = chip.get_lines([line.offset()])
lines.request(consumer='foobar', type=gpiod.LINE_REQ_DIR_OUT, default_vals=[0])
while True:
print("RL1 on")
lines.set_values([1])
time.sleep(1)
print("RL1 on")
lines.set_values([0])
time.sleep(1)