Milestones, why we need to take a minute.

There is so much to do in life,  so much to to make, test, verify, improve, install etc.   that it is good to look back on goals completed and know that progress is being made.  I think that is why I like programming so much, it is near instant feedback to test and observe the results.  In my outside of night work hobby life I am finally going to get a machine out of my shop that has been there nearly a year.    That is going to free up a lot of physical space, but mentally I know it is going to be huge.  A constant reminder of time and money gone.  YEA!

On the project side I received a package I ordered from Yourduino.com to complete a phase of the OpenLog testing.  My plan has been to create a temperature recorder with a real time clock using a Arduino Uno  logging time and temperature data to OpenLog’s microSD card recorder.  Here is the finished code, that compiles and works.

/*
Temperature and Time recorder test

This code records time and temperature to a microSd card, this is a test program to prove the ability and
allow the code to be used in other programs as part of a larger code development

A thermistors is attached to analog pin 0
The Real time clock SDA pin is attached to analog 4, the RTC SCL pin is attached to analog pin 5

The circuit:
Arduino Digitial Pins
0 RX to MicroSD TX
1 TX to MicroSD RX
2 to MicorSD GRN
3
4
5
6
7
8
9
10
11
12
13

Inputs
* Thermister, Analog in 0
* RTC SDA, Analog pin 4
* RTC SCL, Analog pin 5

Created 9/10/12
http://www.frugaltinker.com

*/
#include <math.h> // include the library code for thermsiter functions
#include <Wire.h>
#include “RTClib.h”

RTC_DS1307 RTC;

// define I/O pins

// define constants for clarity

// define variables
int statLED = 13;          //toggles LED
int resetOpenLog = 2;      //reset OpenLog

int hour = 0;              // clock hour
int minute = 0;            // clock minute

// the following variables are long’s because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

unsigned long prevmillis = 0;     // prevmillis
long DisplayDwell = 7500; // dwell time of 7.5 secs

//define function to calculate the temperature in fahrenheit for Analog pin 0
double Thermister(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 OutsideTempSection() {// outside temp section
Serial.print(Thermister(analogRead(0))); //print to the lcd should be the Outside temp if thermistor is hooked up properly
Serial.print(“, “);
}// end outside temp 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
if (hour>=13)              //PM Section
hour=hour-12;           //printed hour is the hour
Serial.print (hour);          //prints the hour
Serial.print (“:”);           // prints a colon
if (minute<10)             //adds a “0” if the time is single digit
Serial.print (“0″);
Serial.print(minute);          //prints minuts
hour=now.hour(),DEC;       //get the hour from the RTC chip
if (hour>=12)   // prints pm
Serial.println (” PM”);
if (hour<12)                       // prints am
Serial.println (” AM”);
}// end time function

void setup()
{//Begin Setup section
// pinMode(ledPin, OUTPUT);
pinMode(statLED, OUTPUT);
pinMode(resetOpenLog, OUTPUT);

Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
Serial.begin(9600);             //initiate serial communication and define baud rate
delay (1000);                   //delay 1 sec for the data logger to begin
//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;
}

} //End setup section

void loop()
{//Begin Loop section
if (millis()-prevmillis> DisplayDwell)
{//start if sections
OutsideTempSection();    //checks and displays the outside temp section
TimeSection();           //displays the time
prevmillis=millis();
}// end if section

}//End loop section

 

 



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s