From c83f19feb55fb3c405431bd12af4132d402cf436 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Mon, 19 Dec 2016 17:22:08 +1100 Subject: Updated example sketch Reading DTC and MEMS data --- .../OBD/examples/obd_i2c_test/obd_i2c_test.ino | 39 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'libraries/OBD/examples/obd_i2c_test') diff --git a/libraries/OBD/examples/obd_i2c_test/obd_i2c_test.ino b/libraries/OBD/examples/obd_i2c_test/obd_i2c_test.ino index c5b89fe..fd9e980 100644 --- a/libraries/OBD/examples/obd_i2c_test/obd_i2c_test.ino +++ b/libraries/OBD/examples/obd_i2c_test/obd_i2c_test.ino @@ -96,28 +96,55 @@ void readPIDs() Serial.println(); } +void readBatteryVoltage() +{ + Serial.print('['); + Serial.print(millis()); + Serial.print(']'); + Serial.print("Battery:"); + Serial.print(obd.getVoltage(), 1); + Serial.println('V'); +} + void setup() { - delay(500); Serial.begin(115200); - obd.begin(); + delay(500); accelgyro.initialize(); - readMEMS(); + obd.begin(); + // send some commands for testing and show response for debugging purpose + //testOut(); + + // initialize OBD-II adapter do { - testOut(); Serial.println("Init..."); - } while (!obd.init()); + } while (!obd.init()); char buf[64]; if (obd.getVIN(buf, sizeof(buf))) { Serial.print("VIN:"); Serial.println(buf); } - delay(1000); + + unsigned int codes[6]; + byte dtcCount = obd.readDTC(codes, 6); + if (dtcCount == 0) { + Serial.println("No DTC"); + } else { + Serial.print(dtcCount); + Serial.print(" DTC:"); + for (byte n = 0; n < dtcCount; n++) { + Serial.print(' '); + Serial.print(codes[n], HEX); + } + Serial.println(); + } + delay(3000); } void loop() { readPIDs(); + readBatteryVoltage(); readMEMS(); } -- cgit v1.2.3