ELM327 + ESP32 Does not load data correctly, on 16x2 LCD screen

Hello, I am trying to use the ELMduino.h library to read data from the car's ECU, on a 16x2 LCD screen, but strange texts appear on the screen.

This is my 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 rpm = 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 tempRPM = myELM327.rpm();

  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
          // set cursor to first column, first row
    lcd.setCursor(0, 0);
    lcd.print("RPM: " + rpm); Serial.println(rpm);

  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();

}

I don't know what I'm doing wrong, in the following line to load the data on the screen:

    lcd.setCursor(0, 0);
    lcd.print("RPM: " + rpm); Serial.println(rpm);

Thnks for help

Did you just make up this syntax and hope?

rpm is a uint32 & not a char or string so you get whatever random character that the binary maps to.

I'm new to this, little experience in programming, I assumed that if the RPMs are displayed like this in serial, the same would happen on the screen, but I'm not sure how to do it

Probably, but that's no reason to be unhelpful.

Don't ever do that when the is loads of documentation to give you the actual usage.

Serial.println is smart enough to know to convert a numeric and display as a string, so is lcd.print but since your starting with a string constant "RPM: " it tries to interpret rpm as a string and prints garbage.

lcd.print("RPM: " + String(rpm) );

should work better

1 Like

Again, snide and unhelpful.

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