Go Down

Topic: efficient eeprom storage (Read 1 time) previous topic - next topic

DirtGambit

Hi, Just now im reading and writing to serial very well but id like to add a time stamp to the data im storing. I store Temp, RH, CO2, and a boolean var for lights on or off, just now im going from 0x50 + 0x850 for temp and 0x851 - 0x1010 for rh and so on so forth for the rest of the vars, that gives me about 2016 points of data or there abouts, now i need to timestamp everything id like to store the whole lot as some sort of a string with time and date eg: 21,75,1500,1,9,1,2011,15,37

what the best way to efficiently store a string like this in an indexable sort of fashion using eeprom.

Ive used structs to store hex addresses in eprom using a library but you need to know the starting address, if the string changes length by any digits then it wont take up the same space on eprom as the previous reading stored, or maybe allow more than i need to store my string and count every reading from there. Just want to know how people have done this.

Regards

Grumpy_Mike

One way round this is to use a "linked list". This is where a byte in the header points to the next data entry.
http://en.wikipedia.org/wiki/Linked_list

robtillaart


YOu could make a struct which includes the timestamp etc and store things in binary format, far more efficient

Code: [Select]
struct data
{
  uint32_t Sec;      // seconds since startdate of some clock 1-1-2000 or so
  uint16_t Temp;   // enough for quite some precission
  uint16_t RH;       // idem
  uint16_t CO2;     // idem
  uint32_t Lights;   // 32 boolean flags
  uint16_t filler;     // for future expansion
}


This struct is 16 bytes long, so you can address it like an array as record
  • has EEPROM address 16 times X  which equals x << 4.
    Furthermore as most EEPROM pages are a multiple of 16 they fit very nice within page boundaries ==> thats why I added the filler in the first place.

    Almost twice as compact as your string, so twice as many records in your EEPROM ..., it needs some pack and unpack code though...

    hope this helps.



Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

DirtGambit

@Grumpy_Mike, ive used linked lists in c++ and java before and it seems logical to do it this way but Ive never used linked lists in arduino and Im wondering if using linked lists will take up much more space on eeprom.

@Rob, That seems the best way to go about it, struct everything up plus like you have identified the filler makes everything fit nicely, Im unsure about the date and how it fits into things, will I have to write alot of code to format the data when packing/unpacking, the clock goes from 1,1,2000 so to get todays date in seconds Id have to find out how many seconds have passed since then which is 379296000 i think but thats basing everything on 365 days a year which some are not.

thanks

Grumpy_Mike

Quote
Im wondering if using linked lists will take up much more space on eeprom.

Well the link takes up an extra byte.
The alternative is to search through the memory each time counting the string terminator bytes.

robtillaart

Quote
will I have to write alot of code to format the data when packing/unpacking, the clock goes from 1,1,2000 so to get todays date in seconds Id have to find out how many seconds have passed since then which is 379296000 i think but thats basing everything on 365 days a year which some are not.

thanks


just download a library of a RTC like the DS1307 - https://github.com/adafruit/RTClib - contains all the code you need :)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up