Skip to content

Commit

Permalink
Support for ESP32, issue 38 and PR 39.
Browse files Browse the repository at this point in the history
Add esp32 example.
  • Loading branch information
iwanders authored Sep 25, 2022
2 parents 420cd63 + 95c57fe commit 6b4a73a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Usage
--------
The code has been developed using [Teensy 3][teensy31], the K-line transceiver IC's used were during the development were the [MC33290][mc33290], [SN65HVDA100][SN65HVDA100] and [SN65HVDA195][SN65HVDA195]. All three transceiver IC's worked without problems when the typical application circuit from the datasheet was used. The OBD9141 class itself has been tested on one Kia car build in 2004.

For the Teensy 3.x or LC versions it is recommended to use one of the HardwareSerial ports. For use with Arduino the [AltSoftSerial][altsoftserial] library is used by default. The example `reader_softserial` was tested with an Arduino UNO. The KWP functionality of this library was verified to work on a Teensy 3.5.
For the Teensy 3.x or LC versions it is recommended to use one of the HardwareSerial ports. For use with Arduino the [AltSoftSerial][altsoftserial] library is used by default. The example `reader_softserial` was tested with an Arduino UNO. The KWP functionality of this library was verified to work on a Teensy 3.5. For ESP32 boards, please try the `reader_esp32` example.

A minimal example of how to use the SN65HVDA195 chip mentioned is given by the following schematic:
![Schematic of circuit using SN65HVDA195](/../master/extras/OBD9141_reader/img/OBD9141_reader_cutout.png?raw=true "Schematic of circuit using SN65HVDA195")
Expand Down
41 changes: 41 additions & 0 deletions examples/reader_esp32/reader_esp32.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <Arduino.h>
#include "OBD9141.h"

// ESP32 example, courtesy of gauix4; https://github.com/iwanders/OBD9141/issues/38

#define RX_PIN 16 // connect to transceiver Rx for ESP32
#define TX_PIN 17 // connect to transceiver Tx

bool init_success;

OBD9141 obd;

void setup(){
Serial.begin(115200);
obd.begin(Serial2, RX_PIN, TX_PIN);
delay(2000);
Serial.println("initialization");
Serial.println("");

while (!obd.init()){
return;
}
}

void loop(){
if (obd.getCurrentPID(0x11, 1)){
Serial.print("Result 0x11 (throttle): ");
Serial.println(obd.readUint8());
}

if (obd.getCurrentPID(0x0C, 2)){
Serial.print("Result 0x0C (RPM): ");
Serial.println(obd.readUint16()/4);
}

if (obd.getCurrentPID(0x0D, 1)){
Serial.print("Result 0x0D (speed): ");
Serial.println(obd.readUint8());
}
Serial.println();
}

0 comments on commit 6b4a73a

Please sign in to comment.