lcd adding 0 to string on start up

Hi,

I'm having an issue with my lcd adding a 0 to the reading on my ds18b20 on power up. Once I reset the extra character goes away. Also, when I pull the pin for the probe out to check the "Error" message there is a 6 added at the end and when I replace the cable the lcd displays the temp probe reading with r6 at the end.

any help would be greatly appreciated.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DallasTemperature sensors(&oneWire);

DeviceAddress Fermenter1 = { 0x28, 0xEE, 0x4C, 0xF4, 0x18, 0x16, 0x02, 0x06 };
DeviceAddress Fermenter2 = { 0x28, 0xFF, 0xA8, 0x96, 0x56, 0x16, 0x04, 0x20 };

  float tempF1;
  float tempF2;

  String err = "Error"; 
    
void setup(){
  lcd.begin(16,2);
  lcd.clear();
  Serial.begin(9600);
  
  sensors.begin();

  
  lcd.setCursor(0,0);
  lcd.print("Fmntr1   Fmntr2");
  sensors.setResolution(Fermenter1, 11);
  sensors.setResolution(Fermenter2, 11); 

   
} 
void loop(){   
  
  tempF1 = sensors.getTempF(Fermenter1); 
  tempF2 = sensors.getTempF(Fermenter2);    
  
  sensors.requestTemperatures();
   delay(100);

  
  lcd.setCursor(0,1);
  lcd.print(tempF1,1);
   if (tempF1 == -196.60){
    lcd.setCursor (0,1);
    lcd.print (err);
   }else{
    lcd.setCursor(0,1);
    lcd.print(tempF1,1);
   }
   
  lcd.setCursor(9,1);
  lcd.print(tempF2,1);
   if (tempF2 == -196.60){
    lcd.setCursor (9,1);
    lcd.print (err);
   }else{
    lcd.setCursor(9,1);
    lcd.print(tempF2,1);
    }
}
lcd.setCursor(0,1);
  lcd.print(tempF1,1);
   if (tempF1 == -196.60){
    lcd.setCursor (0,1);
    lcd.print (err);
   }else{
    lcd.setCursor(0,1);
    lcd.print(tempF1,1);
   }

What's the purpose of those first two lines if you are just going to either overwrite it with "err" or the same thing again a few lines later?

My guess is that the first reading from the sensor is different and you have leftover characters on the screen when it prints the second time because you don't clear your screen between calls to print on it. If you don't want to clear the whole screen you could just print 16 spaces on the bottom row to just clear that.

Thanks, clearing the second line with blank spaces did the trick.

I think you could have fixed this by printing leading blank characters for small numbers, thereby ensuring the decimal point is always in the same place. I believe that is normal procedure.

I would also be suss about the data you are getting with such a resolution, and the short delay time - not to mention the point of the exercise. It is possible that the loop timing is determined by the conversion time taken by the sensor, in this instance 375 ms, or you are simply triplicating readings.

Similalrly, a delay 1000 inserted in the setup will enable the sensor to settle down and thereby refrain from sending an extraneous reading on startup.