Finding my issue has had no joy. HELP!
Thanks
The test runs for the sensors and card seemed to work.
I sure hope I posted correctly.
Code:
Code: Select all
#include "SD.h"
#include <Wire.h>
#include "RTClib.h"
// A simple data logger for the Arduino analog pins
#define LOG_INTERVAL 1000 // mills between entries
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
// the digital pins that connect to the LEDs
#define redLEDpin 3
#define greenLEDpin 4
// The analog pins that connect to the sensors
#define photocellPin 0 // analog 0
#define tempPin 1 // analog 1
RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
while(1);
}
void setup(void)
{
Serial.begin(9600);
Serial.println();
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis,time,light,temp");
#if ECHO_TO_SERIAL
Serial.println("millis,time,light,temp");
#if ECHO_TO_SERIAL// attempt to write out the header to the file
if (logfile.writeError || !logfile.sync()) {
error("write header");
}
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
}
void loop(void)
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
#if ECHO_TO_SERIAL
Serial.print(m); // milliseconds since start
Serial.print(", ");
#endif
// fetch the time
now = RTC.now();
// log time
logfile.print(now.get()); // seconds since 2000
logfile.print(", ");
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
Serial.print(now.get()); // seconds since 2000
Serial.print(", ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
int photocellReading = analogRead(photocellPin);
delay(10);
int tempReading = analogRead(tempPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = tempReading * 5.0 / 1024;
float temperatureC = (voltage - 0.5) * 100 ;
float temperatureF = (temperatureC * 9 / 5) + 32;
logfile.print(", ");
logfile.print(photocellReading);
logfile.print(", ");
logfile.println(temperatureF);
#if ECHO_TO_SERIAL
Serial.print(", ");
Serial.print(photocellReading);
Serial.print(", ");
Serial.println(temperatureF);
#endif //ECHO_TO_SERIAL
digitalWrite(greenLEDpin, LOW);
}
Code: Select all
C:\Program Files\Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IC:\Program Files\Arduino\arduino-1.0.1\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\arduino-1.0.1\hardware\arduino\variants\standard -IC:\Users\Mike\Documents\Arduino\libraries\SD -IC:\Program Files\Arduino\arduino-1.0.1\libraries\Wire -IC:\Users\Mike\Documents\Arduino\libraries\RTClib_Master C:\Users\Mike\AppData\Local\Temp\build9139454464786825608.tmp\sketch_may26c.cpp -o C:\Users\Mike\AppData\Local\Temp\build9139454464786825608.tmp\sketch_may26c.cpp.o
sketch_may26c.cpp:93:1: error: unterminated #if
sketch_may26c.cpp:91:1: error: unterminated #if
sketch_may26c.cpp: In function 'void setup()':
sketch_may26c.cpp:76: warning: deprecated conversion from string constant to 'char*'
sketch_may26c:89: error: 'class File' has no member named 'writeError'
sketch_may26c:89: error: 'class File' has no member named 'sync'
sketch_may26c.cpp:95: warning: deprecated conversion from string constant to 'char*'
sketch_may26c.cpp: In function 'void loop()':
sketch_may26c:120: error: 'class DateTime' has no member named 'get'
sketch_may26c:134: error: 'class DateTime' has no member named 'get'