This program supports an ongoing series of DIY 'Classroom Logger' tutorials from Edward Mallon & Dr. Patricia Beddows at the Cave Pearl Project. The idea is to provide a starting point for student projects in environmental monitoring courses and/or thesis level research.
The tutorial for this logger: The e360: A Classroom Data Logger for Science
has a companion video 2-Module Data Logger Build Video (90min w Commentary)
>//++++++++++++++++++++++++++++++++++++++++++++++++++++
>// STEP1 : #include libraries & Declare Variables HERE
>//++++++++++++++++++++++++++++++++++++++++++++++++++++
If all you do is enable the supported sensors via defines at the start of the program you won't have to deal with the low-level storage details.
However to add new sensors you'll need to understand the I2C transaction that transfers those sensor readings into the EEprom at the end of the main loop. This involves dividing your sensor variables into 8-bit pieces and adding those bytes to the wire transfer buffer. This is accomplished with bit-math operations or via the lowByte & highByte macros. The general pattern when sending bytes to an I2C EEprom is:
Wire.beginTransmission(EEpromAddressonI2Cbus);
Wire.write(highByte(memoryAddress));
Wire.write(lowByte(memoryAddress));
loByte = lowByte(SensorReadingVariable); Wire.write(loByte);
hiByte = highByte(SensorReadingVariable); Wire.write(hiByte);
add more Wire.write statements here as needed
You can ONLY add a total of 1, 2, 4, 8 or 16 DATA bytes to the I2C transaction. Powers of two increments are required because the recorded data must align with page boundaries inside the EEprom.
Wire.endTransmission();
The key insight here is that the wire library is only loading a memory buffer until Wire.endTransmission() is called. So it does not matter how much time you spend doing calculations, or slicing the variables, so long as you don't try and start another I2C transaction while you are still in the middle of this one. Once that buffer is physically sent over the wires, the EEprom enters a self-timed writing sequence and the logger reads the rail voltage while the CR2032 is under load.
The data download function in setup retrieves those separate bytes and concatenates them back into the original integers - so the sequence of operations in the sendData2Serial function -STEP6- must exactly mirror the byte-order used to load the EEprom in the main loop.