Elmduino data on screen

Hi, could someone shed a suggestion why engine Temperature isn't being displayed on my tft display, but I can clearly see the value in terminal.

//Engine Temperature
//Print value is temp_1;



  void temperature(){
  int state1=digitalRead(SENSOR_PIN1);
  float tempTemp=myELM327.engineCoolantTemp();
if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
Temp = (uint16_t)tempTemp;    
Serial.print("Temp: "); Serial.println(Temp);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();
    Temp=0;

  
  char temp_1[17];

  
  dtostrf(Temp,3,0,temp_1);

  // read the state of the the input pin:
  int state = digitalRead(SENSOR_PIN);

// Gornja spica
tft.drawLine(0,5,76,5,0x92B0);
tft.drawLine(76,5,80,0,0x92B0);
tft.drawLine(80,0,84,5,0x92B0);
tft.drawLine(84,5,160,5,0x92B0);

{ tft.setCursor(15, 10);
 tft.setTextSize(2);
  tft.setTextColor(0x1D9E,TFT_BLACK);
 tft.println("Engine temp");}
/// Donja spica

tft.drawLine(0,30,76,30,0x92B0);
tft.drawLine(76,30,80,35,0x92B0);
tft.drawLine(80,35,84,30,0x92B0);
tft.drawLine(84,30,160,30,0x92B0);

{ tft.setCursor(25, 55);
 tft.setTextSize(5);
 tft.setTextColor(TFT_WHITE,TFT_BLACK);
 tft.println(temp_1);

 }

 if (temp>100){
 tft.setCursor(25, 55);
tft.setTextSize(5);
tft.setTextColor(TFT_RED,TFT_BLACK);
tft.println(temp_1);
// tft.drawString(temp_1,25,55,5);
 }
 


 
{ tft.setCursor(130, 65);
 tft.setTextSize(3);
  tft.setTextColor(TFT_WHITE,TFT_BLACK);
 tft.println("c");}
 tft.drawCircle(149,63,2,TFT_WHITE);
 
 tft.drawLine(0,110,76,110,0x92B0);
tft.drawLine(76,110,80,115,0x92B0);
tft.drawLine(80,115,84,110,0x92B0);
tft.drawLine(84,110,160,110,0x92B0);

delay(200);
}

This is the data that I get in serial monitor

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13924
ho 0 tail 12 room 4
load:0x40080400,len:3600
entry 0x400805f0
Clearing input serial buffer
Sending the following command/query: AT D
	Received char: \r
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT Z
	Received char: A
	Received char: T
	Received char: _
	Received char: Z
	Received char: \r
	Received char: \r
	Received char: \r
	Received char: O
	Received char: B
	Received char: D
	Received char: I
	Received char: I
	Received char: _
	Received char: _
	Received char: v
	Received char: 1
	Received char: .
	Received char: 5
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: ATZOBDIIv1.5
Clearing input serial buffer
Sending the following command/query: AT E0
	Received char: A
	Received char: T
	Received char: _
	Received char: E
	Received char: 0
	Received char: \r
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: ATE0OK
Clearing input serial buffer
Sending the following command/query: AT S0
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT AL
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT ST 00
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT TP A0
	Received char: O
	Received char: K
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: OK
Service: 1
PID: 5
Normal length query detected
Query string: 01051
Clearing input serial buffer
Sending the following command/query: 01051
	Received char: S
	Received char: E
	Received char: A
	Received char: R
	Received char: C
	Received char: H
	Received char: I
	Received char: N
	Received char: G
	Received char: .
	Received char: .
	Received char: .
	Received char: \r
	Received char: 4
	Received char: 1
	Received char: 0
	Received char: 5
	Received char: 5
	Received char: A
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: SEARCHING...41055A
Expected response header: 4105
Single response detected
64-bit response: 
	responseByte_0: 90
	responseByte_1: 0
	responseByte_2: 0
	responseByte_3: 0
	responseByte_4: 0
	responseByte_5: 0
	responseByte_6: 0
	responseByte_7: 0
Temp: 50
Service: 1
PID: 5
Normal length query detected
Query string: 01051
Clearing input serial buffer
Sending the following command/query: 01051
	Received char: 4
	Received char: 1
	Received char: 0
	Received char: 5
	Received char: 5
	Received char: A
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: 41055A
Expected response header: 4105
Single response detected
64-bit response: 
	responseByte_0: 90
	responseByte_1: 0
	responseByte_2: 0
	responseByte_3: 0
	responseByte_4: 0
	responseByte_5: 0
	responseByte_6: 0
	responseByte_7: 0
Temp: 50
Service: 1
PID: 5
Normal length query detected
Query string: 01051
Clearing input serial buffer
Sending the following command/query: 01051
	Received char: 4
	Received char: 1
	Received char: 0
	Received char: 5
	Received char: 5
	Received char: A
	Received char: \r
	Received char: \r
	Received char: >
Delimiter found.
All chars received: 41055A
Expected response header: 4105
Single response detected
64-bit response: 
	responseByte_0: 90
	responseByte_1: 0
	responseByte_2: 0
	responseByte_3: 0
	responseByte_4: 0
	responseByte_5: 0
	responseByte_6: 0
	responseByte_7: 0
Temp: 50

I'm using esp32-Elmduino via Bluetooth connection, st7735 display.
In serial monitor I get Temp:50
but on the screen i get 0
agh I think it's because of Temp=0; after the serial.

Would you post the full sketch? It will be better for understanding.

And please reformat it before posting (Ctrl-T to auto-format in the IDE), the posted code is horribly formatted.

Here is the full code

lantTemp=0;



void setup() {
  //Elm
  SerialBT.setPin("1234");
  ELM_PORT.begin("ArduHUD", true);
  DEBUG_PORT.begin(115200);


  tft.init();
  tft.fillScreen(TFT_BLACK);
  tft.setSwapBytes(true);
  tft.setRotation(0);
  Serial.begin(115200);
  // initialize the ESP32's pin as aninput
  pinMode(SENSOR_PIN, INPUT);                 // Potentiometer
  pinMode(SENSOR_PIN1, INPUT);                //Digital switch
  //Case 2: Multi Colored Images/Icons
  tft.pushImage(0, 0, 128, 160, logo);
  img.createSprite(160, 128);
  ccc.createSprite(160, 128);

  delay(5000);                                // Welcome Image time to be shown
  tft.fillScreen(TFT_BLACK);
  tft.setRotation(1);
  tft.pushImage(80, 100, 20, 20, loading);
  if (!ELM_PORT.connect("OBDII"))
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    tft.setCursor(5, 10);
    tft.setTextSize(2);
    tft.setTextColor(TFT_WHITE, TFT_BLACK);
    tft.println("Connecting..");


    while (1);
  }

  if (!myELM327.begin(ELM_PORT, true, 2000))
  {
    DEBUG_PORT.println("Connecting..");
    tft.setCursor(5, 50);
    tft.setTextSize(2);
    tft.setTextColor(TFT_WHITE, TFT_BLACK);
    tft.println("Trying to connect Ph2");
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }


  tft.fillScreen(TFT_BLACK);
  tft.pushImage(70, 70, 20, 20, checked);

  tft.setCursor(25, 10);
  tft.setTextSize(2);
  tft.setTextColor(TFT_GREEN, TFT_BLACK);
  tft.println("CONNECTED");
  delay(1200);
  tft.fillScreen(TFT_BLACK);
}

void loop() {

  switchState = digitalRead(SENSOR_PIN1);
  if (switchState != prevSwitchState) {
    if (switchState == HIGH) {
      hits = hits + 1;
      delay(10);
    }
  }


  if (hits == 0) {
    temperature();
  } else if (hits == 1)
  {
    boostGauge();
  } else if (hits >= 1)
  
//Engine Temperature
//Print value is temp_1;



void temperature() {
  int state1 = digitalRead(SENSOR_PIN1);
  float tempTemp = myELM327.engineCoolantTemp();
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    Temp = (uint16_t)tempTemp;
    Serial.print("Temp: "); Serial.println(Temp);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();
  //Temp=0;


  char temp_1[17];


  dtostrf(Temp, 3, 0, temp_1);

  // read the state of the the input pin:
  int state = digitalRead(SENSOR_PIN);

  // Gornja spica
  tft.drawLine(0, 5, 76, 5, 0x92B0);
  tft.drawLine(76, 5, 80, 0, 0x92B0);
  tft.drawLine(80, 0, 84, 5, 0x92B0);
  tft.drawLine(84, 5, 160, 5, 0x92B0);

  { tft.setCursor(15, 10);
    tft.setTextSize(2);
    tft.setTextColor(0x1D9E, TFT_BLACK);
    tft.println("Engine temp");
  }
  /// Donja spica

  tft.drawLine(0, 30, 76, 30, 0x92B0);
  tft.drawLine(76, 30, 80, 35, 0x92B0);
  tft.drawLine(80, 35, 84, 30, 0x92B0);
  tft.drawLine(84, 30, 160, 30, 0x92B0);

  { tft.setCursor(25, 55);
    tft.setTextSize(5);
    tft.setTextColor(TFT_WHITE, TFT_BLACK);
    tft.println(temp_1);

  }

  if (temp > 100) {
    tft.setCursor(25, 55);
    tft.setTextSize(5);
    tft.setTextColor(TFT_RED, TFT_BLACK);
    tft.println(temp_1);
    // tft.drawString(temp_1,25,55,5);
  }




  { tft.setCursor(130, 65);
    tft.setTextSize(3);
    tft.setTextColor(TFT_WHITE, TFT_BLACK);
    tft.println("c");
  }
  tft.drawCircle(149, 63, 2, TFT_WHITE);

  tft.drawLine(0, 110, 76, 110, 0x92B0);
  tft.drawLine(76, 110, 80, 115, 0x92B0);
  tft.drawLine(80, 115, 84, 110, 0x92B0);
  tft.drawLine(84, 110, 160, 110, 0x92B0);


}
void boostGauge() {
  ///uint8_t absBaroPressure();


  float tempManifold = myELM327.manifoldPressure();
  float tempABS = myELM327.absBaroPressure();
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    Manifold = (uint8_t)tempManifold;
    Baro = (uint8_t) tempABS;

    Serial.print("manifoldPressure: "); Serial.println(Manifold);
    Serial.print("AbsolutePressure: "); Serial.println(Baro);

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



  /// Voltage reading from potentiometer sets the Angle-Value to be displayed
  char boost[17];
  float angle;
  // static int OldPotValue = 0;
  static float oldAngle = 0;
  // potValue = analogRead(potPin);
  //if (abs(potValue - OldPotValue) < 7) {
  // potValue = OldPotValue;
  // }

  if ( angle != oldAngle) { // update screen
    // voltage = (3.3 / 4095.0) * potValue; /// Potentiometer to 3.3V

    float angle = 90 + ((Manifold - Baro) / 100) * 27.27 ; // Calculate angle going from 90:180:0:3.3V  +0.1 to eliminate arc draw(180+) if angle is 90
    float boost1 = ((Manifold - Baro) / 100);

    img.drawString("bar", 95, 55, 2);
    dtostrf(boost1, 3, 1, boost);         ///Float to string

    //   tft.drawSmoothArc(x, y, radius, inner_radius, start_angle, end_angle, fg_color, bg_color, arc_end);
    img.drawString(boost, 70, 70, 6); /// Print text value of boost
    img.drawSmoothArc(128, 128, 128, 115, 88, oldAngle, TFT_BLACK, TFT_BLACK, false);  ///Delete arc
    img.drawSmoothArc(128, 128, 128, 115, 88, angle, TFT_WHITE, TFT_BLACK, false);      ////// Draw arc
    img.pushSprite(0, 0);
    //OldPotValue = potValue;
    oldAngle = angle;  ///store old potentiometer value}
  }

}

I left out logo, and checked.h, and loding.h
they are basically an image converted.
Forget about Potentiometer, I just used it to test the TFT screen unitl I mannaged to make the ELM327 talk to ESP32 - I had to get an different elm327 adapter...

Here is it working

//Engine Temperature
//Print value is temp_1;



  void temperature(){
  int state1=digitalRead(SENSOR_PIN1);
  float tempTemp=myELM327.engineCoolantTemp();
if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
Temp = (uint16_t)tempTemp;    
Serial.print("Temp: "); Serial.println(Temp);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();
    //Temp=0;

  
  char temp_1[17];

  
  dtostrf(Temp,3,0,temp_1);

  // read the state of the the input pin:
  int state = digitalRead(SENSOR_PIN);

// Gornja spica
tft.drawLine(0,5,76,5,0x92B0);
tft.drawLine(76,5,80,0,0x92B0);
tft.drawLine(80,0,84,5,0x92B0);
tft.drawLine(84,5,160,5,0x92B0);

{ tft.setCursor(15, 10);
 tft.setTextSize(2);
  tft.setTextColor(0x1D9E,TFT_BLACK);
 tft.println("Engine temp");}
/// Donja spica

tft.drawLine(0,30,76,30,0x92B0);
tft.drawLine(76,30,80,35,0x92B0);
tft.drawLine(80,35,84,30,0x92B0);
tft.drawLine(84,30,160,30,0x92B0);

{ tft.setCursor(25, 55);
 tft.setTextSize(5);
 tft.setTextColor(TFT_WHITE,TFT_BLACK);
 tft.println(temp_1);

 }

 if (temp>100){
 tft.setCursor(25, 55);
tft.setTextSize(5);
tft.setTextColor(TFT_RED,TFT_BLACK);
tft.println(temp_1);
// tft.drawString(temp_1,25,55,5);
 }
 


 
{ tft.setCursor(130, 65);
 tft.setTextSize(3);
  tft.setTextColor(TFT_WHITE,TFT_BLACK);
 tft.println("c");}
 tft.drawCircle(149,63,2,TFT_WHITE);
 
 tft.drawLine(0,110,76,110,0x92B0);
tft.drawLine(76,110,80,115,0x92B0);
tft.drawLine(80,115,84,110,0x92B0);
tft.drawLine(84,110,160,110,0x92B0);


}

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