PulseMote.ino Question

Started by G550_Pilot, May 26, 2016, 12:24:31 AM

G550_Pilot

This is not specific to the PulseMote but since that is the sketch that I started with I was curious about something.

Basically the sketch writes the current water meter pulses to the EEPROM and then reads it back. In all of my testing to get it working correctly, I now have something like 5M gallons showing up...how can I reset that number to my actual meter reading (based on pulses)?

Thanks

Felix

#1
When EEPROM is virgin from factory it probably is all 1s hence it maxes out anything you read from it.
So you can either write your first struct to the eeprom as all 0s or just initialize the whole eeprom by writing 0s.
Something like:

for (int addr=0; addr <=1023; addr++)
  EEPROM.write(addr, 0);


---------------------

Actually if you think about it... the first time we read an max(unsigned long) from EEPROM. As soon as your counter increases, it will overflow to 0, so you will loose a pulse but the sketch "self-heals" or basically initializes the counter at that point. I remember this happening to me as well, but I didn't make any changes to the sketch since the sketch cannot know that it's running for the first time, unless we make an assumption that with every power cycle we reset the EEPROM which actually defeats the purpose of saving to EEPROM in the first place (ie we could just keep a RAM counter and simplify the sketch in that case).

So bottom line, you don't have to do anything, just issue a pulse or let a pulse happen and let the sketch save it back to EEPROM, that first save will go from 5M to 0.

G550_Pilot

Hi Felix -

That is exactly what it did, it reset to zero eventually, but it took quite a bit more than one or two reboots. What I would like to do is actually set it to the physical meter reading so that the value in the eeprom matches exactly what my meter reads.

Is there anyway to do a one time write of a specific value where it stores the pulsecount?

Thanks

Felix

Yes. Use the following function from the eepromex lib:

bool writeLong(int address, uint32_t value);

G550_Pilot