Temperature and Light data logger sketch problem

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mike_795
 
Posts: 3
Joined: Sun May 26, 2013 11:20 pm

Temperature and Light data logger sketch problem

Post by mike_795 »

I am sure I will get thumped but I can not compile the example sketch for the L&T logger.
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);
} 
Error List:

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'
Last edited by adafruit_support_bill on Mon May 27, 2013 5:50 am, edited 2 times in total.
Reason: Fixed code tags

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature and Light data logger sketch problem

Post by adafruit_support_bill »

Not sure where you got the code, but it has what look like some random stray lines in it. Download the code here from Github:
https://github.com/adafruit/Light-and-Temp-logger

User avatar
mike_795
 
Posts: 3
Joined: Sun May 26, 2013 11:20 pm

Re: Temperature and Light data logger sketch problem

Post by mike_795 »

Thanks _bill
I downloaded the zip file and tried again. Got a number of SPI errors.
I am still not up to speed on where the various arduino IDEs look for files and some of the keyword highlighting means.
Tried Arduino 1.5.2 the include section has SD & Wire in amber and enclosed with<> the RTCLib is blue and enclosed with " ".
not sure if that is trouble or not.
Knocked around trying to learn what is what but still have a lot of holes in things. As you can see I'm not very accomplished at posting either.

#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
Got a different set of errors this time. I have the verbose turned on to try and trace where the compiler is getting files. The SD.h seems to be coming from an unintended folder(I have things in c:/program files/Arduino/SD which is where I though I sent it) so I am not sure why it is looking in the documents folder or how to send it to where I want it to go.
Any hints?

Errors:
C:\Program Files\Arduino\arduino-1.5.2\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\variants\standard -IC:\Users\Mike\Documents\Arduino\libraries\SD -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\libraries\Wire -IC:\Users\Mike\Documents\Arduino\libraries\RTClib_Master C:\Users\Mike\AppData\Local\Temp\build1066046646291438703.tmp\lighttemplogger.cpp -o C:\Users\Mike\AppData\Local\Temp\build1066046646291438703.tmp\lighttemplogger.cpp.o
C:\Program Files\Arduino\arduino-1.5.2\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\variants\standard -IC:\Users\Mike\Documents\Arduino\libraries\SD -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\libraries\Wire -IC:\Users\Mike\Documents\Arduino\libraries\RTClib_Master -IC:\Users\Mike\Documents\Arduino\libraries\SD\utility C:\Users\Mike\Documents\Arduino\libraries\SD\File.cpp -o C:\Users\Mike\AppData\Local\Temp\build1066046646291438703.tmp\SD\File.cpp.o
C:\Program Files\Arduino\arduino-1.5.2\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\variants\standard -IC:\Users\Mike\Documents\Arduino\libraries\SD -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\libraries\Wire -IC:\Users\Mike\Documents\Arduino\libraries\RTClib_Master -IC:\Users\Mike\Documents\Arduino\libraries\SD\utility C:\Users\Mike\Documents\Arduino\libraries\SD\SD.cpp -o C:\Users\Mike\AppData\Local\Temp\build1066046646291438703.tmp\SD\SD.cpp.o
C:\Program Files\Arduino\arduino-1.5.2\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\variants\standard -IC:\Users\Mike\Documents\Arduino\libraries\SD -IC:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\libraries\Wire -IC:\Users\Mike\Documents\Arduino\libraries\RTClib_Master -IC:\Users\Mike\Documents\Arduino\libraries\SD\utility C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp -o C:\Users\Mike\AppData\Local\Temp\build1066046646291438703.tmp\SD\utility\Sd2Card.cpp.o
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp: In function 'void spiSend(uint8_t)':
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp:35: error: 'SPI' was not declared in this scope
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp: In function 'uint8_t spiRec()':
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp:44: error: 'SPI' was not declared in this scope
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t)':
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp:251: error: 'SPI' was not declared in this scope
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':
C:\Users\Mike\Documents\Arduino\libraries\SD\utility\Sd2Card.cpp:507: error: 'SPI' was not declared in this scope

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature and Light data logger sketch problem

Post by adafruit_support_bill »

Tried Arduino 1.5.2
1.5.2 is beta software. And in our experience, it is not quite ready for prime time. I would recommend version 1.0.4.

User avatar
mike_795
 
Posts: 3
Joined: Sun May 26, 2013 11:20 pm

Re: Temperature and Light data logger sketch problem

Post by mike_795 »

1.5.2 is beta software. And in our experience, it is not quite ready for prime time. I would recommend version 1.0.4.
Spot on _bill! Tried version 1.0.4 and things came together. Thank you very much.
All things wee running but now have an odd result with the RTC. The 3V battery is showing 3.1V so I think it was holding over night. When I got the logger running the time was off by the amount between power down and power up.(I did not remove the 3V bat) Am I missing a procedure or 3V needs replacement(Came with the logger)?
What a device, I remember needing three men and a boy to setup data loggers and a week to get the strip charts synced with the sensors. Using in the field required portable generators.
This is just to cool!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Temperature and Light data logger sketch problem

Post by adafruit_support_bill »

3.1v sounds like a healthy battery and should be plenty to keep the clock running. Make sure the contacts are clean and check to see that the RTC chip is getting power when the rest of the system is powered down.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”