SD Storage problem with UNO+wifi shield

I face a problem that i used UNO and wifi shield to do project. The process is that first connect to wifi AP, sensing data , send to database and finally store data to SD which is on the wifi shield. The first three step is OK, however, when enter to storage process, the program would have some problem such as show the garbage characters in serial monitor and stop.

This problem is really confused me. i separate this code to sensing data+SD, it works. So is the wifi.h would effect SD.h?

How could i fix this problem?

THX!

I face a problem that i used UNO and wifi shield to do project. The process is that first connect to wifi AP, sensing data , send to database and finally store data to SD which is on the wifi shield. The first three step is OK, however, when enter to storage process, the program would have some problem such as show the garbage characters in serial monitor and stop.

This problem is really confused me. i separate this code to sensing data+SD, it works. So is the wifi.h would effect SD.h?

How could i fix this problem?

THX!

Without seeing your code, it sounds like you have run out of SRAM. If you try to use more SRAM than you have available, it will wrap around into areas of SRAM used by the serial buffer.

You are probably running out of SRAM. Either reduce the amount of SRAM you are using, or get an Arduino with more SRAM, like a Mega.

The easiest way to reduce the amount of SRAM is using the F() function to keep static strings in program memory.

But without seeing your code, I am just guessing.

Here is a part of the code.

I think wifi and sd all use SPI bus. is this the reason which cause the program problem?

How could i fix with these code?

THX!

WiFiClient client;
int  Status = WL_IDLE_STATUS;               
int CS_pin = 4;

void setup()
{
   Serial.begin(9600);
   delay(1000);
   SDsetup();
   ConnectToAP();
}

void ConnectToAP(){  
  Status = WiFi.begin(ssid, pass);
  
  if ( Status != WL_CONNECTED) { 
      Serial.println("Couldn't get a wifi connection");
      while(true);
  } 
  
  else {        
      printWifiStatus();
  }
}

void SDsetup(){
  //Check if card ready
  if(!SD.begin(CS_pin))
  {
    Serial.println("Card Failed");
    return;
  }
  Serial.println("Card Ready");
  
  File logFile = SD.open("LOGG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println(", , ,"); 
    logFile.println("number, Temp_C, Hum, Illu");
    logFile.close();
  }
  else
  {
    Serial.println("Couldn't open log file");
    return;
  }
}

moderator: cross posts merged

Hi, robtillaart!!

I'm no very understand what you explain. I'm a new player in this area. Please explain more detail for me or tell me how to modify my code to have these two function at the same program.

Thanks.

On this forum it is not appreciated if you post the same question in different sections.
The reason is that all answers get scattered around and you will get multiple the same answers, other people give the same answer, effectively wasting time.

If you have multiple SPI devices you must enable/disable them alternately with their CS (=Chip Select) pin.

If you have multiple SPI devices you must enable/disable them alternately with their CS (=Chip Select) pin.

If you have ANY SPI devices (on a UNO or other 328-based Arduino) you need to set pin 10 as OUTPUT, too.

I just add pinMode(10, OUTPUT) in front of the SDsetup() in setup condition. However, it still fail.

The SD card shows card ready, but i can not open log file and write data in to SD card.

this problem makes me crazy. =(