Go Down

Topic: Storage of Mileage and Trip info into memory (Read 715 times) previous topic - next topic


Hey all, long time lurker/tinkerer, and i havent posted in ages. In fact I got busy and distracted from Arduino for quite a while. But Im BACK. Now Im doing a custom gauge panel in a project, and have a 2650 MEGA running 4 16x4 displays, a 128x64 dot matrix, and a 1x16 display. I have all the inputs and screens working for all the data i want to see. my issue is the odometer, but i have an idea. I have never used EEPROM in Arduino before, so here goes...

The ECU im using puts out a 4000 pulse per mile signal, which i can easily read and display as a MPH. and break down into .1 mile display, but i want to save it. my idea is that, rather than constantly be writing to EEPROM, write either everytime the speed =0, like at a stop, or use a latched 5v relay to keep the arduino powered on, sense the voltage input from when the key is turned off, write the data, then kill the latch pin and shut the arduino down.

I also need to figure out how to pull the data back out when it comes back up. I need to add a button for a trip reset that has a 3 or 4 second hold time to reset. I know i need to read more on storage into and out of EEPROM, but addresses and such confuse me. I know enough to get through the basics and smash code together, so here I am. Once I get some code started and cleaned up ill post it up as well.


If you only have one variable to store, you can simply store it at eeprom address 0.

To save
Code: [Select]
unsigned long odoMeter = 3456;
EEPROM.put(0, odoMeter);

To retrieve
Code: [Select]
unsigned long odoMeter;
EEPROM.get(0, odoMeter);

If you have multiple variables, it's a little more complicated. You can use something like
Code: [Select]
#define AVGFUEL_ADDRESS (MAXSPEED_ADDRESS + sizeof(unsigned long))

The odometer data will be stored at address 0. The average fuel will be stored after that (it will be address 4 but is not really relevant). And the maximum speed will be stored after the average fuel.

The above assumes that the odoMeter variable is an 32 bit variable (e.g. unsigned long) and that the average fuel variable is a float (a float is also a 32 bit variable).
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up