Go Down

Topic: Question using SD with WiFi Shield (Read 484 times) previous topic - next topic

Muser84

I've tried to work SD into this code below.  Which was unsuccessful.  Any suggestions? Thanks

Code: [Select]
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>

#include <Wire.h>
#include "RTClib.h"
#include <SdFat.h>
SdFat SD;
RTC_DS1307 RTC;
File myFile;

#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX

char ssid[] = "//"; //  your network SSID (name)
char pass[] = "//";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
int x = 0;  //vaiable for machine one
int y = 0;  //variable for machine two
// Your Xively key to let you upload data
char xivelyKey[] = "pass here";

// Define the strings for our datastream IDs
char sensorId[] = "Machine_1_Bridgeport";
char sensor2Id[] = "Machine_2_Colchester";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
  XivelyDatastream(sensor2Id, strlen(sensor2Id), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(3455656, datastreams, 2 /* number of datastreams */);

WiFiClient client;
XivelyClient xivelyclient(client);


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void setup() {
  // put your setup code here, to run once:
 XBee.begin(9600);
  Serial.begin(9600);      // initialize serial communication
 while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
    Wire.begin();
    RTC.begin();
 //Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(10, OUTPUT);
   
    if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  // check for the presence of the shield:

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while(true);        // don't continue
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  if (Serial.available()>0){
   Serial.write(Serial.read());
 }
 
  Serial.print("X value:");
  Serial.print(x);
  int Machine_1_Bridgeport = x;
  datastreams[0].setFloat(Machine_1_Bridgeport);

  Serial.print(" Read sensor value ");
  Serial.println(datastreams[0].getFloat());

  Serial.println("Uploading it to Xively");
 


  Serial.println();
   
  ////////////////////////////////////////////////////////////////////
    Serial.print("Y value:");
  Serial.print(y);
  int Machine_2_Colchester = y;
  datastreams[1].setFloat(Machine_2_Colchester);

  Serial.print(" Read sensor value ");
  Serial.println(datastreams[1].getFloat());
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);


  Serial.println();
  //////////////////////////////////////////
 while (Serial.available()>0)
 {
 
   if (Serial.read()=='1')  //machine one Bridgeport ON
   {
     x = 1;
 
   }
   {
if (Serial.read()=='2')  //machine one Bridgeport ON
   {
     x = 0;
   
   }
   }
 
   /////////////////////////////////////////////////////////////////////////////////
    if (Serial.read()=='3')  //machine two Colchester ON
   {
     y = 1;
   
   }
   {
if (Serial.read()=='4')  //machine two Colchester ON
   {
     y = 0;

   }
   }
 }
}

 

 

   
 



I know my problem is here.  I've also tried adding digitalwrite(10 high) below pinMode(10, OUTPUT);
Any suggestions? Thanks

Code: [Select]
  pinMode(10, OUTPUT);
   
    if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }

Muser84

Solved.  There was not enough memory on the Arduino UNO.  Purchased a MEGA 2560 and worked just fine. 

Go Up