Skip to content

Add a realy board to a RPICT

This guide shows how to combine a RPICT series card with a Relay Board. This is a convenient setup for controlling devices based on power uage decisions.

Equipment list

To mount this assembly you will need the following hardware.

  • A Raspberry Pi.
  • A RPICT card (can be any)
  • A RPIEXP West expansion card. (find it here).
  • A Relay Hat. (find it here).
  • Some 18mm male-female stand off.

The details for stand off are:

  • RPI/RPIEXP West -> 11mm Female-Female
  • RPIEXP West/Relay Hat -> 18mm Male-Female
  • RPIEXP West/RPICT -> 13mm Male-Female

Software Usage

Preliminaries

Make sure you have a fresh Raspbian image installed.

Setup the Raspbian to enable the serial port. See the guide below to complete this.
Howto setup Raspbian for serial read

Demonstration Script

This is an example below monitoring a single channel CT1. The relay is activated/de-activated when power goes above/below a given threshold.

#!/usr/bin/python3
import serial
import RPi.GPIO as GPIO

relay = 21 # use 21 for relay 1, 20 for relay 2, 26 for relay 3.
threshold = 30. # using 30W here
rpict_channel = 1 # using the first channel from the RPICT here

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(relay, GPIO.OUT)

ser = serial.Serial('/dev/ttyAMA0', 38400)

while 1:
    line = ser.readline().decode().strip()
    z = line.split(' ')

    value = z[rpict_channel]

    print(value, end = '')
    if float(value)>threshold:
        if GPIO.input(relay)==GPIO.LOW:
            GPIO.output(relay, GPIO.HIGH)
            print(" set to high", end = '')
    else:
        if GPIO.input(relay)==GPIO.HIGH:
            GPIO.output(relay, GPIO.LOW)
            print(" set to low", end = '')

    print()