Template: Pico-ETH-CH9121 Guide
From Waveshare Wiki
Configuration
TCP Client
- Connect the Pico-ETH-CH9121 (ETH module hereafter) to the router, and use the host PC as a TCP server. The PC should be connected to the same LAN as the ETH module
- Use the SSCOM software, set the port to TCP server and you can check the local IP (the Target IP) and the port (Target port)
- Run the NetModuleConfig.exe software on your PC
- Click the Search button to detect device
- Double-Click the device detected, then you can modify the network parameters in the left area
- After configuration, the ETH module will auto-restart, wait for a moment, search the device again and check the setting.
- Note that you need to modify the parameters according to the actual situation. The Mode should be TCP CLIENT, target IP and port is same as the TCP server.
- After setting, you can listen to the data by the SSCOM software
TCP SERVER
- Connect the Pico-ETH-CH9121 (ETH module hereafter) to the router, and use the host PC as a TCP CLIENT.
- Run the NetModuleConfig.exe software on your PC
- Click the Search button to detect the ETH module
- Double-click the device detected
- Set the mode to TCP SERVER and modify other parameters according to the actual situation.
- Click the Set ALL button to save the setting
- User the SSCOM software, configure as TCP CLIENT, and connect to the SERVER(The ETH module)
UDP CLIENT/SERVER
The UDP modes are the same as the TCP, the only difference is the mode is UDP CLIENT/SERVER but not the TCP CLIENT/SERVER.
Using with Pico
Hardware connection
ETH | Pico | Description |
---|---|---|
5V | VSYS | Power input |
GND | GND | Ground |
RXD1 | GP0 | UART 1 data input |
TXD1 | GP1 | UART 1 data output |
RXD2 | GP4 | UART 2 data input |
TXD2 | GP5 | UART 2 data output |
CFG0 | GP14 | Network configrate enable pin |
RST1 | GP17 | Reset pin |
=Configurate Environment
To use the Pico, you need to configure your PC or the Raspberry Pi first.
Please refer to the official guide about the setting Pico Manual
Examples
We use Raspberry Pi board as examples
Download examples
Open the terminal and run the following commands:
sudo apt-get install p7zip-full cd ~ sudo wget https://www.waveshare.com/w/upload/a/a4/Pico_ETH_CH9121_CODE.7z 7z x Pico_ETH_CH9121_CODE.7z -o./Pico_ETH_CH9121_CODE cd ~/Pico_ETH_CH9121_CODE cd Pico/c/build/
C examples
- Go intot the c directory
cd ~/Pico_ETH_CH9121_CODE/Pico/C/
- You can use the Pico_ETH_CH9121_CODE/Pico/C/Serial Port Parameter Configuration: configura module
- Pico_ETH_CH9121_CODE/Pico/C/RX_TX: Echo examples, receive data and echo
- Go into examples directory and export sdk
cd build export PICO_SDK_PATH=../../pico-sdk
- You need to modify the path to the actual one if you use directly path
- Generate the Makefile file
cmake ..
- Build the examples
make -j9
- After building, copy the .uf2 file to the Pico
- Press the BOOTSEL button of Pico and hold it, connect the pico to your Pi by micro USB cable and then release the button. The portable disk RPI-RP2 is recognized, you need to copy the uf2 file to the portable disk.
cp main.uf2 /media/pi/RPI-RP2/
=Python examples
- Press and hold the BOOTSEL button of pico, connect it to Raspberry Pi or PC by micro USB cable, and then release the button
- The Pico is recognized as portable disk RPI-RP2, copy the rp2-pico-20210418-v1.15.uf2 file to the portable disk
- Open the Thonny IDE
- Choose Tools -> Options .. -> Interpreter
- Choose MicroPython(Raspberry Pi Pico) and the related port.
- If your Thonny IDE doesn't support Pico, you need to update it to the newest version
sudo apt upgrade thonny
- Click File -> Open... -> python/RX_TX.py to run the codes.
Codes Description
- C codes
- Data types:
#define UCHAR unsigned char #define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
- Initailize module:
void CH9121_init(void);
- Parameters for configuring modules
UCHAR CH9121_Mode //Mode UCHAR CH9121_LOCAL_IP[4] //Device IP UCHAR CH9121_GATEWAY[4] //Gateway UCHAR CH9121_SUBNET_MASK[4] //Subnet mask UCHAR CH9121_TARGET_IP[4] //Target IP UWORD CH9121_PORT1 //Device port UWORD CH9121_TARGET_PORT //Target port UDOUBLE CH9121_BAUD_RATE //baud rate of serial
- You can configure the module by the following functions with serial commands
void CH9121_TX_4_bytes(UCHAR data, int command); //Can be used to configure the mode, random port, disconnect network, clear buffer, DHCP, UART2 void CH9121_TX_5_bytes(UWORD data, int command);//Can be used to set the port of Serial void CH9121_TX_7_bytes(UCHAR data[], int command);//Can be used to set IP, subnet mask, gateway. void CH9121_TX_BAUD(UDOUBLE data, int command);//Can be used to set the baud rate of Serial. void CH9121_Eed(); // Can be used to save setting to EEPROM, enable the setting, reset module, exit from setting mode
- Python
You just need to modify the Serial Port Parameter Configuration.py for setting the module
ODE = 1 #0:TCP Server 1:TCP Client 2:UDP Server 3:UDP Client GATEWAY = (169, 254, 88, 1) # GATEWAY TARGET_IP = (169, 254, 88, 17)# TARGET_IP LOCAL_IP = (169,254,88,70) # LOCAL_IP SUBNET_MASK = (255,255,255,0) # SUBNET_MASK LOCAL_PORT1 = 5000 # LOCAL_PORT1 LOCAL_PORT2 = 4000 # LOCAL_PORT2 TARGET_PORT = 3000 # TARGET_PORT BAUD_RATE = 115200 # BAUD_RATE