RP2040-ETH

From Waveshare Wiki
Jump to: navigation, search
RP2040-ETH
RP2040-ETH.jpg

RP2040
Type-C, ETH
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

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.
  • 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
  • Temperature sensor.
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support.

Pinout Definition

RP2040-ETH02.jpg

RP2040-ETH User Manual

Environment Building

*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.

Pico-R3-Tonny1.png

  • 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.

Raspberry Pi Pico002.png
Raspberry-Pi-Pico-Basic-Kit-M-3.png

  • 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: Press and hold the BOOT button and connect to the computer, release the BOOT button, and 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".

Hardware Connection

  • The internal connection between CH9120 and RP2040 as shown below:
RP2040 connection pins correspondence
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/8/88/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 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 MicroPico -> Interpreter to select MicroPython (Raspberry Pi Pico and ttyACM0 port).

As shown below:
Pico-lcd-0.96-img-config2.png
If your current Thonny version has no Pico support package, you can enter the following commands to update Thonny IDE.

sudo apt upgrade thonny

3. 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.

RP2040-ETH010.jpg

  • Choose the Compiler.

1.28inch Touch LCD pico2.jpg

  • Start to compile.

1.28inch Touch LCD pico3.jpg

  • Finish.

1.28inch Touch LCD pico4.jpg

  • Copy the main.uf2 file in build to Pico, and then it can automatically run the demo.

1.28inch Touch LCD pico5.jpg

Python

  1. Press the BOOTSET button on the Pico and connect the Pico to the USB port of the computer with a Micro USB cable. Release the button when the computer identifies a movable disk (RPI-RP2).
  2. Copy the rp2-pico-20230209-unstable-v1.19.1.uf2 file in the Python directory to the recognizable movable disk(RPI-RP2).
  3. 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.)
  4. Click Tool -> Setting -> Explainer. select the Pico and the corresponding port as shown below:
    Pico-lcd-0.96-img-config.png
  5. File -> Open -> RP2040-ETH-Demo.py, click to run, the effect is shown below.
    1.28inch Touch LCD pico7.jpg

We provide a simple demo for you...

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 configuration tool.
  1. Power on RP2040-ETH and the Ethernet.
  2. Open the network debugging tool.
  3. Search the device -> double click the searched device -> set the information you require -> Configure the device parameters -> wait for rebooting.

RP2040-ETH 30.jpg

  • 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, use 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.
    RP2040-ETH-Demo-show1.png
  • Data transmission mode:
    RP2040-ETH-Demo-show2.png

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.
    RP2040-ETH-Python-Demo-config.jpg
  • 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.
    RP2040-ETH-Demo-show1.png
  • Data transmission test:
    RP2040-ETH-Demo-show2.png

02-MQTT

1. Network Setting
The code for configuring 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)
  • 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 to subscribe 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 the connection with 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 to 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)
    Extract the topic and message 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

4. Running Effect

  • Program the micropython firmware, and upload ch9120.py and mqtt_client.py, run the demo.
    RP2040-ETH-Python-MQTT-config.jpg
  • Open the MQTT client test tool, and configure the MQTT client. After configuring, click on "Connect" in the top right corner.
    RP2040-ETH-MQTT-show1.jpg
  • Subscribe to the topic.
    RP2040-ETH-MQTT-show2.jpg
  • 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.
    RP2040-ETH-MQTT-show3.jpg

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

Resource

Document

Demo

Tool

Raspberry Pi

Examples

Software

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)