The example below is only one way how to set up the Relay Module.
In this examples we have connected a Rock Pi 4C Plus to the BEVRLink Manager HAT V2 with BEVRLink 8 Channel Relay V1 12V. With this relay module board you need the BEVRLink Power Supply 12V 2A.
Optional for a safe setup we recommend to use case for both the manager and relay boards: BEVRLink Cases
Install Ubuntu Server for Rock
1. Download the image for your board, this guide assume you download Ubuntu Server for Rock 4C Plus:
2.Use Balena Etcher to flash the image to an SD Card.
5. Insert the SD Card to the Rock and
6. Connect the Rock to Ethernet
After the board has booted
7. Open a terminal and ssh into it.
sudo nano /boot/hw_intfc.conf
9. Change intfc:i2c7=off to on to turn on i2c on channel 7 that is used by BEVRLink to communicated with the relay boards.
Install i2c and Python libraries
sudo apt update sudo apt install python3-smbus python3-dev i2c-tools
12. Test if i2c works
sudo i2cdetect -y 7
13. Example with chip MCP23008 used in 8 ch relay
sudo nano relay.py
Each relay is a bit in the sent byte, so 0x55 converted to binary number 01010101 turns on relay 1,3,5 and 7
Add a jumper to position 1 on the expander to increase the address to 0x21
Remove or add lines contaning the i2c address for each relay board removed or added
from smbus import SMBus # Import the i2c library import time # Import time library to use sleep i2cbus = SMBus(7) # Create the i2c bus object on channel 7 i2caddress_Relay_1 = 0x20 # Address of relay card 1 i2caddress_Relay_2 = 0x21 # Address of relay card 2 # Registers for MCP23008 INREG = 0x09 # Input read register OUTREG = 0x0A # Output write register IOCONF = 0x00 # Configure IO as Input or Output register # Config all as outputs i2cbus.write_byte_data(i2caddress_Relay_1, IOCONF, 0x00) i2cbus.write_byte_data(i2caddress_Relay_2, IOCONF, 0x00) while (True): # Loop # Turn on half the relays i2cbus.write_byte_data(i2caddress_Relay_1, OUTREG, 0x55) i2cbus.write_byte_data(i2caddress_Relay_2, OUTREG, 0x55) time.sleep(1) # Wait 1 second # Turn on the other half i2cbus.write_byte_data(i2caddress_Relay_1, OUTREG, 0xAA) i2cbus.write_byte_data(i2caddress_Relay_2, OUTREG, 0xAA) time.sleep(1) # Wait 1 second
sudo python3 relay.py
15. CTRL+C to stop script