Pico Relay B

From Waveshare Wiki
Jump to: navigation, search
Pico-Relay-B
Pico RTC DS3231
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

Industrial 8-Channel Relay Module For Raspberry Pi Pico, Power Supply Isolation, Photocoupler Isolation.

Features

  • Onboard unibody power supply isolation, provides stable isolated voltage, needs no extra power supply for the isolated terminal.
  • Onboard photocoupler isolation, prevent interference from external high-voltage circuit connected to the relay.
  • High-quality relay, contact rating: 10A 250V AC or ≤10A 30V DC.
  • ABS protection enclosure with rail-mount support, easy to install, safe to use.
  • Breakout USB port and BOOT pin, make it easy to debug without disassembling the enclosure.
  • PWR indicator, RGB LED, and passive buzzer outside the enclosure.

Specifications

  • Operating voltage: 5V
  • Communication Protocol: USB
  • Communication interface: Micro USB
  • Relay channel: 8 ch
  • Contact form: 1NO 1NC
  • Dimension: 88(H)x 122(V) mm

Pinout

Pico-Relay-B-details-inter.jpg

Pico User Guide

Hardware connection

Relay B Pico Description
VCC VSYS Power input
GND GND Ground
CH1 GP21 Control pin of Channel 1
CH2 GP20 Control pin of Channel 2
CH3 GP19 Control pin of Channel 3
CH4 GP18 Control pin of Channel 4
CH5 GP17 Control pin of Channel 5
CH6 GP16 Control pin of Channel 6
CH7 GP15 Control pin of Channel7
CH8 GP14 Control pin of Channel 8
RGB GP13 Control pin of RGB LED
BUZZER GP6 Control pin of buzzer

Connection

Pico-Relay-B-details-3.jpg
Download the SSCOM serial port debugging assistant and open it on the computer, open the corresponding port number, set the baud rate to 115200, and click the corresponding function to send the corresponding command.
Pico-Relay-B Guide003.jpg

Setup environment

1. For the Raspberry Pi environment setting, please refer to link.
2. For the Windows environment setting, please refer to link.

Raspberry Pi

1. Open a terminal of Raspberry Pi.
2. Download and unzip the demo codes to the directory Pico C/C++ SDK.

sudo apt-get install p7zip-full
cd ~
sudo wget  https://files.waveshare.com/upload/a/a1/Pico-Relay-B_code.7z
 
7z x Pico-Relay-B_code.7z -o./Pico-Relay-B_code
cd ~/Pico-Relay-B_code
cd c/build/

C

1. Hold the BOOTSEL button of Pico, and connect the USB interface of Pico to Raspberry Pi then release the button.
2. Go into the build directory and add the SDK path.

cd ~/Pico-Relay-B_code/c/
cd build
export PICO_SDK_PATH=../../pico-sdk

3. Run the command cmake to generate the Makefile file.

cmake ..

4. Run the command make to build and generate the executable file.

make -j9

4. after building, a uf2 file is generated. Press and hold the button of the Pico board, connect it to Raspberry Pi by USB cable, and then release the button. Copy the main.uf2 file generated to the recognized movable disk (RPI-RP2).

cp main.uf2 /media/pi/RPI-RP2/

Send hexadecimal commands to Relay via serial port for control of:

01: Relay switch #1
02: No.2 relay switch
03: No.3 relay switch
04: Relay switch #4
05: No.5 relay switch
06: No.6 relay switch
07: No.7 relay switch
08: No.8 relay switch
09: Relay fully off
0A: Relay fully open

Python codes

Use in Windows

  • 1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer through the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
  • 2. Copy the rp2-pico-20210418-v1.15.uf2 file in the python directory to the recognized removable disk (RPI-RP2).
  • 3. Open Thonny IDE (Note: Use the latest version of Thonny, otherwise there is no Pico support package, the latest version under Windows is v3.3.3).
  • 4. Click Tools -> Settings -> Interpreter, and select Pico and the corresponding port as shown in the figure.

Pico-lcd-0.96-img-config.png

  • 5. File -> Open -> the corresponding .py file, click to run, as shown in the following figure:

Pico-Thonny-v1.15.jpg

  • After running, you can send the command directly in the Shell, the command is as follows:
1: Relay switch No. 1
2: Relay switch No. 2
3: Relay switch No. 3
4: Relay switch No. 4
5: Relay switch No. 5
6: No. 6 relay switch
7: Relay switch No. 7
8: No. 8 relay switch
9: The relay is fully closed
10: The relay is fully open

Run in Raspberry Pi

  • Hold the BOOTSET key of the Pico board, then connect the Pico to Raspberry Pi by USB cable, then release the key.
  • Once the removable disk (RPI-RPI2) is recognized, copy the rp2-pico-20210418-v1.15.uf2 file to pico.
  • Open the Thonny IDE in Raspberry Pi, update it if it doesn't support Pico.
  • Configure the port by choosing MicroPython(Raspberry Pi and ttyACM0 port) in Tools -> Options... -> Interpreter.

Pico-lcd-0.96-img-config2.png
If your Thonny doesn't support Pico, you can update it with the following command:

sudo apt upgrade thonny
  • Choose File -> Open...-> python/ and select the corresponding .py file to run the codes.
  • After running, you can send the command directly in the Shell, the command is as follows:
1: Relay switch No. 1
2: Relay switch No. 2
3: Relay switch No. 3
4: Relay switch No. 4
5: Relay switch No. 5
6: No. 6 relay switch
7: Relay switch No. 7
8: No. 8 relay switch
9: The relay is fully closed
10: The relay is fully open


Pico W

Due to the change in the location of Pico W's BOOT pads, the Pico W cannot be entered into burn-in mode through the BOOT switch that comes with the bottom board.

Demo Download

Open the Raspberry Pi terminal and execute:

cd ~
sudo wget  https://files.waveshare.com/upload/0/0c/Pico-w-Relay-demo.zip
unzip Pico-w-Relay-demo.zip

Demo Use

C

  • Enter the Pico_Relay_Tcp.c file in examples, and set up the wifi name, wifi password, server IP, and server port.
sudo nano ~/Pico-w-Relay-demo/c/examples/Pico_Relay_Tcp.c

Pico-w-Relay-demo01.jpg

  • The following tutorial is for operation on Raspberry Pi, but due to the multi-platform and portable nature of CMake, it can be successfully compiled on a PC, but the operation is slightly different and requires your own judgment.

To do the compilation, make sure that the c directory:

 cd ~/Pico-w-Relay-demo/c/

Create and enter the build directory, and add the SDK: where . /... /pico-sdk is the directory of your SDK. There is a build in our sample application, just enter it directly:

cd build
export PICO_SDK_PATH=../../pico-sdk
(Note: Be sure to write the right path to your own SDK)

Execute CMake and automatically generate Makefile:

cmake ..

Execute make to generate the executable file, the first compilation time is longer:

make -j9

When the compilation is complete, the uf2 file will be generated. Press and hold the button on the Pico board, connect the pico to the USB port of the Raspberry Pi via the micro USB cable, and then release the button. Once connected, the Raspberry Pi will automatically recognize a removable disk (RPI-RP2), copy the main.uf2 file from the build folder to the recognized removable disk (RPI-RP2).

cp main.uf2 /media/pi/RPI-RP2/

Sending string commands to Relay via TCP server for control:

Relay 1: Relay switch No. 1
Relay 2: Relay switch No. 2
Relay 3: Relay switch No. 3
Relay 4: Relay switch No. 4
Relay 5: Relay Switch No. 5
Relay 6: Relay Switch No. 6
Relay 7: Relay Switch No. 7
Relay 8: Relay 8 switch
Relay ALL OFF: Relay all off
Relay ALL ON: Relay ALL ON

Python

  • Enter TCP_Relay.py file in Python, and set up the wifi name, wifi password, server IP, and server port.

Pico relay b pico w09.jpg

Windows

  • 1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer via the Micro USB cable, and release the button after the computer recognizes a removable disk (RPI-RP2).
  • 2. Copy the rp2-pico-w-20230209-v1.19.1.uf2 file from the python directory to the recognized removable disk (RPI-RP2).
  • 3. Open the Thonny IDE (note: use the latest version of Thonny, otherwise there is no support package for Pico, the latest version for Windows is v3.3.3).
  • 4. Click Tools -> Settings -> Interpreter, and select Pico and the corresponding port as shown in the picture.

Pico-lcd-0.96-img-config.png

  • 5. File -> Open -> Pico-Relay-B_test.py, click to run and as shown below:

Pico-lcd-0.96-img-run.png

  • After running, you can directly send the commands in Shell, the commands as shown below:
1: No.1 relay switch
2: No.2 relay switch
3: No.3 relay switch
4: No.4 relay switch
5: No.5 relay switch
6: No.6 relay switch
7: No.7 relay switch
8: No.8 relay switch
9: Relay full off
10: Relay fully open

Raspberry Pi

  • 1. The process of firmware flushing is the same as on Windows, you can choose to copy the pico_micropython_20210121.uf2 file into pico on a PC or Raspberry Pi.
  • 2. Open the Thonny IDE in Raspberry Pi Mountain (click Raspberry logo -> Programming -> Thonny Python IDE), you can check the version information in Help->About Thonny

To make sure your version has the Pico support package, also you can click on Tools -> Options... -> Interpreter to select MicroPico. -> Interpreter to select MicroPython (Raspberry Pi Pico and ttyACM0 port.) As shown in the image:
Pico-lcd-0.96-img-config2.png
If your current Thonny version has no Pico support package, you can input the following commands to update Thonny IDE:

sudo apt upgrade thonny
  • 3. Click File -> Open... -> python/Pico-Relay-B.py, and run the script:
  • Sending string commands to Relay via TCP server for control:
Relay 1: Relay 1 switch 
Relay 2: Relay 2 switch   
Relay 3: Relay 3 switch 
Relay 4: Relay 4 switch  
Relay 5: Relay 5 Switch  
Relay 6: Relay 6 Switch 
Relay 7: Relay 7 Switch  
Relay 8: Relay 8 switch
Relay ALL OFF: Relay all off
Relay ALL ON: Relay ALL ON

Resource

Document

Demo codes

Software

Development Software

Pico Quick Start

Download Firmware

  • MicroPython Firmware Download

MicroPython Firmware Download.gif

  • C_Blink Firmware Download

C Blink Download.gif

Video Tutorial

  • Pico Tutorial I - Basic Introduction

  • Pico Tutorial II - GPIO

  • Pico Tutorial III - PWM

  • Pico Tutorial IV - ADC

  • Pico Tutorial V - UART

  • Pico Tutorial VI - To be continued...

MicroPython Series

C/C++ Series

Arduino IDE Series

Install Arduino IDE

  1. Download the Arduino IDE installation package from Arduino website.
    RoArm-M1 Tutorial II01.jpg
  2. Just click on "JUST DOWNLOAD".
    Arduino IDE Pico.png
  3. Click to install after downloading.
    RoArm-M1 Tutorial II02.gif
  4. Note: You will be prompted to install the driver during the installation process, we can click Install.

Install Arduino-Pico Core on Arduino IDE

  1. Open Arduino IDE, click the File on the left corner and choose "Preferences".
    RoArm-M1 Tutorial04.jpg
  2. Add the following link in the additional development board manager URL, then click OK.
    https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

    RoArm-M1 Tutorial II05.jpg
    Note: If you already have the ESP8266 board URL, you can separate the URLs with commas like this:

    https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
    
  3. Click on Tools -> Dev Board -> Dev Board Manager -> Search for pico, it shows installed since my computer has already installed it.
    Pico Get Start 05.png
    Pico Get Start 06.png

Upload Demo At the First Time

  1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer via the Micro USB cable, and release the button when the computer recognizes a removable hard drive (RPI-RP2).
    Pico Get Start.gif
  2. Download the demo, open arduino\PWM\D1-LED path under the D1-LED.ino.
  3. Click Tools -> Port, remember the existing COM, do not need to click this COM (different computers show different COM, remember the existing COM on your computer).
    UGV1 doenload02EN.png
  4. Connect the driver board to the computer with a USB cable, then click Tools -> Ports, select uf2 Board for the first connection, and after the upload is complete, connecting again will result in an additional COM port.
    UGV1 doenload03EN.png
  5. Click Tool -> Dev Board -> Raspberry Pi Pico/RP2040 -> Raspberry Pi Pico.
    Pico Get Start02.png
  6. After setting, click the right arrow to upload.
    Pico Get Start03.png
    • If you encounter problems during the period, you need to reinstall or replace the Arduino IDE version, uninstall the Arduino IDE needs to be uninstalled cleanly, after uninstalling the software you need to manually delete all the contents of the folder C:\Users\[name]\AppData\Local\Arduino15 (you need to show the hidden files in order to see it) and then reinstall.


Open Source Demo

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)