Get Started With BEVRLink 4 Channel Relay with 4 Inputs - ROCK PI Manager Python

Get Started With BEVRLink 4 Channel Relay with 4 Inputs - ROCK PI Manager Python

Get Started With BEVRLink 8 Channel Relay - ROCK PI Manager Python Reading Get Started With BEVRLink 4 Channel Relay with 4 Inputs - ROCK PI Manager Python 3 minutes Next Get Started With BEVRLink 8 Channel Relay - ESP32 manager ESPHOME

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 4 Channel Relay and 4 manual test buttons 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:

https://www.okdo.com/software-hub

2.Use Balena Etcher to flash the image to an SD Card. 

https://www.balena.io/etcher

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.

ssh rock@rock-4c-plus

ref: https://www.okdo.com/getting-started/get-started-with-rock-4-se-ubuntu-server/

Enable i2c

8.

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.

10.

sudo reboot

Install i2c and Python libraries

11.

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

14.

sudo nano relay.py

Each relay is a bit in the sent byte, so 0x05 converted to binary number 00000101 turns on relay 1,3.

Add a jumper to position 1 on the expander to increase the address to 0x39

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 = 0x38 # Address of relay card 1  
i2caddress_Relay_2 = 0x39 # Address of relay card 2 

# Registers for PCA9554A
INREG = 0x00 # Input read register
OUTREG = 0x01 # Output write register    
IOCONF = 0x03 # Configure IO as Input or Output register

# Config 4 first pins as outputs and 4 last as inputs
i2cbus.write_byte_data(i2caddress_Relay_1, IOCONF, 0xF0)
i2cbus.write_byte_data(i2caddress_Relay_2, IOCONF, 0xF0)

while (True): # Loop
    # Read the inputs and copy it to the output
    input1 = i2cbus.read_byte_data(i2caddress_Relay_1, INREG)     
    input2 = i2cbus.read_byte_data(i2caddress_Relay_2, INREG) 
    i2cbus.write_byte_data(i2caddress_Relay_1, OUTREG, ~(input1 >> 4))
    i2cbus.write_byte_data(i2caddress_Relay_2, OUTREG, ~(input2 >> 4)) 

sudo python3 relay.py

 

15. CTRL+C to stop script