Skip to content

A classroom logger developed for the e360 Instrumentation & Field Methods course at Northwestern University. This 2-Module logger includes mini-breadboards and runs on a Cr2032 coincell battery.

License

Notifications You must be signed in to change notification settings

EKMallon/e360-Classroom-Data-Logger-2023

Repository files navigation

banner image 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)

The code has support for a built-in NTC / LDR combination, Bmp280, BH1750, and PIR sensors. These are enabled / disabled by uncommenting define statements at the beginning of the code. Each sensor enabled after the single-byte LowBat & RTCtemp defaults contributes two additional bytes per sampling event because every sensor reading gets stored in a 16-bit integer. The total bytes per saved per record must total 1, 2, 4, 8 or 16 only. Modifying the logger base code for a new type of sensor requires edits only at the areas indicated by call out numbers on the following flow charts. These are labeled with comments: STEP1, STEP2, STEP3, etc. so you can locate those sections with the Find function in the IDE. They are surrounded by rows of ++PLUS++ symbols:
>//++++++++++++++++++++++++++++++++++++++++++++++++++++
>// STEP1 : #include libraries & Declare Variables HERE
>//++++++++++++++++++++++++++++++++++++++++++++++++++++

image 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. image

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.


About

A classroom logger developed for the e360 Instrumentation & Field Methods course at Northwestern University. This 2-Module logger includes mini-breadboards and runs on a Cr2032 coincell battery.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages