RPi Relay Board (B)

From Waveshare Wiki
Jump to: navigation, search
RPi Relay Board (B)
RPi-Relay-Board-B-0.jpg

Raspberry Pi Expansion Board, Power Relay
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

We provide Raspberry Pi and Jetson Nano demo for this module

Interface introduce

The correspondence between relay channels and Pi pins:

Channel number RPi pin number wiringPi BCM Description
Channel label 29 P21 5 Channel 1
Channel label 31 P22 6 Channel 2
Channel label 33 P23 13 Channel 3
Channel label 36 P27 16 Channel 4
Channel label 35 P24 19 Channel 5
Channel label 38 P28 20 Channel 6
Channel label 40 P29 21 Channel 7
Channel label 37 P25 26 Channel 8

【Note】The silk screen marking on the PCB corresponds to the BCM code.

The use of yellow jumpers

Relay_JMP is the relay control pin selection jumper. When the jumpers are connected, the Raspberry Pi can be used to control the relays.

Working with Raspberry Pi

Install library

PS: If you are using the system of the Bullseye branch, you need to change "apt-get" to "apt", the system of the Bullseye branch only supports Python3.

BCM2835

#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz 
cd bcm2835-1.71/
sudo . /configure && sudo make && sudo make check && sudo make install
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error

# Bullseye branch system using the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error

Python

# python2
sudo apt-get update
sudo apt-get install python-pip
sudo pip install RPi.GPIO
# python3
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install RPi.GPIO

Test demo

Execute the following commands on the terminal, download the demo, and extract it to the specified directory.

wget https://files.waveshare.com/upload/b/b4/RPi_Relay_Board_B.zip
unzip -o RPi_Relay_Board_B.zip -d ./RPi_Relay_Board_B
sudo chmod 777 -R RPi_Relay_Board_B
cd RPi_Relay_Board_B/RaspberryPi/

BCM2835 demo

Enter the Linux terminal and execute the following command in the terminal:

cd bcm2835
make
sudo ./Relay_demo

Expected result: The relays on the module are closed in turn, and then disconnected in turn. Each relay has a corresponding indicator light, which can be known by observing the status of the indicator light. When the user wants to stop running the program, press Ctrl+C to stop the running of the demo.

WiringPi demo

Enter the Linux terminal and execute the following command in the terminal:

cd wiringPi
make
sudo ./Relay_demo

Expected result: The relays on the module are closed in turn, and then disconnected in turn. Each relay has a corresponding indicator light, which can be known by observing the status of the indicator light. When the user wants to stop running the program, press Ctrl+C to stop the running of the demo.

Python demo

Enter the Linux terminal and execute the following command in the terminal:

cd python
sudo python Relay_demo.py

Expected result: The relays on the module are closed in turn, and then disconnected in turn. Each relay has a corresponding indicator light, which can be known by observing the status of the indicator light. When the user wants to stop running the program, press Ctrl+C to stop the running of the demo.

Web control

The web page control of this demo is based on the Python web framework to control the relay.
Enter the Linux terminal and execute the following command in the terminal:

sudo apt-get install python-bottle
cd python-bottle
sudo python main.py

Enter the IP address of the Raspberry Pi in the address bar of Google Chrome (other browsers may not be compatible), port number 8080.
RPi-Realy Board B python-bottle.png

Working with Horizon Sunrise X3 Pi

RPI Relay Board (B)

Install Library File

sudo apt update
sudo pip3 install bottle

Download Demo & Unzip to the Specified Directory

sudo apt-get install p7zip
wget https://files.waveshare.com/upload/b/b4/RPi_Relay_Board_B.zip
unzip -o RPi_Relay_Board_B.zip -d ./RPi_Relay_Board_B
sudo chmod 777 -R RPi_Relay_Board_B
cd RPi_Relay_Board_B/Sunrise_X3

Run the Demo

Python

cd python
sudo python3 Relay_Module.py

Expected results: The relays on the module close and then break in sequence, each with a responsive indicator, which can be seen by observing the status of the indicator. When the user wants to stop running the program, press Ctrl+C to stop the demo.

Web Control

The web control for this routine is based on the Python web framework to control relays.

cd python-bottle
sudo python3 main.py

Enter the Raspberry Pi IP address in the address bar of Google Chrome (other browsers may not be compatible), port number 8080.
RPi-Realy Board B python-bottle.png

Working with Jetson nano

Install library

sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install Jetson.GPIO
sudo groupadd -f -r gpio
sudo usermod -a -G gpio your_user_name
sudo cp /opt/nvidia/jetson-gpio/etc/99-gpio.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger

Test demo

Download the demo and enter the specified directory.

sudo apt-get install p7zip
wget https://files.waveshare.com/upload/c/c2/RPi_Relay_Board_B.7z
7zr x RPi_Relay_Board_B.7z -r -o./RPi_Relay_Board_B
sudo chmod 777 -R RPi_Relay_Board_B
cd RPi_Relay_Board_B/JetsonNano/

C demo

Enter the Linux terminal and execute the following command in the terminal:

cd C
make
sudo ./main

Expected result: The relays on the module are closed in turn, and then disconnected in turn. Each relay has a corresponding indicator light, which can be known by observing the status of the indicator light. When the user wants to stop running the program, press Ctrl+C to stop running the demo.

Python demo

Enter the Linux terminal and execute the following command in the terminal:

cd python
sudo python relay_demo.py

Expected result: The relays on the module are closed in turn, and then disconnected in turn. Each relay has a corresponding indicator light, which can be known by observing the status of the indicator light. When the user wants to stop running the program, press Ctrl+C to stop the running of the demo.

Web control

The web page control of this demo is based on the Python web framework to control the relay.
Enter the Linux terminal and execute the following command in the terminal:

sudo apt-get install python-bottle
cd python-bottle
sudo python main.py

Enter the IP address of the Raspberry Pi in the address bar of Google Chrome (other browsers may not be compatible), port number 8080.
RPi-Realy Board B python-bottle.png

Resources

Others

Related Guides

FAQ

 Answer:
Because the relay is triggered by a low level, the relay pulls in when the output is low.


 Answer:
Yes, it is c45 rail, 35MM rail


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 AM GMT+8 (Monday to Friday)