Skip to content

Commit ba51e32

Browse files
committed
corrections
1 parent 2a296f0 commit ba51e32

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

examples/OBDII/EngineRPM/EngineRPM.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bool useStandardAddressing = true;
88
void setup() {
99
Serial.begin(9600);
1010

11-
Serial.println("CAN OBD-II supported pids");
11+
Serial.println("CAN OBD-II engine RPM");
1212

1313
// start the CAN bus at 500 kbps
1414
if (!CAN.begin(500E3)) {
@@ -36,8 +36,9 @@ void loop() {
3636

3737
// wait for response
3838
while (CAN.parsePacket() == 0 ||
39-
CAN.read() != 0x41 || // correct mode
40-
CAN.read() != 0x0c); // correct PID
39+
CAN.read() < 3 || // correct length
40+
CAN.read() != 0x41 || // correct mode
41+
CAN.read() != 0x0c); // correct PID
4142

4243
float rpm = ((CAN.read() * 256.0) + CAN.read()) / 4.0;
4344

examples/OBDII/SupportedPIDs/SupportedPIDs.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void loop() {
3232
}
3333
CAN.write(0x02); // number of additional bytes
3434
CAN.write(0x01); // show current data
35-
CAN.write(pid); // PID
35+
CAN.write(pid); // PID
3636
CAN.endPacket();
3737

3838
// wait for response
@@ -66,5 +66,7 @@ void loop() {
6666
}
6767
}
6868

69+
Serial.println("That's all folks!");
70+
6971
while (1); // all done
7072
}

examples/OBDII/VINReader/VINReader.ino

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,28 @@ void loop() {
4747
Serial.write((char)CAN.read());
4848
}
4949

50-
// send the request for the remaining bytes
51-
if (useStandardAddressing) {
52-
CAN.beginPacket(0x7e0, 8);
53-
} else {
54-
CAN.beginExtendedPacket(0x18db10f1, 8); // TODO - verify this
55-
}
56-
CAN.write(0x30);
57-
CAN.endPacket();
58-
59-
// read in remaining bytes
50+
// read in remaining chunks
6051
for (int i = 0; i < 2; i++) {
52+
// send the request for the next chunk
53+
if (useStandardAddressing) {
54+
CAN.beginPacket(0x7e0, 8);
55+
} else {
56+
CAN.beginExtendedPacket(0x18db33f1, 8);
57+
}
58+
CAN.write(0x30);
59+
CAN.endPacket();
60+
6161
// wait for response
62-
while (CAN.parsePacket() == 0 || // wait for response
63-
CAN.read() != 0x21);
62+
while (CAN.parsePacket() == 0 ||
63+
CAN.read() != (0x21 + i)); // correct sequence number
6464

6565
// print out
6666
while (CAN.available()) {
6767
Serial.write((char)CAN.read());
6868
}
6969
}
7070

71+
Serial.println("That's all folks!");
72+
7173
while (1); // all done
7274
}

0 commit comments

Comments
 (0)