Ethernet library issue with raspberry pi pico

Hi all,

This is my first post on the Arduino forums :).
I am currently trying to create a controller for my garage door which communicates with my home assistant server via mqtt using a W5500 Ethernet board. In my sketch I use the following libraries:

  #include <Ethernet.h>
  #include <PubSubClient.h>
  #include <ArduinoJson.h>

I tried to do this with an arduino Nano but soon ran into memory issues due to having to send a huge JSON configuration char array (460 bytes). I tried optimizing memory usage, but got tired always operating at the edge of having no more memory available.

I had a Raspberry Pi Pico lying around and thought maybe I could use it instead, sure enough it has quite a lot more RAM compared to the NANO.
I got the Pico to connect to the Arduino IDE and can upload sketches just fine. When trying to compile my garage door sketch though, I get the following compilation error, which occurs in the Ethernet or PubSubClient library (not really sure which one):

In file included from C:\Users\miche\OneDrive\Dokumente\ArduinoData\packages\arduino\hardware\mbed_rp2040\2.1.0\cores\arduino/mbed/connectivity/lwipstack/lwip-sys/arch/cc.h:38:0,
                 from C:\Users\miche\OneDrive\Dokumente\ArduinoData\packages\arduino\hardware\mbed_rp2040\2.1.0\cores\arduino/mbed/connectivity/lwipstack/lwip/src/include/lwip/arch.h:48,
                 from C:\Users\miche\OneDrive\Dokumente\ArduinoData\packages\arduino\hardware\mbed_rp2040\2.1.0\cores\arduino/mbed/connectivity/lwipstack/lwip/src/include/lwip/prot/Ethernet.h:40,
                 from C:\Users\miche\Arduino\sketch_GaragentorSteuerung\sketch_GaragentorSteuerung.ino:9:
C:\Users\miche\OneDrive\Dokumente\ArduinoData\packages\arduino\hardware\mbed_rp2040\2.1.0\cores\arduino/mbed/connectivity/lwipstack/include/lwipstack/lwipopts.h:34:2: error: #error "Either IPv4 or IPv6 must be enabled."
 #error "Either IPv4 or IPv6 must be enabled."
C:\Users\miche\OneDrive\Dokumente\ArduinoData\packages\arduino\hardware\mbed_rp2040\2.1.0\cores\arduino/mbed/connectivity/lwipstack/include/lwipstack/lwipopts.h:71:2: error: #error "Either IPv4 or IPv6 must be preferred."
 #error "Either IPv4 or IPv6 must be preferred."
exit status 1
Error compiling for board Raspberry Pi Pico.

Any idea what is going on here? I am no C++ expert so I cannot really tell which library might cause the issue in the first place.

Any help on this would be greatly appreciated.

Hi @darkwarden. The problem is that the "Arduino Mbed OS RP2040 Boards" platform contains a file named ethernet.h, which is completely different from the Ethernet.h of the Arduino Ethernet library. On a case insensitive file system like Windows, ethernet.h and Ethernet.h are the same, so it picks the wrong file.

We can give the IDE a little bit of help to pick the right file by adding an #include directive for a filename that only occurs in the Ethernet library before the ambiguous #include directive for Ethernet.h. The file EthernetClient.h will work perfectly for that purpose.

Please change this line of your sketch:

#include <Ethernet.h>


#include <EthernetClient.h>
#include <Ethernet.h>

then try compiling again.


@pert Thank you very much. Everything works now as expected :).

You're welcome. I'm glad to hear it's working now. Enjoy!