Relay controlled with CAN BUS

In this tutorial we explain how to control the Relay Board with can bus. The hardware setup is composed by Master Board (to send CAN commands) and Slave Board (for Relays control). The Master Board is the official carrier CM4IO with a CM4 module and CAN BUS Shield. The Slave Board is the Relay Board whit a Raspberry Pi 4 and DUAL CAN BUS Shield.

The hardware connections is the follow

The CM4IO requires a 12 V DC power supply, instead the Relay boards require a 5 V DC power supply (max allowed value is 5.1 V). On can side, the connection requires a a couple of wires for CAN High and CAN Low (CAN High is connected with CAN High, CAN Low is connected with CAN Low).

Software example

On our demo we use Python, all our scripts are ready for download. For scripts execution it is mandatory to install Python, and several libraries for GPIO, can and arguments parser on both boards. Run the following commands:

sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install RPi.GPIO
sudo pip3 install argparse
sudo pip3 install can

Start can bus on Slave Board

On Slave Board we can run the script relay_mcp2515.py

python relay_mcp2515.py

The slave script switch off all relays and start CAN message listen with Id 0x1B2

Start can bus on Master Board

On Master Board we can run the script set_can_relay.py to send CAN commads. The script execution requires two argument Relay number (from 1 to 8) and Relay status (on/off), for example to switch on relay 1 use

python set_can_relay.py --rel 8 --status on

instead to switch off relay 8 use

python set_can_relay.py --rel 1 --status off