-
Notifications
You must be signed in to change notification settings - Fork 72
/
readerKWP.ino
71 lines (51 loc) · 1.5 KB
/
readerKWP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Arduino.h"
#include "OBD9141.h"
#define RX_PIN 0
#define TX_PIN 1
#define EN_PIN 2
OBD9141 obd;
void setup(){
Serial.begin(9600);
delay(2000);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, HIGH);
obd.begin(Serial1, RX_PIN, TX_PIN);
}
void loop(){
Serial.println("Looping");
// only change from reader is the init method here.
bool init_success = obd.initKWP();
Serial.print("init_success:");
Serial.println(init_success);
delay(50);
//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());
}
delay(50);
res = obd.getCurrentPID(0x0C, 2);
if (res){
Serial.print("Result 0x0C (RPM): ");
Serial.println(obd.readUint16()/4);
}
delay(50);
res = obd.getCurrentPID(0x0D, 1);
if (res){
Serial.print("Result 0x0D (speed): ");
Serial.println(obd.readUint8());
}
Serial.println();
delay(200);
}
delay(200);
}
delay(3000);
}