missing numbers on temp display

Hello, I’m pulling my hair out over this one…
I’ve made a temp display from an Arduino uno, MAX6675, LCD2004, and a High temp k type thermocouple.
the LCD display wont show all the numbers. if the temperature is 68.80 in the serial monitor it shows as 6.80*F on the LCD Display
How can I get the LCD to display all the numbers for the temperature

#include “max6675.h”// this file is part of the library. See video for details

// start of settings for LCD2004 with I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>// this file is part of the library. See video for details
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
// end of settings for LCD2004 with I2C

int soPin = 12;// SO=Serial Out
int csPin = 10;// CS = chip select CS pin
int sckPin = 13;// SCK = Serial Clock pin

MAX6675 thermocouple(sckPin, csPin, soPin);

void setup() {
lcd.init();// initialize the LCD2004
lcd.backlight();// turn the backlight ON for the LCD

Serial.begin(9600);// initialize serial monitor with 9600 baud
Serial.println(“Robojax MAX6675”);

delay(3);// give time to user to read the display at the beginning
}

void loop() {
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());

lcd.clear();// clear previous values from screen

lcd.setCursor(6,0);// set cursor at character 0, line 1
lcd.print(thermocouple.readCelsius());
lcd.setCursor(12,0);// set cursor at character 9, line 1
lcd.print((char)223);
lcd.setCursor(13,0);// set cursor at character 9, line 1
lcd.print(“C”);

lcd.setCursor(6,2);// set cursor at character 9, line 1
lcd.print(thermocouple.readFahrenheit()); // print temperature in Fahrenheit
lcd.setCursor(12,2);// set cursor at character 9, line 1
lcd.print((char)223);
lcd.setCursor(13,2);// set cursor at character 9, line 1
lcd.print(“F”);
delay(500);
}

delay(500);
}

Are the number correct in the serial monitor ?

Can you make a layout for the text, and put that in the sketch.
I use this:

// LCD display
// 
//     01234567890123456789
//    +--------------------
//   0|      20.44 *C
//   1|      68.80 *F
//   2|
//   3|

It should also be possible to print negative numbers. When writing a new value, you can print a few spaces to remove the old value or you can build a new text in a buffer with the proper format that overwrites the old value.

Suppose the old value is "11.11" and the new value is "9.99", then the display might show "9.991", because there was still that "1" from the previous number.

By the way, I can not spot the bug :frowning:

Can you confirm you did not have any spelling mistake when you say one is showing as 68.80 and the other a 6.80? Those are very different values by a factor 10ish

Try reading the temperature only once into float variables so that you print from the same source of data

What are all those crappy comments next to the setCursor () calls? They are not matching the code. How do we know what is right?

Please edit your post.

Replace the first by [code].
Replace the second one by [/code].

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Koepel,
Yes the numbers are correct in the serial monitor.
I apologise, but I'm not sure what you mean by a "layout"... I'm a bit new to this.

please answer also questions from #2 (and fix code tags)

J-M-L:
Can you confirm you did not have any spelling mistake when you say one is showing as 68.80 and the other a 6.80? Those are very different values by a factor 10ish

Try reading the temperature only once into float variables so that you print from the same source of data

What are all those crappy comments next to the setCursor () calls? They are not matching the code. How do we know what is right?

Yes, I can confirm that is not a spelling error. You are reading that correctly.
Those "crappy comments" are my bad. Those were in the sketch I copied from, and I changed the numbers to adjust the position of the numbers on the LCD, but never change the comments. My bad.

sterretje,
Thank you for showing me what I did wrong in posting the code. As I've said, I'm new to this stuff, particularly posting in a forum.
In the forum rules it just seems to assume you know exactly how to do what they want you to do. I don't....

Ok, Sorry everyone. Apparently I posted my code wrong. :o
So here is the fixed code…

#include "max6675.h"
// start of settings for LCD2004 with I2C
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
// end of settings for LCD2004 with I2C

int soPin = 12;// SO=Serial Out
int csPin = 10;// CS = chip select CS pin
int sckPin = 13;// SCK = Serial Clock pin

MAX6675 thermocouple(sckPin, csPin, soPin);


void setup() {
  lcd.init();// initialize the LCD2004
  lcd.backlight();
     
          
  Serial.begin(9600);// initialize serial monitor with 9600 baud
  Serial.println("MAX6675"); 
    
 delay(3);
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("C =  "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());

  lcd.clear();// clear previous values from screen 

      lcd.setCursor(6,0);
      lcd.print(thermocouple.readCelsius()); 
      lcd.setCursor(12,0);
      lcd.print((char)223); 
      lcd.setCursor(13,0);
      lcd.print("C");    
                  
      
      lcd.setCursor(6,2);
      lcd.print(thermocouple.readFahrenheit());
      lcd.setCursor(12,2);    
      lcd.print((char)223); 
      lcd.setCursor(13,2);
      lcd.print("F");           
   delay(500);
}

Here is a diagram of the circuit in question

Thanks for the extra information. I still can't see the bug :frowning: Is the Fahrenheit still printed wrong ? Can you give a few examples what should be displayed and what is shown on the display ?

With "layout" I mean where everything is on your display. Where is the 'C' for Celsius en where the 'F' for Fahrenheit, where is the number, the negative sign and so on.

I see now that you have a lcd.clear() in the loop(). That removes any previous text from the display. When you have the "layout" written down, it is possible to omit the lcd.clear() and over-write the previous number. Maybe that is an improvement for later.

I would change your code to follow the advice of post #2

Try reading the temperature only once into float variables so that you print from the same source of data

J-M-L:
Try reading the temperature only once into float variables so that you print from the same source of data

I am so sorry, I'm still learning the coding part of this. I'm mostly a copy and paste idiot at the moment. I goof around with that and learn what changes, so... Learning...
Can anyone show me what this means and how to implement. I will research. but help is much appreciated.
**Que "pulling hair out" meme.....

You call "thermocouple.readCelsius()" and "thermocouple.readFahrenheit()" to send them to the serial monitor.
Then you call those functions again to show them on the LCD display.
That means you might send something different to the serial monitor than you show on the LCD display.

Read them once and put them in 'float' variables. Let's call those variables 'temperatureC' and 'temperatureF'.

void loop()
{
  float temperatureC = thermocouple.readCelsius();
  float temperatureF = thermocouple.readFahrenheit();

  ...

  Serial.print( "C =  ");
  Serial.println( temperatureC);
  Serial.print( "F = ");
  Serial.println( temperatureF);

  ...

  lcd.setCursor( 6,0);
  lcd.print( temperatureC);

  ...

  lcd.setCursor( 6,2);
  lcd.print( temperatureF);

I hope this is enough information. We are not going to give you a full sketch.

Koepel:
You call "thermocouple.readCelsius()" and "thermocouple.readFahrenheit()" to send them to the serial monitor.
Then you call those functions again to show them on the LCD display.
That means you might send something different to the serial monitor than you show on the LCD display.

Read them once and put them in 'float' variables. Let's call those variables 'temperatureC' and 'temperatureF'.

void loop()

{
 float temperatureC = thermocouple.readCelsius();
 float temperatureF = thermocouple.readFahrenheit();

...

Serial.print( "C =  ");
 Serial.println( temperatureC);
 Serial.print( "F = ");
 Serial.println( temperatureF);

...

lcd.setCursor( 6,0);
 lcd.print( temperatureC);

...

lcd.setCursor( 6,2);
 lcd.print( temperatureF);




I hope this is enough information. We are not going to give you a full sketch.

No, that makes sense enough for me to muddle thru. Got it to work even.... :slight_smile: same results... >:(.
even set this up on an LCD1602 ic2 display. same thing.

Can you tell what the result is for different values ? For example "1.00", "10.00", "100.00".

same results... >:(.
even set this up on an LCD1602 ic2 display. same thing.

A mystery indeed. When you changed from the 20x4 to the 16x2 were you using the same i2c backpack expander, or was that changed with the display?

The best available library for the i2c lcd displays is called hd44780.h. written by Bill Perry. It is available through the library manager.

I would suggest that you convert to it. It is plug and play for a variety of configurations of the i2c backpack modules.

As part of the library there is a comprehensive diagnostic sketch which will test some internal details of the display. It's called I2CexpDiag

In the in the ide you can navigate to the library example

File>Examples>hd44780>ioclass>hd44780_I2Cexp>I2CexpDiag

cattledog:
A mystery indeed. When you changed from the 20x4 to the 16x2 were you using the same i2c backpack expander, or was that changed with the display.

I changed the i2c module also

cattledog:
The best available library for the i2c lcd displays is called hd44780.h. written by Bill Perry. It is available through the library manager

I will look for that one. And hope it makes a difference.

Koepel:
Can you tell what the result is for different values ? For example "1.00", "10.00", "100.00".

It literally only shows the first digit of the whole number. So if it's 1.23 degrees it'll show 1.23 degrees.
But if it's 12.34 degrees it shows 1.34 degrees. Same if it's 123.45 degrees. Still only shows 1.45 degrees.
Now mind you... In the serial monitor it shows all the correct values but on the LCD they are all truncated as I have said...