How to add Ethernet to Raspberry Pi Pico

Raspberry Pi Pico has a lot of interesting and unique features, but it doesn’t have networking. Of course this was only ever going to be a temporary inconvenience, and sure enough, over Pi Day weekend we saw both USB Ethernet and Ethernet PHY support released for Pico and RP2040.

Raspberry Pi Pico and RMII Ethernet PHY
Raspberry Pi Pico and RMII Ethernet PHY

The PHY support was put together by Sandeep Mistry, well known as the author of the noble and bleno Node.js libraries, as well as the Arduino LoRa library, amongst others. Built around the lwIP stack, it leverages the PIO, DMA, and dual-core capabilities of RP2040 to create an Ethernet MAC stack in software. The project currently supports RMII-based Ethernet PHY modules like the Microchip LAN8720.

Breakout boards for the LAN8720 can be found on AliExpress for around $1.50. If you want to pick one up next day on Amazon you should be prepared to pay somewhat more, especially if you want Amazon Prime delivery, although they can still be found fairly cheaply if you’re prepared to wait a while.

What this means is that you can now connect your $4 microcontroller to an Ethernet breakout costing less than $2 and connect it to the internet.

Building from source

If you don’t already have the Raspberry Pi Pico toolchain set up and working, you should first set up the C/C++ SDK. Afterwards you need grab the the project from GitHub, along with the lwIP stack.

[[code]]czozNjM6XCI8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS1jb2xvciBoYXMtdml2aWQtZ3JlZW4tY3lhbi1jb2xvclwiPiQ8L3tbJiomXX1zcGFuPjwvc3Ryb25nPiBnaXQgY2xvbmUgZ2l0QGdpdGh1Yi5jb206c2FuZGVlcG1pc3RyeS9waWNvLXJtaWktZXRoZXJuZXQuZ2l0e1smKiZdfQo8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS1jb2xvciBoYXMtdml2aWQtZ3JlZW4tY3lhbi1jb2xvclwiPiQ8L3NwYW4+PHtbJiomXX0vc3Ryb25nPiBjZCBwaWNvLXJtaWktZXRoZXJuZXQKPHN0cm9uZz48c3BhbiBjbGFzcz1cImhhcy1pbmxpbmUtY29sb3IgaGFzLXZpdntbJiomXX1pZC1ncmVlbi1jeWFuLWNvbG9yXCI+JDwvc3Bhbj48L3N0cm9uZz4gZ2l0IHN1Ym1vZHVsZSB1cGRhdGUgLS1pbml0XCI7e1smKiZdfQ==[[/code]]

Make sure you have your PICO_SDK_PATH set before before proceeding. For instance, if you’re building things on a Raspberry Pi and you’ve run the pico_setup.sh script, or followed the instructions in our Getting Started guide, you’d point the PICO_SDK_PATH to

[[code]]czoxMjk6XCI8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS1jb2xvciBoYXMtdml2aWQtZ3JlZW4tY3lhbi1jb2xvclwiPiQ8L3tbJiomXX1zcGFuPjwvc3Ryb25nPiBleHBvcnQgUElDT19TREtfUEFUSCA9IC9ob21lL3BpL3BpY28vcGljby1zZGtcIjt7WyYqJl19[[/code]]

then after that you can go ahead and build both the library and the example application.

[[code]]czozNzA6XCI8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS1jb2xvciBoYXMtdml2aWQtZ3JlZW4tY3lhbi1jb2xvclwiPiQ8L3tbJiomXX1zcGFuPjwvc3Ryb25nPiBta2RpciBidWlsZAo8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS1jb2xvciBoYXMtdml2aWQtZ3tbJiomXX1yZWVuLWN5YW4tY29sb3JcIj4kPC9zcGFuPjwvc3Ryb25nPiBjZCBidWlsZAo8c3Ryb25nPjxzcGFuIGNsYXNzPVwiaGFzLWlubGluZS17WyYqJl19Y29sb3IgaGFzLXZpdmlkLWdyZWVuLWN5YW4tY29sb3JcIj4kPC9zcGFuPjwvc3Ryb25nPiBjbWFrZSAuLgo8c3Ryb25nPjxzcGFuIGN7WyYqJl19bGFzcz1cImhhcy1pbmxpbmUtY29sb3IgaGFzLXZpdmlkLWdyZWVuLWN5YW4tY29sb3JcIj4kPC9zcGFuPjwvc3Ryb25nPiBtYWtlXCI7e1smKiZdfQ==[[/code]]

If everything goes well you should have a UF2 file in build/examples/httpd called pico_rmii_ethernet_httpd.uf2. You can now load this UF2 file onto your Pico in the normal way.

Go grab your Raspberry Pi Pico board and a micro USB cable. Plug the cable into your Raspberry Pi or laptop, then press and hold the BOOTSEL button on your Pico while you plug the other end of the micro USB cable into the board. Then release the button after the board is plugged in.

A disk volume called RPI-RP2 should pop up on your desktop. Double-click to open it, and then drag and drop the UF2 file into it. Your Pico is now running a webserver. Unfortunately it’s not going to be much use until we wire it up to our Ethernet breakout board.

Wiring things up on the breadboard

Unfortunately the most common (and cheapest) breakout for the LAN8720 isn’t breadboard-friendly, although you can find some boards that are, so you’ll probably need to grab a bunch of male-to-female jumper wires along with your breadboard.

LAN8720 breakout wired to a Raspberry Pi Pico on a breadboard.
LAN8720 breakout wired to a Raspberry Pi Pico on a breadboard (with reset button)

Then wire up the breakout board to your Raspberry Pi Pico. Most of these boards seem to be well labelled, with the left-hand labels corresponding to the top row of breakout pins. The mapping between the pins on the RMII-based LAN8720 breakout board and your Pico should be as follows:

Pico RP20401 LAN8720 Breakout
Pin 9 GP6 RX0
Pin 10 GP7 RX1 (RX0 + 1 )
Pin 11 GP8 CRS (RX0 + 2)
Pin 14 GP10 TX0
Pin 15 GP11 TX1 (TX0 + 1)
Pin 16 GP12 TX-EN (TX0 + 2)
Pin 19 GP14 MDIO
Pin 20 GP15 MDC
Pin 26 GP20 nINT / RETCLK
3V3 (OUT) VCC
Pin 38 GND GND
Mapping between physical pin number, RP2040 pin, and LAN8720 breakout