Skip to content

Instantly share code, notes, and snippets.

@rocketjosh
Last active October 27, 2017 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocketjosh/4d481f6b55e6492b3d35e2f1abb5a929 to your computer and use it in GitHub Desktop.
Save rocketjosh/4d481f6b55e6492b3d35e2f1abb5a929 to your computer and use it in GitHub Desktop.
OBD9141_DUE.INO
/*
* 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