Tag Archives: Arduino

State memory for Wall-E2 – writing telemetry packets to FRAM

posted 28 September 2018

In previous posts, I have described my effort to give time, memory and relative heading super-powers to Wall-E2, my autonomous wall-following robot.  This posts describes a helper class I created to allow Wall-E2 to periodically write its current operating state to FRAM memory, for later readout by his human master(s), and a small test program to verify proper operation of the helper class.

My current conception of Wall-E2’s operational state consists of the current time/date, its tracking mode and submode, and the current left, right, and forward distances, and the current battery voltage. These parameters have been encapsulated in a CFramStatePacket class with methods for writing state packets to FRAM and reading them back out again.  The complete code for this class is shown below. Note that all the class code is contained in just one file – FramPacket.h.  There is no associated .cpp file, as I didn’t think that was necessary.

To test my new CFRAMStatePacket class, I created a small test program that periodically writes simulated state packets to FRAM using the helper class methods, and optionally (if the user creates an interrupt by grounding the appropriate pin) reads them back out again.  This program is designed to run on an Arduino Mega 2560.  If a Uno is used, the interrupt pin number would have to be changed.

The test code also looks for a low on the CLEAR_FRAM_PIN (Pin 3) on startup.  If it finds one, it will clear NUM_FRAM_BYTES_TO_CLEAR (currently 2000) FRAM bytes and then read them back out again, byte-by-byte.  Otherwise, the program will continue storing state packets where it left off the last time it was powered up.  Here’s the test code:

And here’s some output from a typical run: