Go Down

Topic: Arduino mega 2560 + ENC28J60 Ethernet Shield + Sd Card Shield (Read 5608 times) previous topic - next topic


Sep 18, 2012, 09:38 am Last Edit: Sep 18, 2012, 10:21 am by tao13 Reason: 1
Hi everyone.
I begin my project for a little home automation.
I want to read a room temp , a motion sensor and to on/off the light.
I made the code for this and works great with this shield ENC28J60 Ethernet LAN / Network Module
I use the thiseldo-EtherShield-3793b4c library.

Now i connect the sd card shield
on the arduino at the same pins like enc28j60 shield :
CS 53
SCK 52

If you see in the image of sd card shield it has a double pins and one part i use to likn the sd card shield to the arduino pins and other part for link the enc shield to sd card shield.

I tested in this configuration the ethernet code and sd code but not in the same code , only one by one and they works separatly.
When i combined code , doesn't work.

So please tell me if i cand use the same pin 53 for many shields, or if i must do something in my code.
I want to load an image from sd card to use it like a backgroun on my web page and open a file where to write all operation who was made on my web page.
This is my code (a part of it for initialisation)

#include <etherShield.h>
#include <SdFat.h>
sdFat sd;
SdFile file;
#define error(s) sd.errorHalt_P(PSTR(s))
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   //Mac address
static uint8_t ip[4] = {192, 168, 1, 15};                       //IP address
static uint16_t port = 80;                                      //port 80
ETHER28J60 e;

void setup()
 //initializare ethernet
 e.setup(mac, ip, port);
 //initializare sd card
 if (!sd.init(SPI_HALF_SPEED)) sd.initErrorHalt();
 char name[] = "WRITE00.TXT";
 if (file.open(name, O_CREAT | O_EXCL | O_WRITE)) break;
 if (!file.isOpen()) error ("file.create");

void loop
void loop()

  char* params;
  if (params = e.serviceRequest())
    e.print("<center><p><h1>TAO13 HOME SYSTEM PAGE </h1></p> ");
    e.print("<body background=\"image2.gif\">"); \\where image2.gif found on my sd card
    e.print("<META HTTP-EQUIV='refresh' CONTENT='2; /'>");

Many thanks everyone.


So please tell me if i cand use the same pin 53 for many shields

No, you can not. Each SPI device needs a separate chip/slave select pin. Usually, pin 4 is the SD card select pin.


Thanks for your ansewer and help.
I'm a begginer and i don't know many thing about electronics.
So i understand if i have many items who works on spi i must use one pin for one item ?
For my case i must use pin 53 for ethernet and pin 4 for sd card? So i must modify the library for sd or something else?
Thanks again to all.


So i must modify the library for sd or something else?

That depends. I can't see the purpose of having more than one SD reader, for instance. Not that it really matters, because the SD card pin is an input to the class, not hardcoded in a library.

What SPI devices are you trying to talk to? Be specific, and we can help you figure out how to make them play together.


Hi and thanks.
Sorry for the delay.
So i don't have many sd module.I have one module for sd (like in the link) and one enc28j60 shield (without sd module).
I don't know what can i do to work both in the same time.
I use the same pin for sd module and enc28j60.
Many thanks again.


I don't know what can i do to work both in the same time.
I use the same pin for sd module and enc28j60.

Well, you can't do that. You need separate slave select pins to select the two different slaves.


Hello tao13,
Did you solved the problem?

Is there any working solution? I am using ENC28J60 and seprate SD card module on Uno.
I am using Pin 10 for Ethernet and 4 for SD.

My Initialization program is like below

void setup()
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");
   myFile = SD.open("test.txt");
  if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    // close the file:
  } else {
     // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
   Ethernet.begin(mac, ip,gateway,gateway,mask);
  Serial.print("DONE Ethernet as well with IP: ");


Does anyone has sample program for this?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131