Closed saagcs closed 2 years ago
Here's an example of how to properly query two PIDs in the same sketch (note that you'll have to do some fixing to make it ESP32 bluetoothserial compatible):
#include "ELMduino.h"
#define ELM_PORT Serial1
const bool DEBUG = false;
const int TIMEOUT = 2000;
const bool HALT_ON_FAIL = false;
const int ERR = -1e6;
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()
{
Serial.begin(115200);
ELM_PORT.begin(9600);
Serial.println("Attempting to connect to ELM327...");
if (!myELM327.begin(ELM_PORT, DEBUG, TIMEOUT))
{
Serial.println("Couldn't connect to OBD scanner");
if (HALT_ON_FAIL)
while (1);
}
Serial.println("Connected to ELM327");
}
void loop()
{
switch (obd_state)
{
case ENG_RPM:
{
rpm = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
Serial.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)
{
Serial.println(mph);
obd_state = ENG_RPM;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = ENG_RPM;
}
break;
}
}
}
Hello, I am trying to read the data of a vehicle from the ELMduino library, on an lcd1602 screen, but I am having two problems:
It only reads me one data at a time, that is, I have two data available in each line: Motor and RPM, but when both data are present, it only updates RPM, and motor always remains at zero, when I eliminate RPM, motor works
In the RPM result, it never shows the thousands, only 3-digit numbers, in the photo the screen shows the RPM in 010, but it was in 1010.
How can I solve both errors, especially the one that updates the screen, both data at the same time, motor and RPM.
I don't know what I'm doing wrong in the code:
Project picture
https://aws1.discourse-cdn.com/arduino/original/4X/c/5/7/c576c682f65ff42186229e1e16d3d4426911d086.jpeg