![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Data log for logging enviornmental, process and system state to FRAM or EPROM chips that do not have support for a file system. Includes support for multiple record types, evolving record types, automatic date and time stamp and copying contents to serial. Will soon support journaling to micro SD file system. We always log to fram first for speed and power conserfaction then copy in bulk to SD cards when we have charging power available.
Flexible Data Logger Example Use and Test Code
Detailed Documentation
See home page for data log library https://developer.mbed.org/users/joeata2wh/code/data_log/
License
By Joseph Ellsworth CTO of A2WH Take a look at A2WH.com Producing Water from Air using Solar Energy March-2016 License: https://developer.mbed.org/handbook/MIT-Licence Please contact us http://a2wh.com for help with custom design projects.
main.cpp@0:0cfc06f9f18c, 2016-03-30 (annotated)
- Committer:
- joeata2wh
- Date:
- Wed Mar 30 21:44:52 2016 +0000
- Revision:
- 0:0cfc06f9f18c
- Child:
- 1:58f86fb1fb22
data log test and sample use code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeata2wh | 0:0cfc06f9f18c | 1 | /* xj-data-log-test-and-exmple.c |
joeata2wh | 0:0cfc06f9f18c | 2 | Shows basic usage of dat_log library and |
joeata2wh | 0:0cfc06f9f18c | 3 | performs some basic tests. |
joeata2wh | 0:0cfc06f9f18c | 4 | |
joeata2wh | 0:0cfc06f9f18c | 5 | By Joseph Ellsworth CTO of A2WH |
joeata2wh | 0:0cfc06f9f18c | 6 | Take a look at A2WH.com Producing Water from Air using Solar Energy |
joeata2wh | 0:0cfc06f9f18c | 7 | March-2016 License: https://developer.mbed.org/handbook/MIT-Licence |
joeata2wh | 0:0cfc06f9f18c | 8 | Please contact us http://a2wh.com for help with custom design projects. |
joeata2wh | 0:0cfc06f9f18c | 9 | */ |
joeata2wh | 0:0cfc06f9f18c | 10 | |
joeata2wh | 0:0cfc06f9f18c | 11 | #include "mbed.h" |
joeata2wh | 0:0cfc06f9f18c | 12 | #include "dataLog.h" |
joeata2wh | 0:0cfc06f9f18c | 13 | |
joeata2wh | 0:0cfc06f9f18c | 14 | const float adc_ref = 3.3f; |
joeata2wh | 0:0cfc06f9f18c | 15 | // SPI PINS |
joeata2wh | 0:0cfc06f9f18c | 16 | #define SPI1_SCK PA_5 |
joeata2wh | 0:0cfc06f9f18c | 17 | #define SPI1_MISO PA_6 |
joeata2wh | 0:0cfc06f9f18c | 18 | #define SPI1_MOSI PA_7 |
joeata2wh | 0:0cfc06f9f18c | 19 | |
joeata2wh | 0:0cfc06f9f18c | 20 | // SPI PINS for Data Log chip |
joeata2wh | 0:0cfc06f9f18c | 21 | #define dataLogMISOPin SPI1_MISO |
joeata2wh | 0:0cfc06f9f18c | 22 | #define dataLogMOSIPin SPI1_MOSI |
joeata2wh | 0:0cfc06f9f18c | 23 | #define dataLogCLKPin SPI1_SCK |
joeata2wh | 0:0cfc06f9f18c | 24 | #define dataLogSelectPin PC_12 |
joeata2wh | 0:0cfc06f9f18c | 25 | |
joeata2wh | 0:0cfc06f9f18c | 26 | AnalogIn waterTempSense(A0); |
joeata2wh | 0:0cfc06f9f18c | 27 | AnalogIn oxygenLevelSense(A1); |
joeata2wh | 0:0cfc06f9f18c | 28 | AnalogIn solarStrengthSense(A2); |
joeata2wh | 0:0cfc06f9f18c | 29 | AnalogIn waterSpeedSense(A3); |
joeata2wh | 0:0cfc06f9f18c | 30 | // imagine for sake of example that we have |
joeata2wh | 0:0cfc06f9f18c | 31 | // circuitry that actually convert these Volt |
joeata2wh | 0:0cfc06f9f18c | 32 | // readings to useful readings. |
joeata2wh | 0:0cfc06f9f18c | 33 | |
joeata2wh | 0:0cfc06f9f18c | 34 | DigitalOut led(LED1); |
joeata2wh | 0:0cfc06f9f18c | 35 | |
joeata2wh | 0:0cfc06f9f18c | 36 | |
joeata2wh | 0:0cfc06f9f18c | 37 | int main() { |
joeata2wh | 0:0cfc06f9f18c | 38 | printf("\nData Logger Example example\n"); |
joeata2wh | 0:0cfc06f9f18c | 39 | |
joeata2wh | 0:0cfc06f9f18c | 40 | float meas; |
joeata2wh | 0:0cfc06f9f18c | 41 | char dlbuff[81]; // buffer used internally by this instance of data log |
joeata2wh | 0:0cfc06f9f18c | 42 | DataLogChipType dlchip(dataLogMOSIPin, dataLogMISOPin, dataLogCLKPin, dataLogSelectPin); |
joeata2wh | 0:0cfc06f9f18c | 43 | DLOG *lgr = dlMake(&dlchip, dlbuff, 80); |
joeata2wh | 0:0cfc06f9f18c | 44 | |
joeata2wh | 0:0cfc06f9f18c | 45 | |
joeata2wh | 0:0cfc06f9f18c | 46 | lgr.log(lgr, "HEAD\tsensors", "waterTemp,oxygenLevel,solarStrength,waterSpeed"); |
joeata2wh | 0:0cfc06f9f18c | 47 | |
joeata2wh | 0:0cfc06f9f18c | 48 | |
joeata2wh | 0:0cfc06f9f18c | 49 | while(1) { |
joeata2wh | 0:0cfc06f9f18c | 50 | float waterTemp = waterTempSense.read() * adc_ref; |
joeata2wh | 0:0cfc06f9f18c | 51 | float oxygenLevel = oxygenLevelSense.read() * adc_ref; |
joeata2wh | 0:0cfc06f9f18c | 52 | float solarStrength = solarStrengthSense.read() * adc_ref; |
joeata2wh | 0:0cfc06f9f18c | 53 | float waterSpeed = waterSpeedSense.read() * adc_ref; |
joeata2wh | 0:0cfc06f9f18c | 54 | |
joeata2wh | 0:0cfc06f9f18c | 55 | float tbff |
joeata2wh | 0:0cfc06f9f18c | 56 | // lgr will internally log time. Whenever the date changes |
joeata2wh | 0:0cfc06f9f18c | 57 | // it will log a new date records. |
joeata2wh | 0:0cfc06f9f18c | 58 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
joeata2wh | 0:0cfc06f9f18c | 59 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
joeata2wh | 0:0cfc06f9f18c | 60 | printf("measure = %.0f mV\n", meas); |
joeata2wh | 0:0cfc06f9f18c | 61 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
joeata2wh | 0:0cfc06f9f18c | 62 | led = 1; |
joeata2wh | 0:0cfc06f9f18c | 63 | } |
joeata2wh | 0:0cfc06f9f18c | 64 | else { |
joeata2wh | 0:0cfc06f9f18c | 65 | led = 0; |
joeata2wh | 0:0cfc06f9f18c | 66 | } |
joeata2wh | 0:0cfc06f9f18c | 67 | wait(0.2); // 200 ms |
joeata2wh | 0:0cfc06f9f18c | 68 | } |
joeata2wh | 0:0cfc06f9f18c | 69 | } |