Pages: [1]   Go Down
Author Topic: autodetect ethernet shield  (Read 1917 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://arduino.cc/en/Reference/EthernetBegin

Quote
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...
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5874
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are going to all that trouble, then assign a static ip and read it. Something like this:
Code:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://arduino.cc/en/Reference/EthernetBegin

Must be new in 1.0...

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Pages: [1]   Go Up
Jump to: