Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Tuesday, April 30, 2013

Save State in Arduino EEProm Across Resets

I am back to playing with the Arduino and am remembering just how uncomfortable I was working in "C" so long ago.   'Def a brain teaser for me compared to Python or PHP.

So anyway, here is an implementation of a couple routines with one that saves a string in the onboard EEProm on the Arduino and then a second that reads it back.   In my next iteration I will add a CSV parser such that if you put two distinct variables into the EEProm, separated by commas, you will get an array of two variables back from the read.

Here is what the serial console displays when this sketch is run:
--Starting
--String to Save on EEProm
2.222,4.44
--String Retrieved from EEProm
2.222,4.44
--All Done

Here is a LINK to the sketch itself.  There is really not that much to this example but the time it took me to relearn a little about array handling in "C" made this more of a challenge than I expected (for my old brain).

Note that I wrote my own floating to string conversion function as I was not thrilled with the way that dtostrf works.   Even this trivial routine took my old brain more than a couple minutes to write...as we hear the clanking of gears shifting.  --Updated to reflect that even after all that I had an error in the code that I just corrected.   I am struggling with working at the pointer level!

Another update - Found this posting on the Arduino Forum with a nice technique for using the EEProm memory to store anything with one operation.

No comments:

Post a Comment