I am very new to Arduino so this might be a very simple question
I am currently doing this on tinkercad but basically I have 2 temperature sensors to mimic the temperature outside and inside and I want both of the temperatures to show up on the lcd on both separate lines. However I can't seem to get it to work because the text keeps on glitching out on one line.
Here is my code:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int degree_inside;
double realDegree_inside;
int degree_outside;
double realDegree_outside;
String lcdBuffer;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
degree_inside = 0;
realDegree_inside = 0;
degree_outside = 0;
realDegree_outside = 0;
//lcd.setCursor(0,0);
//lcd.print("Inside:");
//lcd.setCursor(1,0);
//lcd.print("Outside:");
// Print a message to the LCD.
}
void loop(){
lcd.print(" ");
degree_inside = analogRead(0);
realDegree_inside = (double)degree_inside/1024;
realDegree_inside *= 5;
realDegree_inside -= 0.5;
realDegree_inside *= 100;
degree_outside = analogRead(1);
realDegree_outside = (double)degree_outside/1024;
realDegree_outside *= 5;
realDegree_outside -= 0.5;
realDegree_outside *= 100;
lcd.setCursor(0,0);
String output_inside = "Inside: " + String(realDegree_inside) + String((char)178) + "C";
lcd.print(output_inside);
lcd.setCursor(1,0);
String output_outside = "Outside: " + String(realDegree_outside) + String((char)178) + "C";
lcd.print(output_outside);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
}
Any ideas what I may be doing wrong or maybe any suggestions?
Between "LCD 2 lines of text updating at the same time" and "However I can't seem to get it to work because the text keeps on glitching out on one line." the issue remains vague.
Are you using an Uno?
double is irrelevant on an Uno and is the same as float.
I found that with setting floats to a default or hard coded value to use the 'f' to designate a float. Like this degree_inside = 0.0f; or you may find your floats are converted to ints.
does that pad a bunch of spaces into the LCD, then you add info to those padded spaces, no?
Your code waits too long to convert the value to float, you might end up with ints.
The Uno and the Mega can be tricky with floats, I found being very explicit when using floats works best.
You may find strange things start to happen after your code has been running for a while because you are using the String class on a real Uno.
Use of the String class can cause memory contamination. Better to use strings (null terminated character arrays).
That was my experience 3+ years ago, since then I just 'X.Xf' my floats as a matter of habit. Since I switched over to using ESP32's I do not have anymore Uno's or Mega's. I gave them to a summer STM program. Thus, I'll not be making an attempt to reproduce the matter.