-
Notifications
You must be signed in to change notification settings - Fork 72
/
reader_softserial.ino
70 lines (49 loc) · 1.69 KB
/
reader_softserial.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
#include "Arduino.h"
// Be sure that the AltSoftSerial library is available, download it from http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html"
#include "AltSoftSerial.h"
#include "OBD9141.h"
#define RX_PIN 8 // connect to transceiver Rx
#define TX_PIN 9 // connect to transceiver Tx
#define EN_PIN 10 // pin will be set high (connect to EN pin of SN65HVDA100)
AltSoftSerial altSerial;
OBD9141 obd;
void setup(){
Serial.begin(9600);
delay(2000);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, HIGH); // enable the transceiver IC.
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(3000);
}