Arduino Ethernet shield + SD card accessibility

I want to have a test setup for Fan speed measurement in Laboratory. Is it possible to access the data from SD card with Arduino Ethernet shield at any time from remote place of that building with other computer.

It is mentioned on Arduino site that W5100 and SD card share the SPI bus, only one can be active at a time. So will it be possible to access both at a time that data gets logged to SD card and any time we can access data with Ethernet ?

hassanhabib1454:
It is mentioned on Arduino site that W5100 and SD card share the SPI bus, only one can be active at a time. So will it be possible to access both at a time that data gets logged to SD card and any time we can access data with Ethernet ?

The SPI bus is shared for SD card and Ethernet access, but you can use one after the other easily.

If you provide a correct programming, then the libraries (Ethernet and SD) will provide the correct handling of the CS (chip select) pins of different devices, so that each device gets it correct SPI commands.

But be aware: Each switching of devices costs some time. So when sending some logfile data over Ethernet and doing such a loop

  • while not end-of file: read one byte from SD and send one byte to Ethernet
    will result in very slow data transmission rates

Data rate across the network would be much higher if you'd read blocks of 64 or 128 bytes at once, with a logic like perhaps:

  • while more than 64 bytes to send ==> read a block of 64 bytes from SD and send a block of 64 bytes to Ethernet
  • read last block of bytes from SD and send last block to Ethernet

My test plan is in such a way that fans will be in climate chamber for some days and I want to access the data of fans from SD card on daily basis with ethernet shield.So SPI will be used at same time for sending data to SD card and acquiring data from SD card over ethernet shield. Will it be possible, If it is possible kindly can someone let me know how ?

hassanhabib1454:
My test plan is in such a way that fans will be in climate chamber for some days and I want to access the data of fans from SD card on daily basis with ethernet shield.So SPI will be used at same time for sending data to SD card and acquiring data from SD card over ethernet shield. Will it be possible, If it is possible kindly can someone let me know how ?

Perhaps create a "SD card data logger" and a "webserver" combined in one sketch?

Loop programming logic perhaps like that for a 1-minute logging:

unsigned long lastLogMillis;
void loop()
{
  if (millis()-lastLogMillis>60000L) // will run every 60 seconds
  {
     doLogging();
     lastLogMillis+=60000L;
  }
  handleServerRequest();  // will run each time the loop function is executed
}

You then write a "doLogging()" function that writes log data to SD card, and a "handleServerRequest()" function that handles request to the webserver part of your sketch.

When using SD and Ethernet library at the same time, most of the RAM of an UNO (2kB) will already be in use. So if you are unable to write very effective and RAM saving programs you better use a MEGA instead an UNO, which provides much more RAM for your project.

You then write a "doLogging()" function that writes log data to SD card, and a "handleServerRequest()" function that handles request to the webserver part of your sketch.

I have done the programming in such a way that Arduino generates PWM for fans from 50% to 100% with increment of 10% PWM in each hour.The output of the fans from MUX is saved into SD card.

void loop(){
  
//50% PWM loop
  time_since_last_reset = millis();                 //obtain reference  
  while((millis() - time_since_last_reset) < interval_one) //loop for one hour
{ 
    analogWrite(pwmPin, 127);
    for(int i = 0; i < 32; i ++)           //For loop save the values of 31 fans
{
    Serial.print("Value at channel ");
    Serial.print(i);
    Serial.print("is : ");
    Serial.println(readMux(i));            //prints the value of Fan
    String dataString = String(id) + ", " + String(readMux(i)); 
    File logFile = SD.open("LOG.csv", FILE_WRITE);
    if (logFile)
    {
     logFile.println(dataString);
     logFile.close();
     Serial.println(dataString);
    }
    else
    {
    Serial.println("Couldn't open log file");
    }
  id++;
  
  delay(1000);
  }
    Serial.println("50% PWM loop");         //for interval_one  
  }
  
  Serial.println(""); Serial.println("");

*********************************
* same for 60%-90%PWM in each hour               *
*********************************
  
  //100% PWM loop
  time_since_last_reset = millis();                //obtain reference 
  while((millis() - time_since_last_reset) < interval_two)  //loop for one hour
{ 
    analogWrite(pwmPin, 255);
    for(int i = 0; i < 32; i ++)         //For loop save the values of 31 fans
{
    Serial.print("Value at channel ");
    Serial.print(i);
    Serial.print("is : ");
    Serial.println(readMux(i));
    String dataString = String(id) + ", " + String(readMux(i)); 
    File logFile = SD.open("LOG.csv", FILE_WRITE);
    if (logFile)
    {
     logFile.println(dataString);
     logFile.close();
     Serial.println(dataString);
    }
    else
    {
    Serial.println("Couldn't open log file");
    }
  id++;
    delay(1000);
  }
    Serial.println("100% PWM loop");   //for interval_two 
  }

hassanhabib1454:
I have done the programming in such a way that Arduino generates PWM for fans from 50% to 100% with increment of 10% PWM in each hour.The output of the fans from MUX is saved into SD card.

You better think first, before starting to write code for your project.

If you want your Arduino to be "responsive at any time", meaning that you can send a HTTP-request from your webbrowser to your Arduino, and want to get back the response without any delay in your webbrowser window, then you

  • cannot use "delay()" in your sketch
  • cannot use "busy waiting" in your sketch

Instead of that you'd have to use a "cooperative multitasking" logic for each and every task of your sketch, so that unsused time can be scheduled for all the things that have to happen in your sketch, like logging to SD card when it's time for logging, and sending HTTP-responses when HTTP-requests are coming in.

Delay and busy waiting is pure nonsense in the programming logic of sketches, that have to do more than just one single task.