Close

Storing a Double in EEPROM

A project log for Portable Altimeter Logger with Display

A portable altimeter that logs the relative height with a simple display to show max and current altitude.

sergSerg 12/30/2014 at 05:100 Comments

So I'm not sure if I'm supposed to be updating the project log this often but this is kind of fun so I'm doing it anyways. I got the BMP 180 to play nicely with the Pro Trinket without a problem. Storing the data was not as straightforward, however.

The chips EEPROM memory is 512 Bytes and is written 1 byte at a time. I'm using a double type form ( because its much more precise than an integer) which is 4 Bytes long. This means that in order to store a point in memory I must divide it up into four groups and then combine it when I need to read it. I thought this was going to be difficult but I found a simple functions that will help with this:

void EEPROM_Write(double *num, int MemPos)
{
  byte ByteArray[4];
  memcpy(ByteArray, num, 4);
  for(int x = 0; x < 4; x++)
  {
    EEPROM.write((MemPos * 4) + x, ByteArray[x]);
  }  
}

memcpy(1,2,3) takes the destination location, adresss of source and the size of an object to move in memory. Moving it to and from an array of 4 bytes makes this process simple.

I decided to store the altitude data on the Pro Trinket's EEPROM instead of an external memory to keep it simpler. This means that I only have 512 Bytes of storage available. So here's how much data I can hold:

About 2 hours of data at 1 sample per minute

About 1 Hour of data at 2 samples per min

About 20 Minutes of data at 6 Samples per minute

I opted for the 20 minutes of data since my flights don't last more than that.

Discussions