autodetect ethernet shield

I'm building a sous-vide shield, and I would like to support both ethernet and serial. However I need to use 9 digital outputs, so I must choose either ethernet, or serial, but cannot support both simultaneously.

I'd like to add a multiplexor, such that if I detect an ethernet shield, I use pins 0 and 1 as digital outputs. If I don't detect a ethernet shield, I use pins 4 and 10 instead. I know I could do this with board jumpers, but why not just autodetect the shield.

Any ideas on how to autodetect an ethernet shield to control my mux?

Why don't you use the analog pins? They work as digital, too.

uh, wow that's a much better solution. I feel pretty dumb for assuming the analog pins were input only.
Thanks!

Ok, so I freed up pins 0 and 1, by moving pins to to A1 and A2.

However it turns out, I still need to autodetect the ethernet shield.

in my void setup(), if I call
networked = Ethernet.begin(mac);

it takes a long time for DHCP to give up, and the code moves on to the next line.
Is there a fast way to check for the shield?

kyngston:
in my void setup(), if I call
networked = Ethernet.begin(mac);

it takes a long time for DHCP to give up, and the code moves on to the next line.
Is there a fast way to check for the shield?

I don't think the Ethernet library supports DCHP...

fungus:
I don't think the Ethernet library supports DCHP...

I don't know how recent it is, but v1.0 now supports DHCP, and it works very well for me:

Returns
The DHCP version of this function, Ethernet.begin(mac), returns an int: 1 on a successful DHCP connection, 0 on failure. The other versions don't return anything.

Apparently it retries for 2 minutes before giving up...

If you are going to all that trouble, then assign a static ip and read it. Something like this:

IPAddress ip(192,168,0,2);

Ethernet.begin(mac, ip);

if(Ethernet.localIP() == ip) Serial.println("shield present");
else Serial.println("no shield");

If it returns 0.0.0.0, then there is no ethernet shield. That will be immediate. No waiting.

SurferTim:
If you are going to all that trouble, then assign a static ip and read it.

I could, but then if I plug multiple sous-vide cookers into my network, I'd have to customize the code for each arduino., and then I could collide with an IP that was already assigned by DHCP, etc, etc

Some background. I'm making an internet-of-things-sous-vide cooker. I have the arduino with a ethernet shield controlling a crock pot with the PID library generating PWM to control a solid-state relay. The arduino is running a mqtt client, communicating to an mqtt broker running on a raspberry pi. I have commands, status, and temperature data on separate channels, so I can remote control and query my arduino. I also have a node.js data logger, sending temperature logs to a file every 10s, so I can plot my PID controller performance.

I may try to do away with the rasperry pi, and write a web server on the arduino that tracks temperature logs. I could use the google charts api, to do all the graphics on the client side.

I want these things to be smart enough, so that I can fab a bunch of pcb for friends and family, they can plug them in and happily start cooking without requiring everybody to upload custom arduino code that is compatible with their network. For now I just gave up and added a jumper that will select ethernet or not.

kyngston:

fungus:
I don't think the Ethernet library supports DCHP...

I don't know how recent it is, but v1.0 now supports DHCP, and it works very well for me:
Ethernet - Arduino Reference

Must be new in 1.0...