-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from jimwhitelaw/bt-multiple-pid
Example sketch to query multiple pids with a Bluetooth connection
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
examples/ESP32_Bluetooth_multiple_pids/ESP32_Bluetooth_multiple_pids.ino
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "BluetoothSerial.h" | ||
#include "ELMduino.h" | ||
|
||
BluetoothSerial SerialBT; | ||
#define ELM_PORT SerialBT | ||
#define DEBUG_PORT Serial | ||
|
||
ELM327 myELM327; | ||
|
||
typedef enum { ENG_RPM, | ||
SPEED } obd_pid_states; | ||
obd_pid_states obd_state = ENG_RPM; | ||
|
||
float rpm = 0; | ||
float mph = 0; | ||
|
||
void setup() | ||
{ | ||
DEBUG_PORT.begin(115200); | ||
// SerialBT.setPin("1234"); | ||
ELM_PORT.begin("ArduHUD", true); | ||
|
||
if (!ELM_PORT.connect("OBDII")) | ||
{ | ||
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1"); | ||
while (1) | ||
; | ||
} | ||
|
||
if (!myELM327.begin(ELM_PORT, true, 2000)) | ||
{ | ||
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 2"); | ||
while (1) | ||
; | ||
} | ||
|
||
DEBUG_PORT.println("Connected to ELM327"); | ||
} | ||
|
||
void loop() | ||
{ | ||
switch (obd_state) | ||
{ | ||
case ENG_RPM: | ||
{ | ||
rpm = myELM327.rpm(); | ||
|
||
if (myELM327.nb_rx_state == ELM_SUCCESS) | ||
{ | ||
DEBUG_PORT.print("rpm: "); | ||
DEBUG_PORT.println(rpm); | ||
obd_state = SPEED; | ||
} | ||
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) | ||
{ | ||
myELM327.printError(); | ||
obd_state = SPEED; | ||
} | ||
|
||
break; | ||
} | ||
|
||
case SPEED: | ||
{ | ||
mph = myELM327.mph(); | ||
|
||
if (myELM327.nb_rx_state == ELM_SUCCESS) | ||
{ | ||
DEBUG_PORT.print("mph: "); | ||
DEBUG_PORT.println(mph); | ||
obd_state = ENG_RPM; | ||
} | ||
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) | ||
{ | ||
myELM327.printError(); | ||
obd_state = ENG_RPM; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} |
5d04161
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have tried it in toyota aqua the parameters are loading very fast and also giving me wrong value mostly like have send mph 5.8 when running at a speed of about 30 kmph and just as rpm