Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales@spotpear.com
dragon_manager@163.com
tech-support@spotpear.com
zhoujie@spotpear.com
WhatsApp:13246739196
The RP2350-ETH is a mini RP2350 development board that allows you to have an integrated TCP/IP protocol stack for network communication.
On a very small board, 14 multi-functional GPIO pins are brought out, and the PCB edge uses half-hole processing, making it easy and quick to integrate into projects.

C/C++ development environment installation
MicroPython development environment installation

name3 =Arduino IDE development environment installation list3 =
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
| CH9120 | RP2350 | Function |
| RXD | GP21 | Serial data input |
| TXD | GP20 | Serial data output |
| TCPCS | GP17 | In TCP client mode, indicate the connection status; a low level signifies a successful connection |
| CFG0 | GP18 | Network configuration enable switch, when the level is low, enter serial port configuration mode |
| RSTI | GP19 | Reset, active low |
cd ~ sudo wget https://www.waveshare.net/w/upload/1/15/RP2350_ETH_CODE.zip unzip RP2350_ETH_CODE.zip cd ~/RP2350_ETH_CODE
cd C/RP2350-ETH-Demo/build/ export PICO_SDK_PATH=../../pico-sdk #Note: Make sure to write the correct path to your own SDK cmake .. #Execute make to generate an executable file, the first compilation takes a long time make -j9 #After the compilation is completed, the uf2 file will be generated
cp main.uf2 /media/pi/RPI-RP2/
As shown below:
If your current Thonny version does not have the pico support package, input the following command to update the Thonny IDE
sudo apt upgrade thonny
3. Click File->Open...->~/RP2350_ETH_CODE/Python/RP2350-ETH-Demo.py to run the script
| Item | Value |
| PICO_SDK_PATH | [The path to store PICO-SDK]\pico-sdk |
NMake Makefiles #Ctrl+S to save the settings, clear the build folder, restart Visual Studio Code and recompile







1. Network configuration
UCHAR CH9120_Mode = TCP_CLIENT; //Optional:TCP_SERVER、TCP_CLIENT、UDP_SERVER、UDP_CLIENT
UCHAR CH9120_LOCAL_IP[4] = {192, 168, 10, 205}; // LOCAL IP
UCHAR CH9120_GATEWAY[4] = {192, 168, 11, 1}; // GATEWAY
UCHAR CH9120_SUBNET_MASK[4] = {255, 255, 252, 0}; // SUBNET MASK
UCHAR CH9120_TARGET_IP[4] = {192, 168, 10, 137}; // TARGET_IP
UWORD CH9120_PORT1 = 1000; // LOCAL PORT1
UWORD CH9120_TARGET_PORT = 2000; // TARGET PORT
UDOUBLE CH9120_BAUD_RATE = 115200; // BAUD RATE
#define TCP_SERVER 0 #define TCP_CLIENT 1 #define UDP_SERVER 2 #define UDP_CLIENT 3
2. Hardware interface
void CH9120_Start();
void CH9120_End();
void CH9120_SetMode(UCHAR Mode);
void CH9120_SetLocalIP(UCHAR CH9120_LOCAL_IP[]);
void CH9120_SetSubnetMask(UCHAR CH9120_SUBNET_MASK[]);
void CH9120_SetGateway(UCHAR CH9120_GATEWAY[]);
void CH9120_SetTargetIP(UCHAR CH9120_TARGET_IP[]);
void CH9120_SetLocalPort(UWORD CH9120_PORT);
void CH9120_SetTargetPort(UWORD CH9120_TARGET_PORT);
void CH9120_SetBaudRate(UDOUBLE CH9120_BAUD_RATE);
3. Code parsing
The main code is as follows:
int Pico_ETH_CH9120_test(void)
{
CH9120_init(); //Initialize Configuration CH9120
RX_TX(); //receive and dispatch
}
4. Result demonstration
1. Network configuration
The code for configuring the operation mode, IP, gateway, subnet mask, port number, and serial port baud rate is in the Python/RP2350-ETH-Demo/RP2350-ETH-Demo.py files. You can modify it according to your actual needs:
MODE = 1 #0:TCP Server 1:TCP Client 2:UDP Server 3:UDP Client GATEWAY = (192, 168, 1, 1) # GATEWAY TARGET_IP = (192, 168, 1, 10) # TARGET_IP LOCAL_IP = (192, 168, 1, 200) # LOCAL_IP SUBNET_MASK = (255,255,255,0) # SUBNET_MASK LOCAL_PORT1 = 1000 # LOCAL_PORT1 TARGET_PORT = 2000 # TARGET_PORT BAUD_RATE = 115200 # BAUD_RATE
2. Hardware interface
The configuration functions of the CH9120 are all in the Python/RP2350-ETH-Demo/ch9120.py file, and the program imports the CH9120 class and then calls it through the ch9120 object
ch9120 = CH9120(uart1)
ch9120.enter_config()
ch9120.exit_config()
ch9120.set_mode(MODE)
ch9120.set_localIP(LOCAL_IP)
ch9120.set_subnetMask(SUBNET_MASK)
ch9120.set_gateway(GATEWAY)
ch9120.set_localPort(LOCAL_PORT1)
ch9120.set_targetIP(TARGET_IP)
ch9120.set_targetPort(TARGET_PORT)
ch9120.set_baudRate(BAUD_RATE)
3. Code parsing
The main code is as follows:
if __name__ == "__main__":
ch9120_configure()
while True:
time.sleep(0.1)
while uart1.any() > 0:
rxData1 = uart1.read(uart1.any())
uart1.write(rxData1)
print(rxData1.decode('utf8'))
4. Result demonstration

1. Network configuration
MQTT communication is implemented based on TCP/IP protocol, and the configuration code of MQTT and CH9120 is in the Python/RP2350-ETH-Demo/RP2350-ETH-MQTT.py file:
# MQTT CLIENT_ID = "Waveshare_RP2350_ETH" SUBSCRIBE_TOPIC = "test_topic1" PUBLISH_TOPIC = "test_topic2" # CH9120 MODE = 1 #0:TCP Server 1:TCP Client 2:UDP Server 3:UDP Client GATEWAY = (192, 168, 1, 1) # GATEWAY TARGET_IP = (47, 92, 129, 18) # TARGET_IP LOCAL_IP = (192, 168, 1, 200) # LOCAL_IP SUBNET_MASK = (255,255,255,0) # SUBNET_MASK LOCAL_PORT1 = 1000 # LOCAL_PORT1 TARGET_PORT = 1883 # TARGET_PORT BAUD_RATE = 115200 # BAUD_RATE
MQTT-related variable explanations, you can modify according to your own needs:
CLIENT_ID: Client ID SUBSCRIBE_TOPIC: The name of the subscribed topic PUBLISH_TOPIC: The name of the published topic TARGET_IP: MQTT server IP TARGET_PORT: MQTT server communication port
2. UART function
mqtt_client = MQTTClient(uart1)
mqtt_client.connect()
mqtt_client.subscribe(SUBSCRIBE_TOPIC)
mqtt_client.publish(PUBLISH_TOPIC, message)
mqtt_client.send_heartbeat()
mqtt_client.check_heartbeat_response()
mqtt_client.extract_data(rxData)
3. Code parsing
The main code is as follows:
if __name__ == "__main__":
ch9120_configure()
mqtt_client = MQTTClient(uart1)
mqtt_client.ClientID = CLIENT_ID # Set ClientID
mqtt_client.connect() # Connect to MQTT server
mqtt_client.subscribe(SUBSCRIBE_TOPIC) # Subscribe to topic:test_topic1
while True:
rxData = uart1.read()
if rxData is not None:
topic, message = mqtt_client.extract_data(rxData) # Parse the received data
if topic == SUBSCRIBE_TOPIC:
print("Topic:", topic)
print("Message:", message)
mqtt_client.publish(PUBLISH_TOPIC, message) # Send received data to topic:test_topic2
time.sleep_ms(20)
This code first configures CH9120, then sends byte data to the communication port of the MQTT server to establish a connection and subscribe to topics:
ch9120_configure() mqtt_client = MQTTClient(uart1) mqtt_client.ClientID = CLIENT_ID # Set ClientID mqtt_client.connect() # Connect to MQTT server mqtt_client.subscribe(SUBSCRIBE_TOPIC) # Subscribe to topic:test_topic1
This code indicates entering a data transmission and reception mode, where messages received are sent back from another topic:
while True:
rxData = uart1.read()
if rxData is not None:
topic, message = mqtt_client.extract_data(rxData) # Parse the received data
if topic == SUBSCRIBE_TOPIC:
print("Topic:", topic)
print("Message:", message)
mqtt_client.publish(PUBLISH_TOPIC, message) # Send received data to topic:test_topic2
time.sleep_ms(20)
After the connection is established, the client needs to ensure that the transmission interval of any two MQTT protocol packets does not exceed the value of Keep Alive. If the client is currently idle and there are no packets to send, it can send PINGREQ protocol packets (heartbeat packets). If the MQTT server does not receive any packets from the client within 1.5 times the time of Keep Alive, it will consider that there is a problem with the connection between the MQTT server and the client, and the server will disconnect from the client. Therefore, when the client does not send data packets for a long time but needs to maintain the connection, it should send a heartbeat packet at regular intervals. It is generally recommended to do so within half of the Keep Alive time. The following code indicates that a heartbeat packet is sent to the server every 30 seconds, and if the heartbeat check fails, it will reconnect until the heartbeat check is successful:
current_time = time.time()
if current_time - last_heartbeat_time >= 30:
last_heartbeat_time = current_time
mqtt_client.send_heartbeat()
if not mqtt_client.check_heartbeat_response():
while True:
mqtt_client.send_heartbeat()
if mqtt_client.check_heartbeat_response():
break
4. Result demonstration




Raspberry Pi Pico introduction
Serial port instruction set]
You can refer to the RP2350-E9 section in the RP2350 Datasheet
Monday-Friday (9:30-6:30) Saturday (9:30-5:30)
Email: services01@spotpear.com