I recently purchased an 'OBD-2 UART Adapter'. I set it up as instructed and uploaded a sample sketch designed to light up pin 13 when the car reaches 3000 rpm. It doesn't work. By messing with the code I think I have deduced that the obd.init() function always returns false. I tested it on a 2008 ford focus. I have attached the webpage for this kit which contains the sample code I was referring to. If anyone has experience using this kit or how to troubleshoot further any help would be appreciated, thanks Freematics OBD-II Adapter for Arduino | ArduinoDev.com
I have attached the webpage for this kit
Where? On a post-it note on your screen?
Sorry I forgot to paste in the link at the end. Its updated now
Try a sketch that prints the RPM value.
I could try that but it seems to be failing when it tries to connect so it never gets to the stage where it requests the rpm value. If you look at the code below it stays in the while loop because obd.init() keeps returning false.
#include <Wire.h>
#include <OBD.h>
COBD obd; /* for Model A (UART version) */
void setup()
{
// we'll use the debug LED as output
pinMode(13, OUTPUT);
// start communication with OBD-II adapter
obd.begin();
// initiate OBD-II connection until success
while (!obd.init());
}
void loop()
{
int value;
// save engine RPM in variable 'value', return true on success
if (obd.read(PID_RPM, value)) {
// light on LED on Arduino board when the RPM exceeds 3000
digitalWrite(13, value > 3000 ? HIGH : LOW);
}
}
COBD obd; /* for Model A (UART version) */
Really? My Model A, a 1931 version, didn't have a OBD port.
In setup, try something like
while (!obd.init()){
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
delay(200);
}
Isaac96, I ran your code in my sketch. 13 is on for 3 sec then off for half a second then on again and so on.... so we know the while loop is definitely running so obd.init() must be returning false.
If the init() is not working, suspect wiring problems. Go over everything again.
Here is a picture of my setup
https://drive.google.com/file/d/0B-7DDOBC2ZbPcUNiUUJyTjBtSEE/view?usp=sharing
red and black wire go to vin and GND. Yellow wire goes to the rx and white to the tx. The tx and rx flash red or green occasionally while testing it if that helps with the troubleshooting. Thanks
I think you need to connect the red wire to 5V, not VIN. Measure the voltage without anything connected to the OBD adapter.
obd.init() still fails when I connect the red to 5v. Do you think its a problem with the arduino interfacing with the adapter or the adapter interfacing to the OBD bus. My car uses the kwp 2000 protocol which the adapter is supposed to support. I have a bluetooth elm327 adapter that connects to my phone and that works great so I dont understand why this wont.
Try something like connecting your reset pin to ground, leaving the OBD connected, and opening the serial monitor at different baud rates.
I don't have a laptop handy so I cant do the serial monitor while in the car. I could probably get one. What would I be looking to see on the serial monitor? What does connecting the reset pin to ground do? Thanks for your continued patient help
Connecting the rest pin to ground lets the OBD module transmit directly to the Serial Monitor.
I tried what you suggested. When I connected res to GND I could not get anything on any baud. When I tried after removing the res GND connection I got some activity on the 115200 baud(see picture). https://drive.google.com/file/d/0B-7DDOBC2ZbPNEJuVEpmMHQ1OGM/view?usp=sharing
Switch TX and RX.
When I switch Tx and Rx I got a lot more activity on the serial monitor across all the bauds, but the obd.init() still fails.