OpenLog partially tested
Posted: August 24, 2012 Filed under: Arduino, Data logging, OPenLog, Testing | Tags: Arduino, data logger, RTC, Thermister Leave a commentWell I have to say, I am not particularly impressed with OpenLog’s documentation but I finally got a sketch to work with OpenLog based heavily on the OpenLog command sketch. I soldered up a Yourduino.com Real time clock kit and am waiting on some male to male jumper wires to breadboard up a thermistor and clock to fully test the OpenLog data logging in a closer to real world trial. Of course until it is finally mounted in the boiler control box and mounted on the boiler this will only be the next step in testing.
Hard experience has taught me many things work on the desk that do not work in the field due often to poor electronic practice, missing diodes, filtering capacitors, missing resistors….
Here is the code which I intend to run when I get the project bread boarded, it compiles but is untested.
/*
RTC, Thermisoter, OpenLog test
One thermistor attached to analog pins 0
The Real time clock SDA pin is attached to analog 4, the RTC SCL pin is attached to analog pin 5
The circuit:
Inputs
* Thermister Analog in 0
* RTC SDA, Analog pin 4
* RTC SCL, Analog pin 5
Outputs
* Arduino digital 0 (rx), OpenLog TX
* Arduino digital 1 (tx), OpenLog Rx
* Arduino digital 2, OpenLog Grn
Created 8/24/12
http://www.frugaltinker.com
*/
#include <math.h> // include the library code for thermsiter functions
#include <Wire.h>
#include “RTClib.h”
//section for time keeping
int hour; //hour
int minute; //minute
int Roomtemp; //room temperature
int statLED = 13; //flashes LED connected to pin 13 for troubleshooting
int resetOpenLog = 2; //reset on OpenLog
long DataDwell = 60000; //seperates the data readings by 1 minute
long prevmillis =0; // previous millis
RTC_DS1307 RTC;
//define function to calculate the temperature in fahrenheit for Analog pin 0
double ThermisterRoom(int RawADC) {//beginning of function
double Temp;
Temp = log(((10240000/RawADC) – 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp – 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}//end of function
void TimeSection() {//start time function
DateTime now = RTC.now();
hour=now.hour(),DEC; //get the hour from the RTC chip
minute=now.minute(),DEC; //get the minute from the RTC chip
}// end time function
void OpenLogData(){//start OpenLogData function
int RoomTemp = ThermisterRoom(analogRead(0)); //read from the sensor
Serial.print (hour);
Serial.print (“:”);
Serial.print (minute);
Serial.print (“, “);
Serial.println (RoomTemp);
}// end OpenLog Data section
void setup()
{//Begin Setup section
pinMode(statLED, OUTPUT); //set pin to output
pinMode(resetOpenLog, OUTPUT); //set pin to output
Serial.begin(9600); // initiate serial communication
//Reset OpenLog
digitalWrite(resetOpenLog, LOW);
delay(100);
digitalWrite(resetOpenLog, HIGH);
//Wait for OpenLog to respond with ‘<‘ to indicate it is alive and recording to a file
while(1) {
if(Serial.available())
if(Serial.read() == ‘<‘) break;
}
//Send three control z to enter OpenLog command mode
//Works with Arduino v1.0
Serial.write(26);
Serial.write(26);
Serial.write(26);
//Wait for OpenLog to respond with ‘>’ to indicate we are in command mode
while(1) {
if(Serial.available())
if(Serial.read() == ‘>’) break;
}
//send the open file
Serial.print(“Templog.txt\r”); //\r in string + regular print works with older v2.5 Openlogs
//Wait for OpenLog to return to waiting for a command
while(1) {
if(Serial.available())
if(Serial.read() == ‘>’) break;
}
// send the command to append the file
Serial.print(“append Templog.txt\r”);
//Wait for OpenLog to indicate file is open and ready for writing
while(1) {
if(Serial.available())
if(Serial.read() == ‘<‘) break;
}
//start process of setting clock time
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
} //End setup section
void loop()
{//Begin Loop section
if (millis()-prevmillis> DataDwell)
{//start if sections
TimeSection(); //displays the time
OpenLogData(); //saves the time and solar temp to the SD card
prevmillis=millis();
}// end if section
}//End loop section