The view from April, Daylight savings time adjustment for your RTC

The boiler has worked flawless all winter, I am happy with the software and hardware but with all things mechanical there is room for improvement. I have just started my 7th ton of pellets. And I really don’t want to get into my 8th and don’t think I will have to, especially if I institute some energy conservation in the software. This is the time of year that I would normally burn what my grandmother called a “trash fire”. In her case it was some cardboard boxes from the trash and maybe an odd shaped piece of wood or two. Just enough for 3-4 hours in the evening, letting it burn out overnight since the days get up to 40°F or 50°F there’s no need for more fire than that. Later in the month most of the nights will be above freezing. But I still want to light the boiler in the evening mostly for the hot water and then turn it off at 2-3 am, so I wrote that into the software and it has gotten the consumption down to 1-2 bags per day. I also added a function in the software to change the real time clock for Daylight savings time and back automatically. It’s not fully tested but I think it will work OK.

void DaylightSavingsSchedule(){//start function
if (Year ==2013 && Month ==11 && Day ==2 && hour ==2&&DaylightTest ==0)//fall back an hour
FallBack();
if (Year ==2013 && Month ==11 && Day ==4 && hour ==2&&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2014 && Month ==3 && Day ==9 && hour ==2&&DaylightTest ==0)//spring forward an hour
SpringForward();
if (Year ==2014 && Month ==3 && Day ==10 && hour ==2&&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2014 && Month ==11 && Day ==2 && hour ==2&&DaylightTest ==0)//fall back an hour
FallBack();
if (Year ==2014 && Month ==11 && Day ==3 &&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2015 && Month ==3 && Day ==8 && hour ==2&&DaylightTest ==0)//spring forward an hour
SpringForward();
if (Year ==2015 && Month ==3 && Day ==9 && hour ==2&&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2015 && Month ==11 && Day ==1 && hour ==2&&DaylightTest ==0)//fall back an hour
FallBack();
if (Year ==2015 && Month ==11 && Day ==2 &&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2016 && Month ==3 && Day ==13 && hour ==2&&DaylightTest ==0)//spring forward an hour
SpringForward();
if (Year ==2016 && Month ==3 && Day ==14 && hour ==2&&DaylightTest ==1)//reset flag
DaylightTest =0;
if (Year ==2016 && Month ==11 && Day ==6 && hour ==2&&DaylightTest ==0)//fall back an hour
FallBack();
if (Year ==2016 && Month ==11 && Day ==7 &&DaylightTest ==1)//reset flag
DaylightTest =0;
}//end function

void SpringForward(){//start function
DateTime now = RTC.now(); //get the data from the RTC
now =now.unixtime()+3600; //subtracts an hour from the time
RTC.adjust(DateTime(now.unixtime())); //resets the time to an hour earlier
DaylightTest =1; //flag variable so it won’t go back in time continously
}//end function

void FallBack(){//start function
DateTime now = RTC.now(); //get the data from the RTC
now =now.unixtime()-3600; //subtracts an hour from the time
RTC.adjust(DateTime(now.unixtime())); //resets the time to an hour earlier
DaylightTest =1; //flag variable so it won’t go back in time continously
}//end function


I am considering adding Ethernet capability

By adding Ethernet capability I can write the data I am currently collecting on the micro SD card to a browser directly. This means I could pull up Firefox and go to my Arduino’s IP Address and see the data.  This will give me the ability to read the data from anywhere on my home network as well as anywhere I can get internet connectivity, potentially allowing me to review data from a smart phone remotely. Additionally I could control relays from a remote location as well. But for now the ability to ease the data collection and monitor the process remotely will be a great first step. First I have to buy an Ethernet shield.  For those of you not familiar with Arduino this means an additional plug-in board that will stack on top of the Arduino pins.

Ethernet Shield

Ethernet Shield

Here’s a picture of just the Ethernet shield, the connection point you see on the front is the plug-in point for the Ethernet connection. This is a RJ-45 connector. I was able to get a 100 foot Cat 5 with installed RJ-45 connectors for $27 at Home Depot.

Ethernet Shield stacked on an Arduino UNO, note upper connection is the RJ-45 Ethernet connection

Ethernet Shield stacked on an Arduino UNO, note upper connection is the RJ-45 Ethernet connection

At present I have already have a prototype shield plugged into my Arduino Uno. This allows me to easily disconnect and update the Uno without disturbing any wiring connections. There are quite a few wiring connections for the RTC or Real Time Clock, the LCD display, the outside temperature thermister, the boiler water tank thermister, the Auger Feed pipe thermister as well as Relays to turn on the Auger motor and boiler tank water circulator. But when I attempted to plug in a prototype shield into the Ethernet shield there was interference with the RJ-45 connection point. The prototype shield would have grounded itself on the metal so I have ordered Stacking headers to extend the height above the shield. More when the headers arrive.


Work out the software bugs to test burn, Step 8 of a DIY Record

Over the summer and fall I have written and tested a number of programs to have the building blocks of a working program.  I knew the key this year would be the ability to log data.  Of course to log data and have it mean something you have to have good data.  So I spent several days working the bugs out of OpenLog, which works but I would not recommend.  I also spent some time figuring out a combination of moving averages which resultx in stable data.

Of course the integration process was a train wreck.  The arrays used for moving average data smoothing were declared wrong so that bug had to be found and fixed.  The Serial LCD needed to be replaced, and my soldering iron wouldn’t work.    A few of the functions are timed and there were some issues with those functions.  The code for Open Log was not robust enough, once I worked out all those issues, which took most of the weekend, it is finally ready to test.

I had a plow in the shop for repair and soaked up the spilled hydraulic fluid off the floor with some sawdust, actually pellets that got wet.  So the hydraulic oil soaked sawdust is in the hopper to be burned.  It’s burning now, so tomorrow I should have some excel data which will help me make decisions to improve the software.  At this point I am not sure it will be valid however, it is really taking a long time to come up to temperature with the sawdust.   Another data point.

Boiler hooked up and burning for the first time

Boiler hooked up and burning for the first time


Radio data transfer!

I have been working through some of Robert Faluidi’s excellent book ” Building Wireless Sensor Networks with Zigbee, Xbee and Arduino Processing”  Working with these radios has been a lot of fun.  The book is a great introduction to the basics and gives you a great idea for what can be done with a little imagination.

My plan for the chip boiler is to continue building and testing blocks of code that will be all integrated into the boiler control program at least at some point for some of the testing period.  Last winter the boiler ran for approximately a month and  a half.  In that time there were many starts and stops which made me wish the Arduino could provide better data for the feedback of the program itself, hence the data logging program just tested.

A second desire is the real time temperature monitoring of the boiler water as well as the auger feed pipe temperature.  Hence the need for wireless radio temperature monitoring.    That is what the wireless data transfer will accomplish.  I am picturing a simple box with a LCD screen to display the data running on a 9v battery.  Video to follow soon. Thanks as always for reading.


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

 

 


OpenLog partially tested

Well 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

 

 


OpenLog Firmware updated and tested

OpenLog is a data logger from SparkFun electronics that is touted as being easy to use and a reliable writer to a microSd card.  I haven’t found that to be true, I think it is a pain in the a** but maybe that’s the experience more than the actual product.  I ordered the data logger in January and got busy and didn’t have the time to use it so I set it aside.

Really the only reason I ordered it was because I could not get GoBetwino, a Freeware Arduino Data logging software program to work.   The GoBetwino program uses a USB connection to a computer connected to the Arduino to log to a file on the PC.  A great concept that I tested and worked fine on the desktop machine.  However on the laptop that I was using to make changes to the Arduino controlling the boiler  in the shop it didn’t work.  It seemed easier to come up with a standalone solution rather than troubleshoot the USB connections, the power managment issues with the Laptop etc.  So I bought the data logger.

As I wrote in an earlier post since the time of my purchase of the OpenLog board it was recommended to update the firmware, this required updating the board with a FTDI board that accepts the USB connection from the PC to update the firmware, after 2-3 hours of frustration this task is finally completed.  The main problem being Windows XP didn’t seem to recognize the FTDI board and assign it a com port but finally was able to find the correct driver and download the firmware.

I ran the test sketch, pulled the micro SD card and reviewed the data.  The board  did log the data correctly so the next step is to write a function that writes temperature data to a file with a time stamp.  Since I have an Arduino on my desk with a real time clock chip that measures the outside temperature  as well as the temperature of a solar hot water storage tank this would seem like a perfect application to test.   After testing the function in that application it will be easy to modify the function for the monitoring of the boiler function.  I prefer to write the code in functions and call the functions from the main body of the loop.  This makes the code modular and easy to reuse.  I comment very carefully and probably over comment, but I personally prefer to make the code painfully simple to understand on the assumption I may not look at the code again for a few years.  I am hoping you will comment as well since your comments will no doubt improve the code.

I will post the function when I complete it.  Thanks for reading.