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

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:
1 2 3 4 5 6 |
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
1 |
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
1 |
python set_can_relay.py --rel 8 --status on |

instead to switch off relay 8 use
1 |
python set_can_relay.py --rel 1 --status off |
