RP2040-ETH
| ||
Overview
Introduction
RP2040-ETH is a mini RP2040-ETH development board, which integrates TCP/IP protocol stack for network communication. 14 × multi-function GPIO pins and the castellated holes on its PCB edges allow easy and quick integration into projects.
Features
- Adopts RP2040 micro-controller chip designed by the official Raspberry Pi.
- Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz.
- Built-in 264KB of SRAM, and 4MB of onboard Flash memory.
- Onboard CH9120 with integrated TCP/IP protocol stack.
- With the host software and serial commands, you can set the network parameters such as chip operating mode, port, and IP.
- The castellated module allows soldering directly to carrier boards.
- Drag-and-drop programming using mass storage over USB.
- 14 × multi-function GPIO pins, compatible with some Pico HATs.
- More hardware peripherals:
- 1x SPI (SPI0)
- 2x I2C
- 2x UART
- 13x Controllable PWM channels
- Built-in temperature sensor.
- 8 × Programmable I/O (PIO) state machines for custom peripheral support.
Pinout Definition
RP2040-ETH User Manual
Environment Building
- C/C++ Development Environment Installation
- Before using demos and tutorials, you need to set up a development environment and learn the basics of engineering.
- MicroPython Development Environment Installation:
- Download the software according to your system from Thonny.
- After installing, please configure the language and the environment for the first time. Note that we should choose the Raspberry Pi option in the board environment.
- Configure the Micrpython environment and select the Pico port.
- First connect the Raspberry Pi Pico to the computer, left-click on the configuration environment option in the lower right corner of Thonny --> select configure an interpreter.
- In the pop-up window bar, select MicroPython (Raspberry Pi Pico), and select the corresponding port.
- Configure the Micrpython environment and select the Pico port.
- Click OK to return to the main interface of Thonny, download the firmware library to Pico, and then click the stop button to display the currently used environment in the Shell window.
- Pico download firmware library method in Windows: After connecting the computer, press and hold the BOOT and RESET buttons at the same time, release the RESET button first, and then release the BOOT button, a removable disk will appear on the computer and copy the firmware library into it.
- The Raspberry Pi system is similar to the Windows system, the Raspberry Pi needs to install the latest version of the system with the desktop.
- Arduino IDE Development Environment Installation:
- Open Arduino IDE, enter File -> Preferences
- In the pop-up dialog box, enter the following URL in the "Additional Boards Manager URLs" field:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
- Click "OK" to close the dialog box.
- Go to Tools -> Board Manager in IDE.
- Type "pico" in the search box and select "Add".
- Click "OK" to close the dialog box.
Hardware Connection
- The internal connection between CH9120 and RP2040 as shown below:
CH9120 | RP2040 | Function |
RXD | GP21 | Serial data input |
TXD | GP20 | Serial data output |
TCPCS | GP17 | In TCP client mode, indicates connection status, low level for successful connection |
CFG0 | GP18 | Network configuration enabled pin, low level for serial debugging mode |
RSTI | GP19 | Reset, active LOW |
Demo Usage
In Raspberry Pi
- Open the Raspberry Pi terminal, and run:
cd ~ sudo wget https://files.waveshare.com/upload/3/36/RP2040_ETH_CODE.zip unzip RP2040_ETH_CODE.zip cd ~/RP2040_ETH_CODE
C
- The following guide is operated in the Raspberry Pi. As CMake is multi-platform and portable, it can also be compiled on the PC. But the operation steps are different, you can explore it by yourselves.
- Before compiling, you should make sure it is in C/RP2040-ETH-Demo/build directory:
- Enter the build directory and add SDK:
- .../.../pico -sdk is your SDK directory.
cd C/RP2040-ETH-Demo/build/ export PICO_SDK_PATH=../../pico-sdk #Note: write the correct SDK path cmake .. #Execute make to generate the executable file and it takes a long time to compile for the first time make -j9 #Compilatio is finished, uf2 file is created.
- After connecting RP2040-ETH to the Raspberry Pi, you should press the BOOT and RESET keys at the same time. Release the RESET key first, and then the BOOT key. A portable disk will appear on the computer, and you can copy the firmware library to it.
cp main.uf2 /media/pi/RPI-RP2/
Python
- After connecting the RP2040-ETH to the Raspberry Pi, press the BOOT key and the RESET key at the same time. Release the RESET key, then the BOOT key and a removable disk are shown on the computer.
- Copy ~/RP2040_ETH_CODE/Python/rp2-pico-20230209-unstable-v1.19.1.uf2 file to the RP2040.
- Open the Thonny IDE on your Raspberry Pi (click on the 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 MicroPicoPython (Raspberry Pi Pico) and ttyACM0 port.
- If your current Thonny version has no Pico support package, you can enter the following commands to update Thonny IDE.
sudo apt upgrade thonny
- Click File -> Open... -> RP2040_ETH_CODE/Python/RP2040-ETH-Demo.py, run the demo.
In Windows Environment
C
- Firstly, install Visual Studio Code.
- After installing, open the Visual Studio Code expansion interface (Ctrl + Shift + X).
- Type CMake Tools and install.
- Press F1 and type open settings UI to open the settings UI screen.
- Search for CMake.configureEnvironment.
- Click Add item.
Item | Value |
PICO_SDK_PATH | [storage PICO-SDK path]\pico-sdk |
- "[storage PICO-SDK path]\pico-sdk" is the path you store SDK, and it can not be compiled when the path is wrong.
- Search cmake.generator, and fill in:
NMake Makefiles #Ctrl+S to save the setting, clear the build file folder, reboot Visual Studio Code, and compile again.
- Click to download the demo, unzip and then enter the RP2040_ETH_CODE file folder.
- After entering RP2040_ETH_CODE\C\RP2040-ETH-Demo, open the project with vs code.
- Choose the Compiler.
- Start to compile.
- Finish.
- Copy the main.uf2 file in build to Pico, and then it can automatically run the demo.
Python
- After connecting RP2040-ETH to the computer, press and hold down the BOOT and RESET keys at the same time, release the RESET button, and then release the BOOT. A removable disk appears on the computer.
- Copy the rp2-pico-20230209-unstable-v1.19.1.uf2 file in the Python directory to the recognized movable disk(RPI-RP2).
- Open Thonny IDE. (Note: please use the latest version of Thonny, otherwise there is no Pico supporting package. Currently, the newest version in Windows is v3.3.3.)
- Click Tool -> Setting -> Explainer. select the Pico and the corresponding port as shown below:
- File -> Open -> RP2040-ETH-Demo.py, click to run, the effect is shown below.
This demo provides only a simple test program.
Host Debugging
- If you want to control the host configuration rather than the serial commands, you can refer to the following method, and this method is only for Windows systems.
- Download Network debugging tool.
- Power on RP2040-ETH and the Ethernet.
- Open the network and tool.
- Search the device -> double click the searched device -> set the information you require -> Configure the device parameters -> wait for rebooting.
- Follows steps 1 and 2 in the above figure, and configure the parameters in the red block. Please wait for 4 after step 3.
Sample Demo
C/C++ Demo
1. Network Configuration
- The code for configuring the operating mode, IP, gateway, subnet mask, port number, and serial port baud rate is in the CH9120.c or CH9120.cpp file. You can modify it according to your specific requirements.
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
- The various operating modes are already defined in the header file, so you can directly modify and use CH9120_Mode.
#define TCP_SERVER 0 #define TCP_CLIENT 1 #define UDP_SERVER 2 #define UDP_CLIENT 3
2. Hardware Interface
- Enter configure mode:
void CH9120_Start();
- Exit:
void CH9120_End();
- Configure working mode:
void CH9120_SetMode(UCHAR Mode);
- Configure local IP:
void CH9120_SetLocalIP(UCHAR CH9120_LOCAL_IP[]);
- Configure subnet mask:
void CH9120_SetSubnetMask(UCHAR CH9120_SUBNET_MASK[]);
- Configure gateway:
void CH9120_SetGateway(UCHAR CH9120_GATEWAY[]);
- Configure target IP:
void CH9120_SetTargetIP(UCHAR CH9120_TARGET_IP[]);
- Configure local port number:
void CH9120_SetLocalPort(UWORD CH9120_PORT);
- Configure target port number:
void CH9120_SetTargetPort(UWORD CH9120_TARGET_PORT);
- Configure baud rate:
void CH9120_SetBaudRate(UDOUBLE CH9120_BAUD_RATE);
3. Demo Expalnation
The main demo code is shown below:
int Pico_ETH_CH9120_test(void) { CH9120_init(); //Initialize Configuration CH9120 RX_TX(); //receive and dispatch }
- CH9120_init();
Invoking various hardware interfaces to initialize and configure the CH9120. - RX_TX();
After initializing the CH9120, call RX_TX() to enter the data transmission mode, the CH9120 will resend the received message back (limited to ASCII code strings) automatically.
4. Running Effect
- Open the network debugging tool, configure the TCP server, and wait for RP2040-ETH to initiate the connection. Please observe the prompt in the lower right corner to check if the connection is successful.
- Data transmission test:
MicroPython Demo
01-TCP/UDP
1. Network Configuration
The code for configuring the operating mode, IP, gateway, subnet mask, port number, and serial port baud rate is located in the Python/RP2040-ETH-Demo/RP2040-ETH-Demo.py file. You can modify it according to your specific requirements.
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 for CH9120 are all in the Python/RP2040-ETH-Demo/ch9120.py file. The demos import the CH9120 class and then utilize the CH9120 object to call the functions.
- Create a new object:
ch9120 = CH9120(uart1)
- Enter configure mode:
ch9120.enter_config()
- Exit:
ch9120.exit_config()
- Configure working mode:
ch9120.set_mode(MODE)
- Configure local IP:
ch9120.set_localIP(LOCAL_IP)
- Configure subnet mask:
ch9120.set_subnetMask(SUBNET_MASK)
- Configure gateway:
ch9120.set_gateway(GATEWAY)
- Configure local port number:
ch9120.set_localPort(LOCAL_PORT1)
- Configure target IP:
ch9120.set_targetIP(TARGET_IP)
- Configure target port number:
ch9120.set_targetPort(TARGET_PORT)
- Configure baud rate:
ch9120.set_baudRate(BAUD_RATE)
3. Demo Explanation
The main demo code is shown below:
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'))
- ch9120_configure()
Invoking various hardware interfaces to initialize and configure the CH9120. - After initializing the CH9120, enter the data transmission mode, the CH9120 will resend the received message back (limited to ASCII code strings).
4. Running Effect
- Program the micropython firmware, upload ch9120.py, run the demo.
- Open the network debugging tool, configure the TCP server, and wait for RP2040-ETH to initiate the connection. Please observe the prompt in the lower right corner to check if the connection is successful.
- Data transmission test:
02-MQTT
1. Network Setting
The configuration code for MQTT communication based on the TCP/IP protocol and for CH9120 is located in the Python/RP2040-ETH-Demo/RP2040-ETH-MQTT.py file.
# MQTT CLIENT_ID = "Waveshare_RP2040_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
The following are the related variables of MQTT, you can modify them according to your needs.
CLIENT_ID: client ID SUBSCRIBE_TOPIC: subscribe topic name PUBLISH_TOPIC: the topic to be published TARGET_IP: MQTT server IP TARGET_PORT: MQTT server communication port
2. Interface Function
- Create MQTT client object:
mqtt_client = MQTTClient(uart1)
- Initiate to connect:
mqtt_client.connect()
- Subscribe to the topic:
mqtt_client.subscribe(SUBSCRIBE_TOPIC)
- Publish the message:
mqtt_client.publish(PUBLISH_TOPIC, message)
- Send a heartbeat packet:
mqtt_client.send_heartbeat()
- Check heartbeat response
mqtt_client.check_heartbeat_response()
- Extract data:
mqtt_client.extract_data(rxData)
3. Demo Explanation
The main demo code is shown below:
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 segment first configures the CH9120 and then establishes a connection to the MQTT server's communication port and subscribed to a specific topic by sending byte data.
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
- ch9120_configure()
Invoking various hardware interfaces to initialize and configure the CH9120. - mqtt_client = MQTTClient(uart1)
Create the MQTT client object "mqtt_client" - mqtt_client.ClientID = CLIENT_ID
Configure the client ID - mqtt_client.connect()
Initiate a connection request to the MQTT server - mqtt_client.subscribe(SUBSCRIBE_TOPIC)
Subscribe the topic
This code segment signifies entering data transmission mode, where the received messages 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)
- rxData = uart1.read()
Read the data - topic, message = mqtt_client.extract_data(rxData)
Parse the data, extract the topic and message from the data. - if topic == SUBSCRIBE_TOPIC
Prints the topic name and message if it is a subscribed topic. - mqtt_client.publish(PUBLISH_TOPIC, message)
Sends the received messages back from another topic.
After the connection is established, the client needs to make sure the intervals between sending two MQTT protocols will not exceed Keep Alive value. If the client currently is idle, and there is no packet to be sent, you can send PINGREQ protocol packet (heartbeat packet). If the MQTT server does not receive any packets from the client within 1.5 times the Keep Alive time, it will assume that there is a problem with the connection between the client and the MQTT server, and the server will disconnect from the client. Therefore, if the client does not send packets for a long time and wants to keep the connection, it needs to send heartbeat packets every once in a while, and it is usually recommended to send them once in half of the Keep Alive time. The following code means to send a heartbeat packet to the server every 30 seconds, if the heartbeat check fails, it will reconnect until the heartbeat check succeeds and exit:
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
- mqtt_client.send_heartbeat()
Send a heartbeat packet to the MQTT server, it is usually recommended to send it once within half of the Keep Alive time, in the program Keep Alive is set to 60 seconds, so it is sent once every 30 seconds. - mqtt_client.check_heartbeat_response()
Check the heartbeat response returned by the MQTT server, if the returned data is normal, then exit the loop, if not, then continue to try to reconnect.
4. Running Effect
- Program the micropython firmware, and upload ch9120.py and mqtt_client.py, run the demo.
- Open the MQTT client test tool, and configure the MQTT client. After configuring, click on "Connect" in the top right corner.
- Subscribe to the topic.
- The data transmission test, sends the message to test_topic1, and the RP2040-ETH receives and sends back a message via the test_topic2 topic.
Pico Quick Start
Firmware Download
Text Tutorial
Introduction
MicroPython Series
- 【MicroPython】 machine.Pin Function
- 【MicroPython】 machine.PWM Function
- 【MicroPython】 machine.ADC Function
- 【MicroPython】 machine.UART Function
- 【MicroPython】 machine.I2C Function
- 【MicroPython】 machine.SPI Function
- 【MicroPython】 rp2.StateMachine
C/C++ Series
For C/C++, it is recommended to use Pico VS Code 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 board. Whether you are a beginner or an experienced professional, this tool can help you confidently and easily develop Pico. Below we will introduce how to install and use the extension.
- Official website tutorial: https://www.raspberrypi.com/news/pico-vscode-extension/.
- This tutorial is applicable to Raspberry Pi Pico, Pico2, and our company's RP2040 and RP2350 series development boards.
- The development environment defaults to Windows as an example. For other environments, please refer to the official website tutorial for installation.
Arduino IDE Series
Install Arduino IDE
-
Download the Arduino IDE installation package from Arduino website.
-
Just click on "JUST DOWNLOAD".
-
Click to install after downloading.
-
Note: You will be prompted to install the driver during the installation process, we can click Install.
Install Arduino-Pico Core on Arduino IDE
-
Open Arduino IDE, click the File on the left corner and choose "Preferences".
-
Add the following link in "Additional boards manager URLs", then click OK.
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
Note: If you already have the ESP32 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
-
Click on Tools -> Board -> Board Manager -> Search for pico, it shows installed since my computer has already installed it.
Upload Demo At the First Time
-
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).
- Download the demo from #Resource, open the D1-LED.ino under arduino\PWM\D1-LED path.
-
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).
-
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.
-
Click Tools -> Board -> Raspberry Pi Pico/RP2040 -> Raspberry Pi Pico.
-
After setting, click the right arrow to upload.
- If you encounter problems during the period, you need to reinstall or replace the Arduino IDE version, uninstall the Arduino IDE clean, 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
- MicroPython Demo (GitHub)
- MicroPython Firmware/Blink Demo (C)
- Official Raspberry Pi C/C++ Demo
- Official Raspberry Pi MicroPython Demo
- Arduino Official C/C++ Demo
Resource
Document
Demo
Tool
Raspberry Pi
- Raspberry Pi Pico Get Started with MicroPython on Raspberry Pi Pico
- Raspberry PI related books download
- Official website of Pico
- Getting started with Pico
- Pico C SDK
- Raspberry Pi Pico Schematic
- Pico Python SDK
- Pico Pinout
- Pico Datasheet
- RP2040 Datasheet
- RP2040 Hardware design
Examples
Software
FAQ
The default serial baud rate of the board is 9600, which may cause the delay issue. Please change it to the maximum baud rate and test again.
{{{5}}}
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 PM GMT+8 (Monday to Friday)