#include "Arduino.h"
#include "OBD9141.h"
#include "AltSoftSerial.h"
#define RX_PIN 8
#define TX_PIN 9
// #define EN_PIN 4
AltSoftSerial altSerial;
OBD9141 obd;
void setup(){
Serial.begin(9600);
delay(2000);
// pinMode(EN_PIN, OUTPUT);
// digitalWrite(EN_PIN, HIGH);
obd.begin(altSerial, RX_PIN, TX_PIN);
}
void loop(){
Serial.println("Looping");
bool init_success = obd.init();
Serial.print("init_success:");
Serial.println(init_success);
// init_success = true;
// Uncomment this line if you use the simulator to force the init to be
// interpreted as successful. With an actual ECU; be sure that the init is
// succesful before trying to request PID's.
if (init_success){
bool res;
while(1){
res = obd.getCurrentPID(0x11, 1);
if (res){
Serial.print("Result 0x11 (throttle): ");
Serial.println(obd.readUint8());
}
res = obd.getCurrentPID(0x0C, 2);
if (res){
Serial.print("Result 0x0C (RPM): ");
Serial.println(obd.readUint16()/4);
}
res = obd.getCurrentPID(0x0D, 1);
if (res){
Serial.print("Result 0x0D (speed): ");
Serial.println(obd.readUint8());
}
Serial.println();
delay(200);
}
delay(200);
}
delay(3000);
}
The code uploads fine and working, but it's not communicating with the K Line,
it's just printing
Looping
init_success = 0
again and again
that means the code works fine right
only the communication is not establishing
I followed the instructions on the website, but the code provided there is not beginner-friendly.
I built the circuit as described, but instead of using the Microchip 16f886 microcontroller (as used on the website), I used an Arduino. However, the C code provided is too confusing for me, and I don't know how to implement it.
I want to get the data from the K-line using an Arduino. If you know how to adapt the instructions for use with an Arduino, please help me. Thank you!
It is not as simple as it appears, you could get a copy of the ISO-81418-2 and read that. When we put that together many years ago it started at 5 baud and worked its way up until either the car or reader was at maximum. You might also look at CAN as that information is on that bus as well.