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
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityMy 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.