Ensuring data variable continuity or persistence

Thread Starter

quique123

Joined May 15, 2015
405
Hi guys,

This is a concept question, not so much a specific question yet. I have fiddled around with both a current sensor (SCT-013) and a water flow sensor (https://www.adafruit.com/product/833). Meaning I have successfully set up an arduino to read their data and verified that it was "correct". (within error)

Now Im ready to have that data read periodically (maybe 1x every hour) and sent to a db or something in order to ensure continuity and persistence in case of a power out.

In the current code I do something like this:

#include "EmonLib.h"
EnergyMonitor emon1;
char ssid[] = "myssid"; // your network SSID (name)
char password[] = "mypwd"; // your network key
void setup(){
Serial.begin(9600);
emon1.current(1, 111.1); // Current: input pin, calibration.111.1
}
void loop(){
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(Irms*120.0); // Apparent power - from 230 to 120
Serial.print(" ");
Serial.println(Irms); // Irms
}​

So the value is stored in a local variable. Same as in my water meter code. In both cases the variables are written to the serial constantly. I know how to post the data to the web and stuff but if power goes out, the Arduino restarts but the data starts from zero again. So if I wanted to log water or power consumed the final data would be incorrect if power ever went out. How do I solve this issue?
 

djsfantasi

Joined Apr 11, 2010
9,163
  1. Use a data logger instead of an Arduino
  2. Use an SD card shield and write your values to disk SD card)
  3. Write the data values as well as sensor data to the SD card when the arduino restarts, read through the file and keep the last recorded data values
  4. Use battery backup to continue powering if external power goes out.
 

Thread Starter

quique123

Joined May 15, 2015
405
Thanks so much! Ok so:

1. Data Logger, not sure what this is specifically. Do you have a link to a device like this?
2. SD card shield or module Im sure I can get and work with. My favorite so far.
3. Sounds like the same as #2
4. Sounds interesting but Ive never worked with a power backup circuit. Ive worked with solar charging lipo battery circuits so Im guessing there are modules that will sense power loss to the mcu and flip over to current from an alternate source.
 

djsfantasi

Joined Apr 11, 2010
9,163
Thanks so much! Ok so:

1. Data Logger, not sure what this is specifically. Do you have a link to a device like this?
2. SD card shield or module Im sure I can get and work with. My favorite so far.
3. Sounds like the same as #2
4. Sounds interesting but Ive never worked with a power backup circuit. Ive worked with solar charging lipo battery circuits so Im guessing there are modules that will sense power loss to the mcu and flip over to current from an alternate source.
  1. Search for “Data Logger”
  2. Great!
  3. Same as #2, but you’re recording additional data that can be read on a restart, restoring the variables before the restart to maintain continuity
  4. The Arduino already has the necessary circuitry. Use the USB port for one power source; use the Vin pin for the second.
 

Thread Starter

quique123

Joined May 15, 2015
405
I got a lot of arduino projects on HOW to make a data logger, is that what you meant, make a separate device used as a data logger or do you mean an actual device that can interface with arduino via i2c or spi and actual record data in it?

The arduino option is now better. I didnt know the arduino could use both power inputs at the same time. Thanks again!
 

djsfantasi

Joined Apr 11, 2010
9,163
I got a lot of arduino projects on HOW to make a data logger, is that what you meant, make a separate device used as a data logger or do you mean an actual device that can interface with arduino via i2c or spi and actual record data in it?
I actually meant a separate device. But that option doesn’t appear to be the best.

The arduino option is now better. I didnt know the arduino could use both power inputs at the same time
Yes. The Arduino has circuitry that chooses the best power source.
 

MrSoftware

Joined Oct 29, 2013
2,202
Example data logger: https://www.sparkfun.com/products/13712

Also you can store some values in EEPROM or Flash on the processor itself, just be sure to read up on how many times it can be re-written before failure to see if that fits your needs. For example, I believe EEPROM is good for 100,000 erase/writes. You can do things to stretch that out, like increment the address that you write to with every write, or write only every 10th reading, etc..

https://www.arduino.cc/en/tutorial/memory
 
Top