WiShield and SD card logging problems

Hello all,
]
I am new to Arduino, but have successfully integrated the Cuhead Wifi Shield with my Arduino Uno. I am able to load my webpage and get my DHT11 humidity/temp sensor data streaming. Additionally, I can simultaneously get serial printing to work without any problems.
Now the problems begin when I try to add the SD card logging capabilities via my Arduino brand SD shield. I can run the logging by itself and it works fine with the serial output, but trying to integrate that with my web page streaming isn't working. So I need help to try and locate the bottleneck, which I suspect is a coding issue I'm unaware of.
My physical layout is this: Arduino Uno, Arduino Wireless Sd card on top, and finally my CuHead Wfi shield on top of that. Again all work well individually as they are stacked.

Here is my code as it stands. I don't feel like any of this is original coding from me. It all came from open sources.
TY in advance,
houdinihar

#include "DHT.h"
#include <WiServer.h>
#include <Arduino.h>
#include <SD.h>

#define DHTPIN 2 // what pin I'm connected to for the Wishield

// Uncomment whatever type sensor you're using! From DHT library
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

//for SD card reading/writing
File myFile;
const int chipSelect = 4;

#define WIRELESS_MODE_INFRA	1
//#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,10};	// IP address of WiShield-self-assigned
unsigned char gateway_ip[] = {192,168,1,1};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"my_network_name"};		// name of your wireless router network--max 32 bytes

unsigned char security_type = 3;	// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase (password)
const prog_char security_passphrase[] PROGMEM = {"my_password"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys

//even though you may not be using wep, DO NOT comment out this section-it will cause errors
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
				};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;

// End of wireless configuration parameters ----------------------------------------


// This is the page serving function that generates web pages
boolean sendMyPage(char* URL) {

        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        float c = dht.readTemperature();
        float f = 0;
        
        //conversion to get C to F
        f = c * 9/5 + 32;
        //declaring a string type for the degree symbol, then adding that to C or F
        String DegC, DegF;  //, DegF, lcdDegF;
        DegC += char(176);           // Setup a Degrees C Serial symbol
        DegC += "C ";
        DegF += char(176);           // Setup a Degrees F Serial symbol
        DegF += "F ";
        
        
        // check if returns are valid, if they are NaN (not a number) then something went wrong!
        if (isnan(c) || isnan(h)) {
        	WiServer.print("<html>");  //Here is the code for the html page         
         	WiServer.print("Failed to read from DHT");
        	WiServer.println("        </html>");
        } else {
        
        
        // open the file. note that only one file can be open at a time,
        // so you have to close this one before opening another.
        myFile = SD.open("test.txt", FILE_WRITE);
  
        // if the file opened okay, write to it:
        if (myFile) {
        Serial.print("Writing to test.txt...");
        myFile.print(h,1);
        myFile.print(",");
        myFile.println(f,1);
        myFile.print(",");
        myFile.println(c,1);
	      // close the file:
        myFile.close();
        Serial.println("Finished storing data.");
        } else {
        // if the file didn't open, print an error:
        Serial.println("Error opening test.txt");
        }
  
       // re-open the file for reading:
       myFile = SD.open("test.txt");
       if (myFile) {
       Serial.println("Reading test.txt:");
    
       // read from the file until there's nothing else in it:
       while (myFile.available()) {
    	 Serial.write(myFile.read());
       }
      
       // close the file:
       myFile.close();
       } else {
  	   // if the file didn't open, print an error:
       Serial.println("Error opening test.txt");
       }
          
        WiServer.print("<html><head>");
        //refresh my web page automaticaly every 10 sec with current data from DHT11 sensor
        WiServer.print("<meta http-equiv='refresh' content='10'></head>");        
        
        WiServer.print("<center><H2>Dave's Home Temp/Hum Setup:  Sensor ID: DHT11</H2>


");
                
        WiServer.print("Humidity: ");
        //make humidity label to a tenth of a degree-not necessarily that accurate per the data literature
        WiServer.print(h,1);       
        WiServer.print("%");
        WiServer.print("
");
        
        WiServer.print("Temperature: ");
        //make fahrenheit label to a tenth of a degree-not necessarily that accurate per the data literature
        WiServer.print(f,1);
        WiServer.print(DegF);
        WiServer.print("
");
        
        WiServer.print("Temperature: ");
        WiServer.print(c,1);
        WiServer.print(DegC);
        WiServer.print("
");
        WiServer.print("</center></html>");
                
        
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}

void setup() {
  pinMode(10, OUTPUT);// for the SD card to read
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
  //start the dht sensor reading
  dht.begin();
}

void loop(){
    // Run WiServer
  WiServer.server_task();
  delay(20);
}

If you have the SD card in the shield slot, you must disable the SD card SPI before starting any other SPI device, like the Cuhead. The SD shield shows the SD slave select is D4, so this will disable it:

void setup() {
  pinMode(10, OUTPUT);// for the SD card to read

  // disable the SD card while starting the WiServer.
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
  //start the dht sensor reading
  dht.begin();
}

Thank you Tim.
So what is the next step to get the SD card back on and start logging the data, since I have just turned off its capabilities to do anything further ATM.

houdinihar

If that worked for your WiShield, getting the SD card going is simple. After you get all your SPI stuff going, start the SD card. I added it last in your setup() function.

void setup() {
  pinMode(10, OUTPUT);// for the SD card to read

  // disable the SD card while starting the WiServer.
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
  //start the dht sensor reading
  dht.begin();

  // Start the SD card
  Serial.print(F("Starting SD..."));
  if(!SD.begin(4)) Serial.println(F("failed"));
  else Serial.println(F("ok"));
}