I purchased a couple of Arduino Mega (must be 1280), and Ethernet shields from Amazon awhile ago, then due to a change in employment status had to set them aside. Now that I am getting back to them, I am struggling with the Ethernet shields, and questioning the library support for these boards.
I don't recall knowing there were different Ethernet shields at the time I bought them, and the only markings I can find on these say TinkerIT. They do have a W5100 chip, and a layout very close to the v3, though these don't have the SD carrier populated. I have tried a variety of example sketches, as well as trying from scratch but they all fail. That said, the boards do appear to work on the Ethernet side as all the leds flash appropriately (though I never see a DHCP attempt on the TX led), if they could only be configured correctly.
It doesn't matter if I try a DHCP, or a static assignment, addresses don't take. When I ping the subnet broadcast wireshark shows a response from 0.0.0.0 with mac 0:0:0:0:0:0, but only when the Arduino is connected. Then a series of ICMP dst/port unreachable messages from 0.0.0.0, that coorespond to the TX led flashing, in response to port 137/138 traffic from the W7 machine running wireshark. There is also a TX flash every 30 sec, what would appear to be a response to the RIP update sent to subnet broadcast, though that is not getting through the switch to wireshark. This 0.0.0.0 address is consistent with the output from: Serial.println(Ethernet.localIP()), so it would appear that the address being passed through begin(), or acquired from DHCP are not getting to the chip. There are unsubstantiated claims that the DHCP timeout in 1.0+ is 1 minute, but as far as I can tell in 1.0.3, it is longer than 30 minutes to drop out and print the 0.0.0.0 address.
Since I can't get a static address assigned, and the board responds for the address it has, the next logical place to start looking is the library support. The first annoying thing I stumbled across is Ethernet.h where any parameter passed beyond (mac) causes a status = Ethernet.begin(...) to fail. Why are those parameter options declared with void rather than int so a proper status is returned, even if most people will ignore it? The next was the decision to insert dns before gtw/mask. There are lots of example sketches showing (mac, ip, gtw, subnet), which are all invalid after 1.0 as far as I can tell. On top of that there is the confusing practice of stating a current string as (mac, ip, gtw, gtw, subnet). While I understand that is a handy short-hand for people too lazy to type out IPAddress dns_srv(,,,), it makes it look like a typo when compared to the older examples with only one gtw entry. 3rd is the fact that if you try to just use IPAddress dns(,,,) it fails compiling due to an attempted reasignment of the array. 4th, why do all DHCP examples try once and fail, rather than retry after a reasonable period? (see below) 5th, I understand why the IDE closes the serial monitor during an upload, but why doesn't it remember that it did that and reopen it after the upload completes? but I digress, so back to the problem at hand...
Is there any code to get full status from the W5100, or perform diagnostics? Search turns up nothing but other people looking for the same. I have been searching for all kinds of errors related to these boards, and/or assignments resulting in 0.0.0.0, with absolutely no luck. Is there some incompatibility between the Mega and this shield? Do I need to do something with ../hardware/arduino/variants/mega/pins_arduino.h, or did declaring the board type to the IDE take care of that? Anyone have a suggestion of what to try next?
Here is the currently loaded sketch:
IDE 1.0.3 on W7
Arduino Mega (1280) w/ tinkerit ethernet shield both acquired Mar 2010.
// pasted together from several sketches + edits & insertions
#include <SPI.h>
#include <Ethernet.h>
boolean status = false;
byte mac[] = { 0x02, 0xAA, 0xBB, 0xCC, 0xDD, 0x02 };
IPAddress ip(192,168,123,24);
EthernetClient client;
void setup() {
// turn off SD select, despite lack of socket on this board
// ambiguous claims all over the place about needing to do this to make 5100 work
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
}
Serial.println("start the Ethernet connection:");
// status = Ethernet.begin(mac, ip); // this fails because ethernet.h has void for parameters beyond (mac)
// Serial.println(status); // this makes no sense when the above fails
Ethernet.begin(mac, ip); // could do more, but this should be enough for on-subnet ping
/* comment out above and uncomment below for DHCP
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP"); // never prints this
// keep trying at 1 minute intervals until it works
while (!Ethernet.begin(mac)) {
delay( 60000 + random(0,100) );
Serial.println("Failed DHCP Retrying");
}
}
*/
delay(2000); // let things settle before moving on...
// print the local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 3; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.print(Ethernet.localIP()[3], DEC);
Serial.println();
}
void loop() {
// no point in putting anything here until a valid address gets assigned
}
Serial Monitor output:
start the Ethernet connection:
My IP address: 0.0.0.0