CM Home technical documentation Buy

Relay interface

Two relays are available on the CM-Home board. This article explais how to use them.

Features:

  • Normally-Opened and Normally-Closed contacts available on screw terminals
  • Max rated: 24 VAC/DC @ 1A
  • Snubbers already on-board to increase reliability with inductive loads

GPIO used

  • RL1 (left relay) GPIO21
  • RL2 (right relay) GPIO22

Manage the relays using RPi.GPIO

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)

Manage the relays using GPIOD

  • Set RL1 on: gpioset $(gpiofind GPIO21)=1
  • Set RL1 off: gpioset $(gpiofind GPIO21)=0
  • Set RL2 on: gpioset $(gpiofind GPIO22)=1
  • Set RL2 off: 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 
... 

Python example using gpiod

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)

Products related

CM-Panel-Basic

Features Index Buy

All-in-one 7 inch touch WiFi terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480
  • Capacitive touch
  • MIPI Camera connector
  • WiFi @ 2.4 GHz
CM-Panel-POE

Features Index Buy

All-in-one 7 inch touch POE terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480 pixel
  • Capacitive touch
  • Embedded micro UPS for safe shutdown
  • Power Over Ethernet @ 10/100 Mbit
  • Hi-resolution audio up to 384KHz@32bit
  • Real Time Clock with backup battery
  • 3 USB Host port
  • 1 RS485/422/RS232 port
  • 1 Relay
  • MIPI Camera connector
  • WiFi @ 2.4 GHz (optional)
CM-Home

Features Index Buy

Home Automation board powered by Raspberry Pi CM4S lite module
  • Power-in @ 12 to 24VDC
  • Double opto-isolated RS-485 ports
  • 2 relays
  • 2 USB 2.0 host port
  • Ethernet port at 10/100Mbit
  • MIPI Camera connector
  • Stereo audio out on 3.5 mm jack

Home page CM Home technical documentation Buy