Get Started With BEVRLink 8 Channel Relay - Raspberry PICO manager Python

Get Started With BEVRLink 8 Channel Relay - Raspberry PICO manager Python

The example below is only one way how to set up the Relay Module.

In this examples we have connected a PICO to the BEVRLink Manager PICO 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

Set up CircuitPython

  1. Download latest CircuitPython Firmware
  2. Hold BOOTSEL while plugging the PICO in to your PC
  3. A USB Drive called RPI-RP2 should appear on your computer
  4. Drag and drop the downloaded UF2 to the Drive
  5. The board will automatically flash it self and reboot removing the drive
  6. You will get a new USB Drive attached called CIRCUITPY that will hold your code and files

Code

  1. First download the library for MCP23008
  2. Unzip and copy the folder adafruit_mcp230xx to the lib folder on the PICO
  3. Write the code in a code.py file
import time
import board
import busio
import digitalio

from adafruit_mcp230xx.mcp23008 import MCP23008

# Initialize the I2C bus:
i2cbus = busio.I2C(scl=board.GP1, sda=board.GP0)

# Create an instance of either the MCP23008 or MCP23017 class depending on
# which chip you're using:
r1 = MCP23008(i2cbus, 0x20)  # Address of relay card 1 
r2 = MCP23008(i2cbus, 0x21)  # Address of relay expansion card 

# Make a list of all the pins
r1_pins = []
for pin in range(0, 8):
    r1_pins.append(r1.get_pin(pin))

r2_pins = []
for pin in range(0, 8):
    r2_pins.append(r2.get_pin(pin))

# Set all the pins to output
for pin in r1_pins:
    pin.direction = digitalio.Direction.OUTPUT

for pin in r2_pins:
    pin.direction = digitalio.Direction.OUTPUT

while True: # Loop
    # Turn on each relay for one second
    for pin in r1_pins:
        pin.value = True    # turn LED on!
        time.sleep(1)     # wait 0.1 seconds
        pin.value = False   # turn LED off
        time.sleep(1)     # wait 0.1 seconds
    for pin in r2_pins:
        pin.value = True    # turn LED on!
        time.sleep(1)     # wait 0.1 seconds
        pin.value = False   # turn LED off
        time.sleep(1)     # wait 0.1 seconds

Copy the code file code.py to the USB drive CIRCUITPY.

The code should autorun as soon as it saved on the drive, otherwise open a serial connection to the Pico shell and check for errors