I'm using arduino code to create a digital gas gauge. Basically a flow sensor in the fuel line emits pulses which have been calibrated to be proportioned to a volume reading. That volume is then subtracted from a constant representing the gas tank's full volume. This "difference" is then displayed on an HT16K33 display. All of that works fine, I am just having difficulty with an on/off switch. Since the circuit runs off of the car battery and needs to stay on constantly so that the difference reading is not lost between power cycles, I want to turn off the display and reduce the mAh draw. (I am aware of EEPROM but its short hardware lifetime will not work for my application, any other non-volatile memory suggestions?) I have an SPST switch connected to Pin 3 and GND, however whenever I flip the switch sometimes the display goes on/off and other times it randomly flashes over constant or irregular time intervals. Very new to code so any debugging is appreciated.
You could use a button telling that power will be turned off. Then data are saved in EEPROM. At power up the EEPROM data are read and used.
Cutting off the display Vcc will cause ghost powering via the signal lines. The result is unpredictable.
You may need to protect against pulse getting updated half way through reading it in this line. Unless you are using an Arduino based on a 32-bit chip.
Thanks for the help, the UNO R3 does not come with an internal I2C FRAM right? What module and library would you recommend that would give me the most about of rewrite cycles? What library would you recommend for the button?
Thanks
Could you type up some example code please, I've had difficulty understanding what is needed to get the EEPROM to read and write the "difference" value.
Also, it's not terribly difficult to arrange it so the Arduino knows that power is soon to be lost, giving it enough time to throw some data into EEPROM.
FRAM is good, so it's down to what kind of fun you want to have.
I googled
arduino write eeprom before loss of power
and suggest to you to do the same. Here's a thread that goes into some detail, see what you think:
and another
The DS1307 is a lousy RTC, but it does make available battery backed RAM of a handful of bytes, totally available for any use you might find for them, yet another kind of fun…