for 5500 I need to
Why is that? Are you aware that the latest 2.0.0 release of the official Ethernet library supports W5100, W5200, and W5500, with automatic detection of which chip is in use? The only valid reason for still using the outdated Ethernet2 library is that the new Ethernet library does use more memory. But there are other significant improvements that make the new Ethernet library much superior to Ethernet2.
#include <ICMPPing.h> //version for 5500 (same name!)
If there really is a different ICMPPing library for W5100 vs W5500 then that will not be possible to select automatically. As adwsystems mentioned, it is possible to determine which chip is used at run time. In fact there is a function in the new Ethernet library that makes this super easy:
But you can not control #include directives based on run time data. It must be known at compile time and there is no way to automatically detect which Ethernet controller chip is being used at compile time.
You can do something like this:
#define USING_W5100 //comment this line when W5500 is in use
but you will need to manually comment/uncomment that first line according to which Ethernet controller you’re using. You’ll notice the #include directives for ICMPPing-W5100.h vs. ICMPPing-W5500.h. If you have two libraries that have the same file name, for example:
Then which one the Arduino IDE decides for #include <ICMPPing.h> to use is somewhat random, and can’t be controlled well.
But the Arduino IDE will give preference to the library that contains a file which has been used in a previous #include directive. So if you add a dummy empty .h file to each library:
and then add an #include directive for the dummy filename before the ambiguous filename, then you can control which of the libraries will be used.
A better solution would be for the ICMPPing library to be written so that it’s compatible with both Ethernet controller chips, but I’m not sure how difficult that would be or whether it would introduce overhead.