Created
July 26, 2016 19:30
-
-
Save macchina/35b7894bfdb73a41a4d7972d2f02ccee to your computer and use it in GitHub Desktop.
ISO9141 read example for M2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example based on code found here. | |
* https://github.com/iwanders/OBD9141 | |
* | |
* Put the "OBD9141 in Libraries folder. | |
* | |
*/ | |
#include "OBD9141.h" | |
#include "SamNonDuePin.h" | |
// The RX pin of the Serial1 connected to 9141 K RX of tranciever. | |
#define RX_PIN 19 | |
// The Tx pin of the Serial1 connected to 9141 K TX of tranciever. | |
#define TX_PIN 18 | |
// The Enable pin connected to 9141 SLP pin of tranciever. | |
#define EN_PIN PIN_EMAC_ECRSDV | |
#define OBD9141_DEBUG | |
OBD9141 obd; | |
void setup(){ | |
SerialUSB.begin(115200); | |
delay(2000); | |
pinModeNonDue(EN_PIN, OUTPUT); | |
digitalWriteNonDue(EN_PIN, HIGH); | |
obd.begin(Serial1, RX_PIN, TX_PIN); | |
} | |
void loop(){ | |
SerialUSB.println("Looping"); | |
bool init_success = obd.init(); | |
SerialUSB.print("init_success:"); | |
SerialUSB.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 = true; | |
while(res){ | |
res = obd.getCurrentPID(0x11, 1); | |
if (res){ | |
SerialUSB.print("Result 0x11 (throttle): "); | |
SerialUSB.println(obd.readUint8()); | |
} | |
res = obd.getCurrentPID(0x0C, 2); | |
if (res){ | |
SerialUSB.print("Result 0x0C (RPM): "); | |
SerialUSB.println(obd.readUint16()/4); | |
} | |
res = obd.getCurrentPID(0x0D, 1); | |
if (res){ | |
SerialUSB.print("Result 0x0D (speed): "); | |
SerialUSB.println(obd.readUint8()); | |
} | |
SerialUSB.println(); | |
delay(200); | |
} | |
} | |
delay(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment