Easy-to-use, flexible data-logger sketch optimised for battery life
Moderators: adafruit_support_bill, adafruit

Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Thu Jan 20, 2011 10:33 pm

I have developed an easy-to-use, flexible sketch for use with Adafruit's Logger Shield (http://www.ladyada.net/make/logshield).

Features:
  • Optimised for battery life by utilising the ATmega's power down sleep mode. This extends battery life by many times... I can now run my data logger on a single 9V NiMH battery and keep it topped up with a solar panel.
  • Any number of analog pins
  • Any time step
  • Provides for sensor calibration using a simple linear model (i.e. to convert from analogRead value to whatever you want)

You can download it here:
https://sites.google.com/site/toddsstuffnthat/arduino-code-1/DataLogger.pde?attredirects=0&d=1

It currently does not handle digital inputs, but this would be easy to change. Please let me know if you use it and/or can think of any improvements. Enjoy!
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by adafruit on Thu Jan 20, 2011 11:00 pm

wow fantastic! thank you! :)
User avatar
adafruit
 
Posts: 11672
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Fri Jan 21, 2011 7:27 pm

It seems there is an issue with my sketch, but I'm not yet sure where... I tested it yesterday and it logged correctly for the first 265 logs (at one minute time step), but then the time jumped forward from 21/01/2011 19:04:21 to 29/04/2043 17:31:44. Perhaps I have invented a time machine ;)

For the remaining 189 logs (after which I switched it off) the time remained unchanged at 29/04/2043 17:31:44 (unix time = 2313941504) and the analog inputs remained constant +/-1.

I will look into it, but if anyone has any ideas, I'd love to hear them. Thanks!
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Sat Jan 22, 2011 8:00 am

Okay, I've improved the sketch substantially. It now logs any number of digital inputs, has better sleep timing, and (hopefully) doesn't crash.
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Wed Jan 26, 2011 5:41 am

I've now had this running for several days with no issues, so it seems I've ironed out the bugs. I hope people find it useful.
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by adafruit on Wed Jan 26, 2011 11:05 am

its appreciated! we do need to adapt the logger to use the latest SD library. its on a long list of ToDos :/
User avatar
adafruit
 
Posts: 11672
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by gotflipped on Fri Feb 11, 2011 4:19 am

When you mention any number of analog pins, are you referring to the analog pins beyond A0-A5? The one's not connected with the shield? Sorry if I'm misunderstanding this. Reason being is that I have an Arduino Mega2560 and I would somehow like to use the A6 and above analog inputs with the datalogger for more analog sensors.
gotflipped
 
Posts: 7
Joined: Wed Dec 01, 2010 1:14 am

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by SwashBuckler on Sun Feb 13, 2011 5:55 pm

Hello!

I am new to the Arduino environment and was curious how difficult it would be to use your code to store position information from an accelerometer. I have this one working without data logging : http://arduino.cc/en/Tutorial/Memsic2125?from=Tutorial.AccelerometerMemsic2125

I have the adafruit data logging shield assembled, and according the the SD card test at http://www.ladyada.net/make/logshield/sd.html my SD card is working too! All I have left is to export the readings to the SD card so that I can open it in Excel.

Your help is greatly appreciated!!

Thanks!
SwashBuckler
 
Posts: 2
Joined: Sun Feb 13, 2011 5:47 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Mon Feb 14, 2011 4:24 pm

When you mention any number of analog pins, are you referring to the analog pins beyond A0-A5?

Sorry, only the analog inputs supported by the shield can be used with my sketch.
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Mon Feb 14, 2011 4:36 pm

@SwashBuckler,
Your problem may be that both the sketch that comes with the AdaFruit DataLogger Shield and my sketch both use (as default) an EXTERNAL analog to digital converter reference voltage (Aref), whereas the accelerometer tutorial does not.

You can use the internal Aref by changing this line in my sketch:

const boolean UseExternalARef = true;

to this:

const boolean UseExternalARef = false;

Alternatively, you can connect 5V to the Aref pin on your Arduino.

If this is not the problem, then please describe what problem you are experiencing.
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by toddh on Tue Feb 15, 2011 3:38 am

Since personal messaging with SwashBuckler, I've found that the challenge he was facing is that the value to be datalogged is neither a standard digital input or standard analog input, but a pulsed digital input that requires the pulseIn() function to convert it to a meaningful value. I'm giving SwashBuckler support to adapt my code to suit his application

I can revise my code to handle any number of pulsed digital inputs, but I won't bother doing this unless requested. So, if you want it, speak up!
toddh
 
Posts: 7
Joined: Mon Jan 03, 2011 8:29 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by devans on Tue Feb 22, 2011 6:04 am

Hi toddh,
I'm keen to try the sleeping element that you have developed in to a device I am currently working on in order to better the battery performance. I am currently using a recharchable lo-poly 1500mAh battery pack and only get 5 hours of logs when fully charged.

One of the sensors I am measuring is an anemometer which requires a digital interrupt in order to count revolutions. would you know if putting the board to sleep prevents the interrupt from firing?
I will give it a try later this evening but was curious to see if you already knew the answer to this.

Also, what size solar panel are you using to charge your device during the day?

Thanks
Dan.
devans
 
Posts: 6
Joined: Thu Feb 17, 2011 9:30 am

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by andywatson on Tue Mar 01, 2011 3:47 pm

I just uploaded the sketch from link in the first post of this thread. While it seems to be logging data correctly to the SD card, the Uno is still pulling 26ma of current during the minute between sensor readings. It seems like it should be much lower, right? I did not connect the LED's on the SD card shielt, but green LED on the uno is still lit, so I'll probably unsolder that one to save a little power, but I still don't think >20ma is a very good lower power mode. Has anyone measured the current of their sleeping uno/datalogger setup?
andywatson
 
Posts: 28
Joined: Tue Feb 15, 2011 11:40 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by flak1 on Wed Jul 20, 2011 3:08 pm

hi my name is gaby, I'm using your code, but I don't know how o where I have to connect the Vref pin
I'm using a system with a transistor and a relay, this system receives a pulse from a digital port, this pulse turns on the relay and at the same time turns on an amplifier for a pressure transducer just before to sample, and turns off the system just after to take the sample and stores the sample in SD card, but in the serial monitor there is only a reading of 0
I measure the pin Vref only in the uno board and it measure 5V not connected
Last edited by flak1 on Wed Jul 20, 2011 3:11 pm, edited 1 time in total.
flak1
 
Posts: 1
Joined: Wed Jul 20, 2011 2:39 pm

Re: Easy-to-use, flexible data-logger sketch optimised for battery life

by albertogt on Thu Jul 28, 2011 2:50 am

Hi there toddh!!

Great job you did for the community with this code. I have been using it quite a lot without problems. :D

But recently, I have been working on a remote water pressure measuring device that needs battery life optimisation. It uses a MPX2010DP differential pressure transducer and a 12V 1.2 Ah battery and it only lasts about 5 days :( .
I have implemented a circuit to monitor the data aquisition, battery voltage as well as a solar panel voltage generation with your code.

I need to log data roughly every 1, 10, 60 min and 24 hrs in some cases.

Looking into the code and the debugging in the serial I found out what seems to be the problem.

When setting up the

Code: Select all | TOGGLE FULL SIZE
const int StepTime            = 60;


Say logging every 1 min the result in the serial/file debugging looks like this


Code: Select all | TOGGLE FULL SIZE
Logging to: LOGGER18.CSV
Date/time, MPX, Solar-Panel, Batt
1311819062,Sleep for,0.50 ***
"2011/7/28 2:11:3",592.00,627.00,682.00
1311819063,Sleep for,8.00 ***
1311819071,Sleep for,8.00 ***
1311819079,Sleep for,8.00 ***
1311819088,Sleep for,8.00 ***
1311819096,Sleep for,8.00 ***
1311819105,Sleep for,8.00 ***
1311819113,Sleep for,8.00 ***
1311819121,Sleep for,1.00 ***
1311819122,Sleep for,0.50 ***
"2011/7/28 2:12:3",592.00,627.00,682.00



So from this I get that the longest sleep time is actually 8 secs. Then when setting logging times to say 1 hr (3600 sec) the code makes the Arduino wake up about 450 times without any need of it.

Checking out the last part of the code namely the:


Code: Select all | TOGGLE FULL SIZE
// GoToSleep //
// SetupWatchdog //
// ISR //
// GetSleepTimeIndex //

and
Code: Select all | TOGGLE FULL SIZE
// GetSleepTime //


parts I see these are the ones control sleep timing and watchdog waking up.

I understand that the
Code: Select all | TOGGLE FULL SIZE
// SetupWatchdog //
and
Code: Select all | TOGGLE FULL SIZE
// GetSleepTimeIndex //
code portions control the TimeIndex.
But have not been able to succesfully modify the code according to my needs.

What do I need to change in order to extend the actual sleeping times of the Arduino. Say 1, 10, 30, 60 min and 24 hrs??

Thanks in advance.
:wink:
albertogt
 
Posts: 5
Joined: Wed Mar 23, 2011 8:13 am