Hey guys. I hope that someone is still viewing this thread. I have recently purchased the OBD-II Adapter for Arduino - Model A (UART) as I am working on a project that needs to read dfrobot vehicle data.
I have tried the following code to get some vehicle data and display it.
Code: Select all#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
COBD obd; // - Declare OBD object
int currSpeed, distance, fuelLevel, engineLoad, rpm;
void setup()
{
Serial.begin(115200);
Serial.println("Started");
obd.begin(); // - Start communication with OBD-II UART adapter
while (!obd.init()); // - Initiate OBD-II connection until success
}
void loop()
{
Serial.println("OBD-II STATE: " + String(obd.getState()));
Serial.println("VOLTAGE: " + String (obd.getVoltage()));
obd.read(PID_RPM, currSpeed);
obd.read(PID_DISTANCE, distance);
obd.read(PID_FUEL_LEVEL, fuelLevel);
obd.read(PID_ENGINE_LOAD, engineLoad);
obd.read(PID_RPM, rpm);
Serial.println(currSpeed);
Serial.println(distance);
Serial.println(fuelLevel);
Serial.println(engineLoad);
Serial.println(rpm);
}
The OBD state and the voltage can be read successfully, so no problems there. The problem is with the PIDs. I keep getting values of 0 printed for each of the vehicle data.
Also, when using read() the data displayed becomes really slow. If I comment out the obd.read() lines and keep the state and voltage, then that data is displayed a lot of times in a second, however when reading the PIDs, this gets a lot slower, like once per 5 seconds.
I'm pretty sure it is connected correctly. I am using the MEGA 2560 and I connected the RX and TX to pins 18 and 19 (Serial1) as instructed.
Am I doing something wrong code-wise? Thank you for reading, any input is appreciated!
---UPDATE---
It seems the PID_FUEL_LEVEL does not work. I tried retrieving vehicle data again (excluding the fuel level) and everything worked perfectly. The data is being retrieved at a fast rate as I had hoped. Also, I have discovered that as soon as one PID fails (in this case, the pid for fuel level) then the other PIDs that initially worked will also end up failing.
Did anyone else have issues with the Fuel Level PID? The vehicle I'm testing this on is a Toyota Yaris 2006 (Hatchback).