Template: Pico relay b pico w
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
- 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.
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.
- 5. File -> Open -> Pico-Relay-B_test.py, click to run and as shown below:
- 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:
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