diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2017-05-08 22:57:39 +1000 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2017-05-08 22:57:39 +1000 |
commit | fe06ee6e27833e26ea19bd740f504a9dcdf78d71 (patch) | |
tree | 2acaab902ef091d1c494bc4a8a388c46aaef23e0 | |
parent | 299de0a90617cb3a0a852aad1df538d1e23272b1 (diff) | |
download | 2021-arduino-obd-fe06ee6e27833e26ea19bd740f504a9dcdf78d71.tar.gz 2021-arduino-obd-fe06ee6e27833e26ea19bd740f504a9dcdf78d71.tar.bz2 2021-arduino-obd-fe06ee6e27833e26ea19bd740f504a9dcdf78d71.zip |
Reference data logger sketch for Freematics OBD-II UART Adapter
-rw-r--r-- | datalogger/datalogger.ino | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/datalogger/datalogger.ino b/datalogger/datalogger.ino index f348943..c04b2c9 100644 --- a/datalogger/datalogger.ino +++ b/datalogger/datalogger.ino @@ -359,8 +359,9 @@ void loop() { #if ENABLE_DATA_LOG if (!(one.state & STATE_FILE_READY) && (one.state & STATE_SD_READY)) { + // create log file if (one.state & STATE_GPS_FOUND) { - // GPS connected + // GPS connected, GPS time as file name Serial.print("File "); if (one.state & STATE_GPS_READY) { uint32_t dateTime = (uint32_t)MMDD * 10000 + UTC / 10000; @@ -373,7 +374,7 @@ void loop() } } } else { - // no GPS connected + // no GPS connected, index number as file name int index = one.openFile(0); if (index != 0) { one.state |= STATE_FILE_READY; @@ -384,6 +385,8 @@ void loop() } } #endif + + // log some OBD-II PIDs if (one.state & STATE_OBD_READY) { byte pids[] = {0, PID_RPM, PID_SPEED, PID_THROTTLE, PID_ENGINE_LOAD}; byte pids2[] = {PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_DISTANCE}; @@ -413,12 +416,19 @@ void loop() one.dataTime = millis(); one.logData(PID_BATTERY_VOLTAGE, v); + // log MEMS data #if USE_MPU6050 - if ((one.state & STATE_MEMS_READY) && accCount) { - // log the loaded MEMS data - one.logData(PID_ACC, accSum[0] / accCount / ACC_DATA_RATIO, accSum[1] / accCount / ACC_DATA_RATIO, accSum[2] / accCount / ACC_DATA_RATIO); - } + if (one.state & STATE_MEMS_READY) { + one.readMEMS(); + if (accCount > 0) { + // log the loaded MEMS data + one.logData(PID_ACC, accSum[0] / accCount / ACC_DATA_RATIO, accSum[1] / accCount / ACC_DATA_RATIO, accSum[2] / accCount / ACC_DATA_RATIO); + accCount = 0; + } + } #endif + + // log GPS data #if USE_GPS if (one.state & STATE_GPS_FOUND) { one.logGPSData(); |