I ran into some pitfalls here, which I wanted to share - maybe it will help others.
I am talking about this one from arduino.ORG
I bought it rather accidentally. I thought I was buying a previous version of
Arduino Ethernet shield Revision 3, which is from arduino.CC
The main difference is that the ORG version uses a newer chip, the W5500.
The CC version uses the W5100.
For differences between the 2 chips, see
The ethernet library in the .CC IDE 1.6.3 does not support the W5500.
The .ORG IDE includes an updated ethernet library, called ethernet2.
However .ORG does not provide a download link on their website, they want you to install the .ORG IDE
But this is not necessary, you can download the library here:
https://github.com/arduino-org/Arduino/tree/Ide-1.7.6-Tian
I downloaded the whole zip and copied the ethernet 2 library into my .CC IDE library folder.
This library
might also work, but I haven't tried it.
I connected the ethernet shield to an arduino mega with jumper leads (power and SPI bus), and at first had no luck at all.
-
It turns out the ethernet shield pins 11 - 13, which are the SPI bus on an arduino uno, are NOT CONNECTED on the ethernet shield. You have to use the 2x3pin ICSP header on the ethernet shield instead. On the Mega, it doesn't matter if you use the ICSP or pins 50 - 52 (SPI on the Mega)
-
Pin 10 on the ethernet shield is CS for the W5500, and pin 4 is CS for the micro SD card reader. For some reason, even if there is no micro SD card inserted, the SPI bus is very flakey to the point of outright not working, if you simply leave pin 4 open. It has to be pulled high.
Maybe I would have never discovered these 2 problems, if I would have plugged the shield directly onto the mega. However, the outside pin rows on the shield are longer than the ICSP socket on the shield. So the ICSP header does not plug in properly into the mega, and the SPI connection sporadically drops out.
Solution: shorten the outside pin rows with a side cutter pliers.
Okay, so we have a working setup now.
A good starting point is the webserver sketch, because it allows for some feedback.
On the IDE serial monitor, if you get "server is at 0.0.0.0", then most likely your SPI connection doesn't work.
It means that the IP address write to the W5500 failed, and obviously the subsequent read also.
If the SPI connection doesn't work:
Insert an SD card and try to connect to it. If that doesn't work, maybe your wiring is wrong.
If the SD card SPI works, maybe you have a problem with your ethernet library.
Try removing the SD card again after successfull SPI test, so it doesn't interfere.
The IP adress write will work without a network cable attached.
Once you attach a network cable, the 4 network status LEDs on the shield (100Mbit, LINK, FDX, and ACTIVE) should light up, and also the 2 LEDS on the RJ45 socket.
If not, your cable or your router socket might be defective.
If you connect directly to another PC, and the PC network adapter does not have an auto-crossover function, then you need a crossover network cable.
Now you can try to ping the shield.
If this doesn't work, maybe your IP address is not in the permissible range.
Most probably your router or another PC in your network is set up as DHCP host. The DHCP host normally assigns IP adresses to all attached network devices. In your router settings, a range of IP adresses is reserved for that purpose.
We ignored the DHCP assignment process, and assigned a fixed IP to our shield. However, this IP adress still has to be in the permissible range, because a data packet sent from a PC to an IP adress outside the range will be dropped by the router, because "recipient address not known"
Other things to try:
- did you enter the correct MAC address (sticker on the shield) into the sketch?
- try adding a subnet mask.
See also Basic Ethernet Shield Arduino Web Server
If the ping works, but the webserver example doesn't, then most likely you once had a functioning SPI connection, and have configured the W5500 correctly. The ping works independently of the arduino MCU - only power to the shield is needed.
However to serve the web page, the MCU is needed.
With me, every time I uploaded a sketch, the webserver was not reachable anymore.
Turns out the communication between W5500 and MCU needs to be reset after a sketch upload.
Two ways to do it:
- cut the power supply by unplugging the USB cable, and plugging it back in.
OR: - press the 2 reset buttons on the arduino and the shield, and let go SIMULTANEOUSLY. If you first press one reset button, and then the other, it won't work.
Okay, so far. I need to go. I hope it's helpful for someone.
Thomas