SD Card wont initialize - SainSmart Arduino uno and ethernet shield

I got fed up and went on bought a real Arduino and Seed Studio ethernet shield from radio shack. Plugged it in and it worked with SdChipSelect = 4 It literally took 30 seconds to get it working with my existing 32GB SD card.

So then I tried plugging the See Studio Ethernet shield into Sainsmart Arduino and that worked too! No issues at all. So the problem comes down to the SainSmart ethernet shield. Now looking closer at this I notice the Seed Studio Arduino ethernet shield has all the pins. The sainsmart ethernet shield is missing 2 pins on the left and 2 pins on the right side. Left pins that are missing are NC and IOREF, Right pins that are missing are SCL and SDA.

As you can see in this picture from their website the shield is missing some pins that plug into the Arduino.

So the problem is with the SainSmart ethernet shield. Now is there any way of getting this working with those 4 pins missing? Sorry I am a bit of a newbie when it comes to what all the pins do.

Those pins are not used by SdFat or the Ethernet library so you have a bad Ethernet board, as I suspected.

SCL and SDA are duplicate I2C pins and used to provide I2C compatibility with newer shields on Mega and Uno. Same for the other pins, they are not needed unless you stack another shield that needs them.

I think you have this shield : http://www.sainsmart.com/sainsmart-ethernet-shield-w5100-for-arduino.html
It is not a 'R3' version, but it has the ICSP header at the bottom, so it should work.
But perhaps only if you have set the Uno to 5V.

Sorry, I forgot the sainsmart 3.3 - 5 v switch. It must be at 5 v.

fat16lib:
Sorry, I forgot the sainsmart 3.3 - 5 v switch. It must be at 5 v.

Yes, I tried that too. I set it to 5V and it didnt work with the SainSmart shield but the SeedStudio ethernet shield worked fine with the Sain Smart Arduino.

Okay now I have another problem!! The SeedStudio ethernet (the one i bought from Radio Shack) wont initialize!! The SainSmart ethernet has been working with no issues and I was able to reach my server. But the same code doesn't work on the Seed Studio shield. (Do I just have that much bad luck that its another hardware problem??)

You have tell exactly which shield and which board you use together. It might be a compatibility problem. Or did it work before ?

This is indeed getting confusing. When you would have bought the official Arduino boards they are version 'R3', and it should work right out of the box.
The Arduino boards have been updated to version 'R3'. Those boards are compatible with other 'R3' boards and shields, and the shields are able to automatically switch between 5V and 3.3V (the Arduino Due runs at 3.3V).

Perhaps you would have less problems when you bought the cheapest 'R3' compatible boards from Ebay. In my experience only 1 in 10 does not work.

The SeedStudio ethernet (the one i bought from Radio Shack) wont initialize!!

The newer ethernet shields from Radio Shack have the w5200 ethernet controller onboard. Is it this one?

If so, you must download and install the Ethernet Shield V2.0 library for that controller from that page.

SurferTim:
The newer ethernet shields from Radio Shack have the w5200 ethernet controller onboard. Is it this one?
Ethernet Shield V2.0 | Seeed Studio Wiki
If so, you must download and install the Ethernet Shield V2.0 library for that controller from that page.

Yes you are right. I got the sample app working with the Ethernet V2.0 library. I am still struggling to get my application working. ( I need to debug further and see what the problem is). I got it to initialize but it wont serve anything.

I use a w5100 shield and Mega 2560, and my server code with a SD works great.
http://playground.arduino.cc/Code/WebServerST
You can do me a favor and try it with your w5200. Insure you change the includes as specified for the w5200. Let me know if it works ok.

SurferTim:
I use a w5100 shield and Mega 2560, and my server code with a SD works great.
Arduino Playground - WebServerST
You can do me a favor and try it with your w5200. Insure you change the includes as specified for the w5200. Let me know if it works ok.

SurferTim, yes that sample works great!!

An existing app which I found online uses SD2Card method of reading files. When I use the Sd2Card method the Ethernet doesnt initialize with the new EthernetV2. Using the SD.readfile(...) method works but why wouldnt the other older method work anymore?

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

Be more specific. What is the indication the ethernet initialization doesn't work?

Post a link to the SD2Card app. I'll take a look at it.

Also post the setup() function from your code that doesn't work.

edit: Maybe you can do a favor for me. :slight_smile: I need someone with the Seeed Studio library installed to test a new function I installed in w5200.h. It allows you to check if the ethernet interface is up or not. That is available only with the w5200, and I have a w5100.

If you are up to the test, let me know and I will post the new w5200.h file and the test sketch. Let me know if you are using Windows or Linux OS.

Sure would love to help! I am on Windows or OSX.

This is what I am building:

http://forum.arduino.cc/index.php?topic=256405.0

This is the Arduino code I am trying to run. The Arduino Controlled, Phone Operated, House Wide Audio System (Part 2) - Home Automation - Arduino Forum

But with Ethernet V2 and the SD2 method the server doesn't run meaning the Browser can not connect to the Arduino there is nothing running on port 80 on my Arduino's IP. This Home Audio Ethernet application runs fine when I don't use the SD2 method of reading the card.

First the errors. This is incorrect. You forgot the dns server parameter.

// change this
  Ethernet.begin(mac, ip, gateway, subnet);
// to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

The only thing I see different from the SD.begin() call and your code is the SPI bus speed. Maybe the speed is too high? Try a slower speed.

// charge this
  card.init(SPI_FULL_SPEED, 4);
// to this
  card.init(SPI_HALF_SPEED, 4);

If that doesn't work, try setting D4 HIGH before the Ethernet.begin() call.

// add this
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

Let me know if that makes any difference, then I'll post the new w5200.h file and test sketch.

// change this
card.init(SPI_FULL_SPEED, 4);
// to this
card.init(SPI_HALF_SPEED, 4);

That did the trick!! The webserver and the SD Card are all finally working now! Thank you so much!
Now time to wire the rest up!

So how can I help you now?? Let me know what you need me to test!!!

I attached the new w5200.h file and the test sketch.
Go to "My Documents/Arduino/libraries/EthernetV2_0/utility" folder.
Rename the current w5200.h file to w5200orig.h. Then move this w5200.h file into that folder.
Then compile and upload the DHCPAddressPrinterW5200.ino sketch.

It should report "interface up" or "interface down", depending on the CAT5 cable. If you leave it inserted, it should report "interface up". If you remove it, it should report "interface down".

Thanks for testing this for me. I'm looking forward to getting a w5200 shield soon.

w5200.h (14.6 KB)

DhcpAddressPrinterW5200.ino (1.62 KB)

SurferTim:
I attached the new w5200.h file and the test sketch.
Go to "My Documents/Arduino/libraries/EthernetV2_0/utility" folder.
Rename the current w5200.h file to w5200orig.h. Then move this w5200.h file into that folder.
Then compile and upload the DHCPAddressPrinterW5200.ino sketch.

It should report "interface up" or "interface down", depending on the CAT5 cable. If you leave it inserted, it should report "interface up". If you remove it, it should report "interface down".

Thanks for testing this for me. I'm looking forward to getting a w5200 shield soon.

Just tried it but something breaks after the linkStatus call and I added a logger for the linkStatus as well but it never prints it...

I adding the following loggers and nothing gets printed after "Starting..."

Serial.println("Starting....");

byte linkStatus = W5100.getPHYStatus();
 
Serial.println(linkStatus);
 
if(linkStatus & 0x20) Serial.println("interface up");
else Serial.println("interface down");

Sorry to come back to my issue... but its taking 20 seconds to serve my 20KB KAMDORA.HTM file...
Its extremely slow..

Is it because of the HALF_SPEED setting I set below?

  card.init(SPI_HALF_SPEED, 4);

OK. Thanks for the try. I guess I'll have to wait to get a w5200 shield myself. If you want, you can remove the new w5200.h file and change the original back to w5200.h.

As for this...

djx18:
Sorry to come back to my issue... but its taking 20 seconds to serve my 20KB KAMDORA.HTM file...
Its extremely slow..

Is it because of the HALF_SPEED setting I set below? I am assuming the SD Card is now reading at half the speed...

  card.init(SPI_HALF_SPEED, 4);

If you are reading a byte from the SD, then sending that byte over the ethernet interface, 20 seconds sounds about right. Is that what you are doing?

Take a look at my server code. The first one is the SD based web server.
http://playground.arduino.cc/Code/WebServerST
It uses a 65 byte array, and loads 64 bytes at a time from the SD, then sends them all as one packet. That will work about 4 times faster.

fat16lib:
This is rarely the SD card. I get your errorCode and errorData with an Arduino Ethernet shield on an Uno when I set SD_CHIP_SELECT to SS or 10.

You should set SD_CHIP_SELECT to 4. When I set SD_CHIP_SELECT to 4 with the Arduino Ethernet shield I get success:

When I remove the SD card with SD_CHIP_SELECT set to 4, I get this with the Arduino Ethernet shield:
Do you get 0XFF for errorData when the card is removed? Do you get a different value for errorData with the card?

fat16lib:
This is rarely the SD card. I get your errorCode and errorData with an Arduino Ethernet shield on an Uno when I set SD_CHIP_SELECT to SS or 10.

You should set SD_CHIP_SELECT to 4. When I set SD_CHIP_SELECT to 4 with the Arduino Ethernet shield I get success:

When I remove the SD card with SD_CHIP_SELECT set to 4, I get this with the Arduino Ethernet shield:
Do you get 0XFF for errorData when the card is removed? Do you get a different value for errorData with the card?

Mr. Author(sdfat.h)

i also have the issue, when i remove the card it shows 0xff to 0x0.

as you said i have to select the SD_CHIP_SELECT to 4 not ss, but still not working.. :frowning: