Hello,
I would like to know if this code works GitHub - ALEEF02/SparkfunOBD2UART: Arduino library for the Sparkfun OBD-II UART Adapter with SparkfunOBD2UART, because i try for example to display VIN, i get No VIN message.
I set return true before condition
if (q - buffer == len - 3) {
return true;
}
the VIN display, missed 4 characters of VIN. So i'm beginner on c language, i would like to know where is the problem?
-
If you can explain this problem, i'm interrested.
-
Is it possible to get all informations about ECU (hardware version, ...) ?
Thank you for your help.
Hello lebossejames
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
What tf is a Vin message?
#include <Wire.h>
#include "SparkfunOBD2UART.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // Green A0, White A1
//SoftwareSerial mySerial;
COBD obd;
#include "LCD_Manage.h"
#include <SPI.h>
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void testATcommands()
{
static const char cmds[][6] = {"ATI","0902"}; // , "ATI", "ATH0", "ATRV", "ATDP", "0100", "010C",
char buf[128];
for (byte i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
const char *cmd = cmds[i];
clearLCD();
displayTextLcd("Sending "+String(cmd));
//delay(3000);
/* tft.print("Sending ");
tft.println(cmd); */
if (obd.sendCommand(cmd, buf, sizeof(buf))) {
char *p = strstr(buf, cmd);
if (p)
p += strlen(cmd);
else
p = buf;
while (*p == '\r') p++;
while (*p) {
displayTextLcd(String(*p));
/* tft.write(*p);
*
if (*p == '\r' && *(p + 1) != '\r')
tft.write('\n'); */
p++;
}
} else {
clearLCD();
displayTextLcd("Timed out!");
// tft.println("Timed out!");
}
delay(1000);
}
}
void checkPIDs()
{
static const char cmds[][7] = {"0100", "0120", "0140", "0160", "0180", "01A0","0902"};
char buf[128];
for (byte i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
const char *cmd = cmds[i];
clearLCD();
displayTextLcd("Sending "+String(cmd));
/* tft.print("Sending ");
tft.println(cmd); */
if (obd.sendCommand(cmd, buf, sizeof(buf))) {
char *p = strstr(buf, cmd);
if (p)
p += strlen(cmd);
else
p = buf;
while (*p == '\r') p++;
while (*p) {
/*tft.write(*p);
if (*p == '\r' && *(p + 1) != '\r')
tft.write('\n'); */
p++;
}
} else {
clearLCD();
displayTextLcd("Timed out!");
//tft.println("Timed out!");
}
delay(1000);
}
}
void setup() {
mySerial.begin(9600);
while (!mySerial);
delay(500);
initLCD();
delay(250);
displayTextLcd("Connecting...");
for (;;) {
//delay(1000);
byte version = obd.begin();
//displayTextLcd("Sparkfun OBD-II Adapter ");
if (version > 0 && version < 254) {
/* tft.println("detected");
tft.print("OBD firmware version ");
tft.print(version / 10);
tft.print('.');
tft.println(version % 10); */
clearLCD();
displayTextLcd("OBD firmware version "+String (version / 10)+"."+String(version % 10));
delay(2000);
break;
} else {
clearLCD();
displayTextLcd("OBD firmware version "+String (version / 10)+"."+String(version % 10));
delay(2000);
/* tft.print("not detected... ");
tft.print(version / 10);
tft.print('.');
tft.println(version % 10); */
}
}
//testATcommands();
clearLCD();
displayTextLcd("Initializing...");
delay(1000);
//tft.println("Initializing...");
int up = obd.init(PROTO_AUTO);
displayTextLcd("Sent initialize command. Waiting 5 seconds... ");
//tft.print("Sent initialize command. Waiting 5 seconds... ");
delay(1000);
//tft.print("passed. Stage: ");
//tft.println(up);
clearLCD();
displayTextLcd("passed. Stage: "+String(up));
delay(500);
char buf[64];
if (obd.getVIN(buf, sizeof(buf))) {
clearLCD();
displayTextLcd(String(buf));
// tft.print("VIN:");
// tft.println(buf);
} else {
clearLCD();
displayTextLcd("No VIN");
// tft.println("No VIN");
}
/* uint16_t codes[6];
byte dtcCount = obd.readDTC(codes, 6);
if (dtcCount == 0) {
tft.println("No DTC");
} else {
tft.print(dtcCount);
tft.print(" DTC:");
for (byte n = 0; n < dtcCount; n++) {
tft.print(' ');
tft.print(codes[n], HEX);
}
}
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0,0);
tft.println("Checking avalible PIDs");
delay(250);
*/
int value;
/* tft.print('[');
tft.print(millis());
tft.print(']');
tft.print("RPM="); */
/* if (obd.readPID(PID_RPM, value)) {
displayTextLcd(String(value));
// tft.print(value);
} */
// tft.println();
/* if (obd.readPID(0x0902, value)) {
displayTextLcd(String(value));
// tft.print(value);
}
displayTextLcd("Checking avalible PIDs");
static const byte pids[]= {0x00, 0x02, 0x20, 0x40, 0x60, 0x80, 0xA0};
int values[sizeof(pids)];
// send a query to OBD adapter for specified OBD-II pid
if (obd.readPID(pids, sizeof(pids), values) == sizeof(pids)) {
obd.readPID(pids, sizeof(pids), values) == sizeof(pids);
for (byte i = 0; i < sizeof(pids); i++) {
clearLCD();
displayTextLcd(String((int)pids[i] | 0x100, HEX));
//tft.print((int)pids[i] | 0x100, HEX);
// tft.print('=');
clearLCD();
displayTextLcd(String(values[i]));
//tft.print(values[i]);
// tft.println();
}
} else {
clearLCD();
displayTextLcd("Failed to read PIDs!");
//tft.println("Failed to read PIDs!");
}
clearLCD();
displayTextLcd("Done reading PIDs");
delay(250);
checkPIDs(); */
}
void loop()
{
delay(6000);
clearLCD();
delay(500);
char buf[64];
if (obd.getVIN(buf, sizeof(buf))) {
clearLCD();
displayTextLcd(String(buf));
// tft.print("VIN:");
// tft.println(buf);
} else {
clearLCD();
displayTextLcd("No VIN");
// tft.println("No VIN");
}
}