Re: Arduino OBD-II UART adapter questions and inquries
Unread postPosted:Sun Jun 22, 2014 10:53 am
[quote="alf"]
[quote="DeWitt"]
[quote="alf"]
Hi, i've recently bought this OBD adapter (model A UART) to use on a 2013 Toyota Auris. I'm using arduino UNO R3 and a Nokia 5110 screen to display data. I'm trying to display 4 PIDs: rpm, coolant temp, speed and hybrid battery percentage. It works but the refresh rate is very slow: about 5 seconds. Additionally, it also has a delay on data reading of about 5-10 seconds. What's wrong? Here is the code:
[code]#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544(SCLK, DIN, D/C, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
COBD obd;
int kmh;
int temperature;
int rpm;
int charge;
void setup() {
kmh=0;
temperature=0;
rpm=0;
charge=0;
display.begin();
display.setContrast(50);
display.clearDisplay();
// start communication with OBD-II UART adapter
obd.begin();
// initiate OBD-II connection until success
//Protocol 6: ISO 15765-4 CAN 11 bit 500 kbaud
while (!obd.init(6));
}
void loop() {
//Read data
obd.read(PID_RPM, rpm);
obd.read(PID_COOLANT_TEMP, temperature);
obd.read(PID_SPEED, kmh);
obd.read(PID_HYBRID_BATTERY_PERCENTAGE, charge);
//Display data
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(3,0);
display.print(kmh);
display.setCursor(53,0);
display.print(temperature);
display.setTextSize(1);
display.setCursor(10,16);
display.print("km/h");
display.setCursor(53,16);
display.print("Temp");
display.drawLine(0, 25, 83, 25, BLACK);
display.setCursor(0,28);
display.setTextSize(1);
display.print(rpm);
display.println("rpm");
display.setCursor(0,38);
display.print(charge);
display.print("%");
display.display();
delay(100);
}
[/code]
Thanks!
[/quote]
I would try commenting out all the PID's except RPM and see if that updates at the correct rate. Then add the others one at a time. The long delay between readings sounds like one of the PID's isn't being supplied by the ECU or it's incorrectly defined.
DeWitt Payne
[/quote]
Thank you! I'll try it tomorrow.
[/quote]
I've commented out all the PIDs except RPM and it updates very fast, about ten times per second. The same happens with the other PIDs: if I only read one PID at a time, it works well. The problem occurs when I read two or more PIDs at a time. I've tried to add a delay between reading one PID and another with no success. What could be wrong?
[quote="DeWitt"]
[quote="alf"]
Hi, i've recently bought this OBD adapter (model A UART) to use on a 2013 Toyota Auris. I'm using arduino UNO R3 and a Nokia 5110 screen to display data. I'm trying to display 4 PIDs: rpm, coolant temp, speed and hybrid battery percentage. It works but the refresh rate is very slow: about 5 seconds. Additionally, it also has a delay on data reading of about 5-10 seconds. What's wrong? Here is the code:
[code]#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544(SCLK, DIN, D/C, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
COBD obd;
int kmh;
int temperature;
int rpm;
int charge;
void setup() {
kmh=0;
temperature=0;
rpm=0;
charge=0;
display.begin();
display.setContrast(50);
display.clearDisplay();
// start communication with OBD-II UART adapter
obd.begin();
// initiate OBD-II connection until success
//Protocol 6: ISO 15765-4 CAN 11 bit 500 kbaud
while (!obd.init(6));
}
void loop() {
//Read data
obd.read(PID_RPM, rpm);
obd.read(PID_COOLANT_TEMP, temperature);
obd.read(PID_SPEED, kmh);
obd.read(PID_HYBRID_BATTERY_PERCENTAGE, charge);
//Display data
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(3,0);
display.print(kmh);
display.setCursor(53,0);
display.print(temperature);
display.setTextSize(1);
display.setCursor(10,16);
display.print("km/h");
display.setCursor(53,16);
display.print("Temp");
display.drawLine(0, 25, 83, 25, BLACK);
display.setCursor(0,28);
display.setTextSize(1);
display.print(rpm);
display.println("rpm");
display.setCursor(0,38);
display.print(charge);
display.print("%");
display.display();
delay(100);
}
[/code]
Thanks!
[/quote]
I would try commenting out all the PID's except RPM and see if that updates at the correct rate. Then add the others one at a time. The long delay between readings sounds like one of the PID's isn't being supplied by the ECU or it's incorrectly defined.
DeWitt Payne
[/quote]
Thank you! I'll try it tomorrow.
[/quote]
I've commented out all the PIDs except RPM and it updates very fast, about ten times per second. The same happens with the other PIDs: if I only read one PID at a time, it works well. The problem occurs when I read two or more PIDs at a time. I've tried to add a delay between reading one PID and another with no success. What could be wrong?