Hi

--- Right now I'm trying to use an Arduino wireless SD shield to transmit temperature data to and Xbee(1) on a breakout board to the computer. The sketch is listed below.
1) See the comment at top of the sketch. The SD card isn't printed to, but it is working for the Examples sketch, SD card read/write. I was extremely careful in comparing the Examples' read/write and the commands in my sketch.
Two more questions came up, but these can be deferred 'till later. The SD card is the important problem right now.
2) The X-CTU terminal prints the data OK, but there are no "mySerial.print" commands needed when the shield atop the UNO is connected to the computer. Yet when I use another power source, no data is sent to the X-CTU terminal. This is true, also, when I do use "mySerial.print" to send data, as shown in the sketch.
3)File myFile; is declared globally
and in void loop(). If it's declared globally only, I get an error message that it isn't declared in this scope. Why?
/* This sketch compiles and prints OK to Serial monitor and to
X-CTU,
but doesn't print to the Micro SD card in the Arduino SD
wireless shield. The card initialization fails. However, The
example, "read/write" does print OK to this same Micro SD on
this shield. Sketch setup for the SD card is between two "===="lines.
*/
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(0,1);
#include <SD.h>
const int chipSelect = 10;
const int sensPin = 0;
const int ledPin = 8;
void setup() {
Serial.begin(9600);
pinMode(sensPin, INPUT);
pinMode(ledPin, OUTPUT);
mySerial.begin(9600);
mySerial.print("Hello World");
//=============================================SD setup
Serial.print("initializing SD card --");
if(!SD.begin(chipSelect)) {
Serial.println("Card Failed");
return;
}
Serial.print("Card Initializeds");
pinMode(10, OUTPUT);
Serial.print("Card Initialized");
if (SD.exists("Datalog.txt")) {
Serial.println("Datalog.txt exists");
}
else {
Serial.println("Datalog.txt doesn't exist");
}
// ===========================================SD done
DateTime now = RTC.now();
RTC.begin(DateTime(__DATE__, __TIME__));
Serial.print("OK thus far");
}
void loop(){
File myFile;
myFile = SD.open("Datalog.txt", FILE_WRITE); // Culprit
int reading = analogRead(sensPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
float tempC = (voltage - .44) * 100;
float tempF = (tempC * 9.0/5.0) + 32;
Serial.print("1");
Serial.print(" ");
DateTime now = RTC.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(" ");
Serial.print(voltage);
Serial.print(" ");
Serial.print(tempC);
Serial.print(" ");
Serial.print(tempF);
Serial.println("");
mySerial.print(now.hour(), DEC);
mySerial.print(':');
mySerial.print(now.minute(), DEC);
mySerial.print(':');
mySerial.print(now.second(), DEC);
mySerial.print(" ");
mySerial.print(voltage);
mySerial.print(" ");
mySerial.print(tempC);
mySerial.print(" ");
mySerial.print(tempF);
mySerial.println("");
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if (myFile) {
myFile.println("Datalog.txt");
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
myFile.print(" ");
myFile.print(voltage);
myFile.print(" ");
myFile.print(tempC);
myFile.print(" ");
myFile.print(tempF);
myFile.println("");
myFile.close();
}
delay(2000);
}