Cornell University ECE4760
UDP data array from Picow to Picow
Pi Pico RP2040
UDP array-send 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 between two picoW's on the same subnet. A serial connection from one pico to a laptop is used for control and debugging. Since IP addresses are assigned via DHCP, a simple discovery scheme allows the two pico's to find each other. A transaction consists of one pico (the sender) sending an integer array to the other pico (the receiver). The receiving picow then acks back to the sender. The sender then prints the elapsed time from send-request to ack-return.
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
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 is a short as possible and just copies the receive buffer, then signals a semaphore to run the receive thread. The receive thread decodes the array or a commend sent from the from the other pico, then signals a semaphore to run the send thread, to ack the array or return an IP address. There is also a thread to blink the on-board receiver LED based on the pairing state of the two picow's.
Initially, both pico's boot up in passive receive state and wait for a packet. A serial connection can be used to switch one of the pico's to send mode. The send-unit can then send a data packet, an ack packet, or self-identify with its IP address. An IP identification packet containing a pair command will modify the blink rate of the other pico. A packet with IP command will cause the recv pico to record a new transmit address and then send it's address back to the initiating pico. At that point each pico knows the address of the other and both stop using the debug broadcast address. If both picow's have serial connections set up, then either one can be set to be the sender. The same code is running on both picow.
Serial commands are:
The packet perfromance depended on the efficiency of the protothreads setting up the transfer. It is important to yield the thread that signals the send_semaphore. By yielding the signalling thread, after signaling the send-semaphore, and optimizing the order of send/receive threads in the round-robin scheduler, the send speed is about 1 Mbyte/sec for packets of 1024 bytes. This is about what I would expect based on the iPerf rates of 5 to 8 Mbits/sec, using the example picow iPerf server and a desktop iPerf client. Including all overhead, the round trip time (data-send to return-ack) is 3.6 to 3.9 mSec, or about .25 Mbytes/sec. A short ack packet round trip time is about 2.8 mSec.
Code, Project ZIP
Note that the code has defines for WIFI SSID and password that must be specified for your system.
Copyright Cornell University August 15, 2023