Converting FLOAT variables to STRS to display onto LCD screen

Hi All,

I’m currently working on a PID device for a personal project. This device uses a thermosistor to record a temperature from the heating element and takes this information to keep the temperature in a certain range.

My problem is currently displaying the float variables from the thermosistor onto the LCD screen.

I’ve checked that my thermosistor is hooked up properly, and I’m able to put words onto my LCD screen, but when I run the sketch, it gives me a “NAN” reading on the LCD which means there’s no input being read.

Can someone help me convert float vars to string vars? I’ve tried the dtostrf() and the sprintf() functions and no dice. The code is attached

/*    Max6675 Module  ==>   Arduino
 *    CS              ==>     D10
 *    SO              ==>     D12
 *    SCK             ==>     D13
 *    Vcc             ==>     Vcc (5v)
 *    Gnd             ==>     Gnd      */

//LCD config
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>    //If you don't have the LiquidCrystal_I2C library, download it and install it
#include <LiquidCrystal.h> 
LiquidCrystal_I2C lcd(0x27,20,4);  //sometimes the adress is not 0x3f. Change to 0x27 if it dosn't work.

//  i2c LCD Module  ==>   Arduino
//  SCL             ==>     A5
//  SDA             ==>     A4
//  Vcc             ==>     Vcc (5v)
//  Gnd             ==>     Gnd      

#include <SPI.h>

#define MAX6675_CS   10
#define MAX6675_SO   12
#define MAX6675_SCK  13

void setup() {
  lcd.begin();
  lcd.backlight();
  
}

void loop() {
  
  float temperature_read = readThermocouple();
  //sensorValue = analogRead(battPin); // ADC read
  float fTEMP_READ;
  int iTEMP_READ;
  char pinA0[50];
  fTEMP_READ = (((float)temperature_read/1024.0f)*1.1f)/(0.124f)*1000.0f;  // ADC calibration
  iTEMP_READ = (int)fTEMP_READ; // Conversion of float to integer
  char TEMP_READ_STR[5]; //Assignment of char
//  sprintf(TEMP_READ_STR,"%d",iTEMP_READ); // Copying integer to char as string
//  sprintf(pinA0,"%c.%c%c f  ",TEMP_READ_STR[0],TEMP_READ_STR[1],TEMP_READ_STR[2]); // Using indexed arguments to put each number in the right place - notice the manually inserted decimal point. 
  dtostrf( temperature_read,4,2,pinA0); // Copying integer to char as string
//  dtostrf(pinA0,"%c%c.%c%c F ",TEMP_READ_STR[0],TEMP_READ_STR[1],TEMP_READ_STR[2]TEMP_READ_STR[3]); // Using indexed arguments to put each number in the right place - notice the manually inserted decimal point. 
  lcd.setCursor(0,0);
  lcd.print("TEMPERATURE");
  lcd.setCursor(7,1);  
  lcd.print(pinA0);    
  lcd.setCursor(10,1);  
  lcd.print("F");    
  delay(300);
}


double readThermocouple() {

  uint16_t v;
  pinMode(MAX6675_CS, OUTPUT);
  pinMode(MAX6675_SO, INPUT);
  pinMode(MAX6675_SCK, OUTPUT);
  
  digitalWrite(MAX6675_CS, LOW);
  delay(1);

  // Read in 16 bits,
  //  15    = 0 always
  //  14..2 = 0.25 degree counts MSB First
  //  2     = 1 if thermocouple is open circuit  
  //  1..0  = uninteresting status
  
  v = shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
  v <<= 8;
  v |= shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
  
  digitalWrite(MAX6675_CS, HIGH);
  if (v & 0x4) 
  {    
    // Bit 2 indicates if the thermocouple is disconnected
    return NAN;     
  }

  // The lower three bits (0,1,2) are discarded status bits
  v >>= 3;

  // The remaining bits are the number of 0.25 degree (C) counts
  return v*0.25;
}

Thank you for the help!

when I run the sketch, it gives me a “NAN” reading on the LCD which means there’s no input being read.

Check the wiring and connections

If the thermocouple is disconnected then the readThermocouple() function will return NAN