Comments (4)
I recalled tried recalling obd.init()
and obd.end()
followed by obd.begin()
again, but obd.getState()
still returned that it was connected. Why?
from arduinoobd.
The easiest way to know if the car is on is by checking the rpms. The value for this comes from the crank sensor so if it's failing you'll know it because it won't show revs and you also know the car is on. When you tried calling obd.getState()
was the key in the "run" position? The ecu will still connect if its on this. Usually if its not on run, it wont connect and it will throw an error. I'll look into the code in a bit to see if you can clear the states and sensor values after you turn off the car or change the key position.
from arduinoobd.
Well, I was looking to count the number of times the vehicle is turned on and off (and trigger events as states change). For example, I want to call this function each time the vehicle is turned on:
void incrementWarmups() {
byte lowerByte = EEPROM.read(0);
byte upperByte = EEPROM.read(1);
warmups = (unsigned int) (upperByte << 8) + lowerByte;
warmups++;
EEPROM.write(0, (byte) ((warmups << 8) >> 8));
EEPROM.write(1, (byte) (warmups >> 8));
}
Right now, my loop function looks something like this, where I check the previous state against the current state and check different things based on that state. Unfortunately, the state does not change when the vehicle is turned off.
void loop() {
lastState = state;
state = obd.getState();
timer = millis();
switch(state) {
case OBD_CONNECTED:
if(lastState == OBD_DISONNECTED) {
//vehicle started
...
}
else if(Serial.available()) {
//send requested data over serial to phone (android app)
...
}
else if(timer - lastUpdate >= 500) updateData();
break;
case OBD_DISCONNECTED:
if(lastState == OBD_CONNECTED) {
//vehicle stopped
...
}
else if(Serial.available()) {
//manually attempt reconnect by phone request
...
}
else if(timer - lastReconnectTry >= 10000) tryReconnect();
break;
case OBD_CONNECTING:
break;
case OBD_FAILED:
break;
}
I thought maybe the OBD-II port was still active when the vehicle was off, but the Arduino cannot connect to the OBD-II from power on when the vehicle is off and returned values from readPID()
do not appear updated. This adds to the confusion of what the OBD_STATES actually mean about the device's connection condition.
However, if there is another method to manage vehicle state other than getState()
, I a all for it.
from arduinoobd.
So what happens is that the Arduino is always receiving power from the port so it never really "turns off", it only disconnects because the key is no longer on run and the ecu power is cut. After that, all the values are still stored in the Arduino but not cleared, that's why the states don't change. Also, it doesn't change the state because of that like you said. I looked a bit through the library and it seems as if it returns the values as integers.
OBD_DISCONNECTED = 0, OBD_CONNECTING = 1, OBD_CONNECTED = 2, OBD_FAILED = 3
Have you set the variables to be ints? also, if you want to know if the car HAS ACTUALLY been turned on, I would suggest you poll the PID_RPM
pid so that if it equals 0, you know that the engine is off and it doesn't consider it a "warm up." If you leave it like that, what would happen is that every time you turn on the key to run but don't actually start the car, it'll register it as a "warm-up" and it will be inaccurate.
Edit: I forgot to mention that you could also try obd. reset();
to reset the connection and see if that erases any old data.
from arduinoobd.
Related Issues (20)
- Quick and non-blocking method to connect the OBD-II? HOT 1
- Transmission Fluid Temperature HOT 2
- OBD-II UART Adapter V2.1 says haven't MEMS HOT 1
- read Speed HOT 1
- Read Vehicle Odometer with OBD2UART HOT 1
- Nano Logger Complie Error
- ReadPID is slow :( is there an alternative way to readPIDs that doesn't block code whilst waiting to receive the PID data?
- Error in adding the library of OBD 2 UART adapter
- Duplicate empty CSV files?
- data2kml thinks I'm in the ocean? HOT 1
- ESP32 without Serial1 use Serial0
- Read Fuel used up
- Freematics OBD-II UART Adapter V2.1 CANNOT Initialize! HOT 4
- OBD 1 ? HOT 3
- Add new PIDs
- debug modus in OBD2UART.cpp / OBD2UART.h
- getVin not getting answer HOT 1
- custom pid not working HOT 1
- how turn off check engine light?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinoobd.