Cornell University ECE4760
UDP from Picow to laptop

Pi Pico RP2040

 

UDP on RP2040 PicoW
The Picow has a WIFI module that can be used to connect to the internet, using the LWIP package running on the rp2040. This project uses the UDP protocol to send/receive data from a picow to a laptop on the same subnet. The laptop initiates a transaction by sending an integer representing the blink time in mSec to set the on-board LED rate. The picow then echos the value back to the laptop.

UDP send/recv code is slightly modified to run in Protothreads and is from :
-- Pico examples https://github.com/raspberrypi/pico-examples/tree/master/pico_w/wifi/udp_beacon
-- lwip contrib apps: https://github.com/lwip-tcpip/lwip/tree/master/contrib/apps

A very simple packet logger was running on the laptop. Code from Microsoft :
https://apps.microsoft.com/store/detail/udp-senderreciever/9NBLGGH52BT0?hl=en-us&gl=us

The structure of the program is built around Protothreads, with a thread to send a packet, a thread to process a received packet, but note that the actual low level packet receive is performed by an ISR required by LWIP. The ISR signals a semaphore to run the receive thread. The receive thread decodes one integer sent from the labtop, then signals a semaphore to run the send thread, to echo the value. There is also a thread to blink the on-board LED based on the integer-time sent from the laptop.

In the following screen capture of the picow serial channel there are several status messages sent by lwip, then the DHCP assigned IP address which is enered into the packet logger to tell the laptop where to send data.

The Microsoft packet logger running on the laptop. Green values are sent from the laptop,
red values are echoed by the picow.

 

Code, project ZIP
Note that the code has defines for WIFI SSID and password that must be specified for your system.


 


Copyright Cornell University July 2, 2023