From 2f3b0db67c3a4006b4c06a27ed0affddc20d6b69 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sat, 24 Sep 2022 19:25:23 -0400 Subject: [PATCH 1/2] Add esp32 example, https://github.com/iwanders/OBD9141/issues/38 --- examples/reader_esp32/reader_esp32.ino | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/reader_esp32/reader_esp32.ino diff --git a/examples/reader_esp32/reader_esp32.ino b/examples/reader_esp32/reader_esp32.ino new file mode 100644 index 0000000..f8c9647 --- /dev/null +++ b/examples/reader_esp32/reader_esp32.ino @@ -0,0 +1,41 @@ +#include +#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(); +} From 95c57fe798f55ead47eceb5edf1d836e7bbc0f80 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sun, 25 Sep 2022 07:50:17 -0400 Subject: [PATCH 2/2] Add note to readme about esp32. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 349d3f9..d81bb14 100644 --- a/README.md +++ b/README.md @@ -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")