Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales@spotpear.com
dragon_manager@163.com
tech-support@spotpear.com
zhoujie@spotpear.com
WhatsApp:13246739196
RP2350-ETH-8DI-8RO is an industrial-grade 8-channel network relay based on RP2350B microcontroller and supports RS485, Ethernet port and other peripheral interfaces. It features built-in power isolation and optocoupler isolation and other protection circuits, which is safe, stable and more reliable.
To facilitate the development of Pico/Pico2 boards with MicroPython on a computer, it is recommended to download the Thonny IDE
【MicroPython】 machine.Pin class function details
【MicroPython】machine.PWM class function details
【MicroPython】machine.ADC class function details
【MicroPython】machine.UART class function details
【MicroPython】machine.I2C class function details
【MicroPython】machine.SPI class function details
【MicroPython】rp2.StateMachine class function details
For C/C++, it is recommended to use Pico VSCode for development. This is a Microsoft Visual Studio Code extension designed to make it easier for you to create, develop, and debug projects for the Raspberry Pi Pico series development boards. No matter if you are a beginner or an experienced professional, this tool can assist you in developing Pico with confidence and ease. Here's how to install and use the extension.
Cmake Path: ${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake.exe Git Path: ${HOME}/.pico-sdk/git/cmd/git.exe Ninja Path: ${HOME}/.pico-sdk/ninja/v1.12.1/ninja.exe Python3 Path: ${HOME}/.pico-sdk/python/3.12.1/python.exe
Here are two methods for flashing firmware
1. Press and hold the Boot button 2. Connect the development board to the computer 3. Then the computer will recognize the development board as a USB device. 4. Copy the .uf2 file to the USB drive, and the device will automatically restart, indicating successful program flashing.
set(PICO_BOARD pico CACHE STRING "Board type")
https://github.com/earlephilhower/arduino-pico/releases/download/4.5.2/package_rp2040_index.json
Note: If you already have an ESP32 board URL, you can use a comma to separate the URLs as follows:
https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/4.5.2/package_rp2040_index.json
MircoPython video demo (github)
MicroPython firmware/Blink demos (C)
Raspberry Pi official C/C++ demo (github)
Raspberry Pi official MicroPython demo (github)
Arduino official C/C++ demo (github)
Demo description
Code analysis
uint8_t index
: In the main
function, the program will parse the received RS485 data and match it with the preset control command array. When a match is found, the Relay_Control
function is called, and the index position of the matching command in the array is passed via index
parameterif else
statement to perform different operations based on the value of index
:index < 8
, that is, for the CH1~CH6
commands, the DEV_Digital_Write
function is used to switch the level status of the corresponding GPIO pin (such as RELAY1_PIN
, etc.), and at the same time, the corresponding relay_status
array element is updated to record the change of the relay status, and the corresponding on or off prompt information is output according to the final state of the relay. Finally, in the main
function, the Beep
function is called to control the buzzer.index = 8
, i.e., for the ALL_ON
command, all GPIO pins (corresponding to 8 channel relays) are set to high level (on state). Using the memset
function, all elements of the relay_status
array are set to 1, indicating that all relays are turned on. A message indicating that all relays are turned on is then output. Finally, in the main
function, the Beep
function is called to control the buzzer.index = 9
, i.e., for the ALL_OFF
command, all GPIO pins (corresponding to 8 channel relays) will be set to low level (off state). Using the memset
function, all elements of the relay_status
array will be set to 0, indicating that all relays are off. A message indicating that all relays are off will be output. Finally, in the main
function, the Beep
function will be called to control the buzzer.index
does not match the above commands, the prompt message of receiving non-command data will be outputDemo description
Precautions
Code analysis
ConnectNetwork()
: Connect to the network via Ethernet portMQTTClientInit()
: Initialize MQTTMQTTConnect()
: Connect to MQTT serverMQTTSubscribe()
: Subscribe to MQTT topicMQTTPublish()
: Publish MQTT messageMQTT_CLIENT_ID
: Client IDMQTT_USERNAME
: UsernameMQTT_PASSWORD
: PasswordMQTT_SUBSCRIBE_TOPIC
: Name of the subscribed topicMQTT_PUBLISH_TOPIC
: Name of the published topicg_net_info.mac
: MAC addressg_net_info.ip
: IP addressg_net_info.sn
: Subnet maskg_net_info.gw
: Gatewayg_net_info.dns
: DNS serverConnectNetwork()
, MQTTConnect()
to connect to the network and MQTT server, and call MQTTSubscribe()
to subscribe to MQTT topicsg_mqtt_client.msg.payload
is not empty, parse the MQTT message and control the corresponding relay switchMQTTPublish()
to send the latest relay status to the server after controlling the relay switchDemo description
Code analysis
index
: In the main
function, the program will parse the received RS485 data and match it with the preset control command array. When a match is found, the relay_control
function is called, and the index position of the matching command in the array is passed via index
parameterif else
statement to perform different operations based on the value of index
:index < 8
, that is, for the CH1~CH6
commands, the relays[index].value
function is used to switch the level status of the corresponding GPIO pin, and at the same time, the corresponding relay_status
array element is updated to record the change of the relay status, and the corresponding on or off prompt information is output according to the final state of the relay. Finally, the beep
function is called to control the buzzer.index = 8
, i.e., for the ALL_ON
command, all GPIO pins (corresponding to 8 channel relays) are set to high level (on state), and all elements of the relay_status
array are set to 1 through the for
loop, indicating that all relays are turned on. A message indicating that all relays are turned on is then output. Finally, the beep
function is called to control the buzzer.index = 9
, i.e., for the ALL_OFF
command, all GPIO pins (corresponding to 8 channel relays) will be set to low level (off state). Using the for
loop, all elements of the relay_status
array will be set to 0, indicating that all relays are off. A message indicating that all relays are off will be output. Finally, the beep
function will be called to control the buzzer.index
does not match the above commands, the prompt message of receiving non-command data will be outputDemo description
Precautions
Code analysis
ethernet_init()
: Connect to the network via Ethernet portmqtt_connect()
: Connect to MQTT servermqtt_subscribe()
: Subscribe to MQTT topicmqtt_publish()
: Publish MQTT messageMQTT_SERVER
: Server IPMQTT_PORT
: Server port numberMQTT_CLIENT_ID
: Client IDMQTT_USERNAME
: UsernameMQTT_PASSWORD
: PasswordMQTT_SUBSCRIBE_TOPIC
: Name of the subscribed topicMQTT_PUBLISH_TOPIC
: Name of the published topicethernet_init()
, mqtt_connect()
to connect to the network and MQTT server, and call mqtt_subscribe()
to subscribe to MQTT topicsclient.set_callback()
, wait for the MQTT message in the main loop, call mqtt_recv_callback()
after judging the received MQTT message, parse the MQTT message and control the corresponding relay switchmqtt_publish()
to send the latest relay status to the server after controlling the relay switchYou can refer to the RP2350-E9 section in the RP2350 Datasheet
Please move the jumper cap to 120R and try again. Some RS485 devices require a 120R resistor to be connected in series
Monday-Friday (9:30-6:30) Saturday (9:30-5:30)
Email: services01@spotpear.com