This guide contains all the information you will need to run the OSA Electronics 6 Ch Relay Board for Raspberry Pi.
What we need
- Raspberry Pi A+/B+/2/3B/3B+/4B
- 6 Ch Relay Board for Raspberry Pi
- A MicroSD Card
- Set of 4 Nylon M2.5 Screws
- Set of 4 Nylon M2.5*11mm Female to Female Standoffs
- Set of 4 Nylon M2.5*5mm Male to Female Standoffs
Use the nylon screws and standoffs to assembly the Raspberry Pi together with the 6 Ch Relay Board, as shown on the image below:
By default, the board will start with OFF state relays. To change to ON state, you will need to control via I2C the main chip (PCF8574). The board requires 5v and 3.3v to operate.
The following image shows you the pinout of the board:
First off, make sure the board is fully assembled with your Raspberry Pi, and you have everything needed to continue qith this guide.
You can download Raspberry OS and other distributions from here.
Use your desired Linux distribution or install a fresh image of Raspberry OS.
Make sure your distro is up to date, or in any case, run:
sudo apt-get update sudo apt-get dist-upgrade
If not installed, install SMBus:
sudo apt-get install python-smbus
The next step is to create a new Python file:
This file should be blank! Just copy and paste the following text into the file:
# Test program for 6 Ch Relay Board RLB0665N # Imports Section import smbus import time # Initial Setup RELAY1 = 0xFE RELAY2 = 0xFD RELAY3 = 0xFB RELAY4 = 0xF7 RELAY5 = 0xEF RELAY6 = 0xDF bus = smbus.SMBus(1) # Set the I2C address PCF8574_addr = 0x20 # Run the program try: while True: bus.write_byte(PCF8574_addr, 0xFF) # Turn OFF all relays time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY1) # Turn ON Relay 1 time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY2) # Turn ON Relay 2 time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY3) # Turn ON Relay 3 time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY4) # Turn ON Relay 4 time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY5) # Turn ON Relay 5 time.sleep(0.5) bus.write_byte(PCF8574_addr, RELAY6) # Turn ON Relay 6 time.sleep(0.5) bus.write_byte(PCF8574_addr, 0x00) # Turn ON all relays time.sleep(0.5) except KeyboardInterrupt: # Trap a CTRL+C keyboard interrupt bus.write_byte(PCF8574_addr, 0xFF) # Turn OFF all relays
Save the file as usual (Ctrl+O) and exit (Ctr+X).
Now, run the script typing:
sudo python RLB0665N_test_script.py
Voilà! Your Relay Board should start to work!
To cancel the script at any time, just press Ctrl+C and it will be stopped.