1

I would like to store temperature readings in eeprom, the value from -55.00 to 125.99. What is the most space efficient way to store these numbers with two significant digits along with epoch timestamp?

Thanks

5

My best off-the-top-of-my-head figure is 6 bytes.

4 bytes for the timestamp (assuming a 32-bit value). Two byte for -32768 to +32767.

Multiply the temperature by 100 to make it into the integer range -5500 to +12599. That then fits comfortably inside a 16-bit signed integer.

However, there are other tricks you can use.

For instance, if you know the time of one reading you don't need to store the time of the next - only how much later it is. One byte can then store up to 255 "whatevers" later than the previous entry - be that seconds, minutes, hours, whatever.

Similar with the temperature. You can just store the difference from the previous reading as a single byte if you know that successive readings will never deviate by more than +/-1.27 degrees.

Also, you can check to see what the last saved temperature was, and only save a new temperature if it has changed from before.

Another thing is the resolution of your data. You say 2 decimal points, but if the values are all multiples of 0.05 then what is the point of storing at 0.01 resolution? Just store how many 0.05s there are (divide by 0.05) then multiply it out again afterwards to get the original temperature. Most useful when coupled with a temperature difference to increase the storage range.

There's many tricks, you see, and which work best depend exactly on what you want to do with the data.

  • Wow, thank you so much! this is gold, I really like the temp diff and the resolution ideas. – Du D. Oct 13 '15 at 15:18
  • Multiply the temperature by 100, not 10 ! – CharlieHanson Oct 13 '15 at 21:27
  • Oops, typo there. – Majenko Oct 13 '15 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.