Ethernet and SD in the same sketch


This is my problem :
During the setup, i read info from a SD card. After That, i don’t need the SD card anymore. I also begin listening on the network using the UDP class.

When doing that, i’m missing a lot of network packets. The system is built to receive 60 packets per second (or more) and i miss about 30 packets per second (there is an id in each packet to know if a packet has been missed)… If i comment the “SD.begin(4)”, i don’t lose any network packet anymore…but i can’t read the info from the SD card…

Can you explain me why and how to fix that?

Board used : Arduino Ethernet R3

Thanks a lot!

Edit : i tried with network packets of 1 byte and it works, but with packets of 10 bytes it doesn’t work :

Example :

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <EthernetUdp.h>

byte mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 3);
EthernetUDP Udp;

void setup(){
Ethernet.begin(mac, ip);

void loop() {

edit 2 : in fact, by changing the value send by my computer, the led changes with 4 to 5 seconds delay…and withouth the SD.begin, the led changes instantly.

What hardware are you using - is the SD on the Ethernet card, or separate? Are they both using SPI? You might need to turn off the chip select pin for the SD to stop it getting involved in SPI transfers, but I can't guess what pin that is.

Thanks for your answer PeterH!

I use the microSD on the Ethernet card, so ethernet and SD reader both use SPI. The chipselect pin for ethernet is pin 10 and the chipselectpin for SD is pin 4.

When i disable SD.Begin, pin 4 is at 0V (mesured with voltmeter) and when i enable it, pin 4 is also at 0V.

I tried to add “digitalwrite(4,HIGH)” before my ethernet.begin() to disable the SD reader but it doesn’t solve the problem… (the pin 4 is then at 5V)

I'm still investigating...I tried With the Arduino 1.0.5 IDE but without success...


I've just came across the same issue. After wondering if the problem was with the ethernet library I found through Zoomkat reply that I needed to remove the SD card (left in from previous test).

Have you found a solution for this problem?


this worked for me:

void setup() {

  // disable SD SPI
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // now do the rest of your setup stuff.

thanks to SurferTim.