Problem refresh info in LCD 1602 two different values

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:

  1. 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

  2. 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

From https://github.com/PowerBroker2/ELMduino

"Just to be clear, do not try to query more than one PID at a time. You must wait for the current PID query to complete before starting the next one."

You could do something like this. Then you can add as many PIDs as you want to the switch statement. I was not able to compile or test but hopefully it works.

//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;

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() 
{
  static int pidCounter = 0;
  
  switch (pidCounter)
  {
    case 0:
      {
        float motor = myELM327.engineCoolantTemp();
        if (myELM327.nb_rx_state == ELM_SUCCESS)
        {
          uint32_t tempeR = (uint32_t)motor;
          lcd.setCursor(0, 0);
          lcd.print("Motor: " + String(tempeR) + " C"); Serial.println(tempeR);
          delay(200);
          pidCounter++;
        }
        else if (myELM327.nb_rx_state != ELM_GETTING_MSG) myELM327.printError();
      }
      break;

    case 1:
      {
        float motorRPM = myELM327.rpm();

        if (myELM327.nb_rx_state == ELM_SUCCESS)
        {
          uint32_t mRPM = (uint32_t)motorRPM;
          lcd.setCursor(0, 1);
          lcd.print("RPM: " + String(mRPM)); Serial.println(mRPM);
          delay(200);
          pidCounter = 0;
        }
        else if (myELM327.nb_rx_state != ELM_GETTING_MSG) myELM327.printError();
      }
      break;
  }
}
1 Like

Very thnks, work perfect

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.