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:
//Import i2C LCD libraries
#include "BluetoothSerial.h"
#include "ELMduino.h"
#include <LiquidCrystal_I2C.h>
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
BluetoothSerial SerialBT;
#define ELM_PORT SerialBT
#define DEBUG_PORT Serial
ELM327 myELM327;
uint32_t tempeR = 0;
uint32_t mRPM = 0;
void setup()
{
#if LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endif
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
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))
{
Serial.println("Couldn't connect to OBD scanner - Phase 2");
while (1);
}
Serial.println("Connected to ELM327");
}
void loop(){
float motor = myELM327.engineCoolantTemp();
float motorRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
tempeR = (uint32_t)motor;
mRPM = (uint32_t)motorRPM;
// set cursor to first column, first row
lcd.setCursor(0, 0);
lcd.print("Motor: " + String(tempeR)+ " C"); Serial.println(tempeR);
delay(200);
lcd.setCursor(0, 1);
lcd.print("RPM: " + String(mRPM)); Serial.println(mRPM);
delay(200);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
myELM327.printError();
}
Picture