Skip to content

Commit

Permalink
Merge pull request #245 from jimwhitelaw/bt-multiple-pid
Browse files Browse the repository at this point in the history
Example sketch to query multiple pids with a Bluetooth connection
  • Loading branch information
jimwhitelaw authored Apr 18, 2024
2 parents af150fc + 530067b commit 5d04161
Showing 1 changed file with 82 additions and 0 deletions.
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;
}
}
}

1 comment on commit 5d04161

@Bakar002
Copy link

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

Please sign in to comment.