1

I have connected arduino nano every to my lcd display. It works perfect when i put all my code in setup() part. But when i put the code in loop() it does werid things. I have to put my code in loop(), because i am reading from load cell and displaying the values that are constantly changing. The delay can't be more than 250 ms.

This works well.

#include <LiquidCrystal.h> 
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
 
void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("testing");
} 
  
void loop(){ 


 } 

When I do this next thing it works well for few seconds and then it starts to display random weird characters and stops displaying anything after some time.

#include <LiquidCrystal.h> 
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
 
void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    
} 
  
void loop(){
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(millis()/1000);
  delay(250);
 }

I have tried removing lcd.clear() it didn't help. I thought it was a problem with wiring first, but it's not. What am I doing wrong?

Any help would be great, thanks.

1
  • 1
    What am I doing wrong? ... you are not debugging the code in a logical way ... first, display fixed text, such as hello world and increase the delay time to something like 2 seconds ... that way you eliminate the possibility that the value of millis() is somehow messing up the displayed values ... it also allows you to use a stopwatch to determine how many iterations run before the problem occurs
    – jsotola
    May 29 at 18:48
2
  1. lcd.setCursor(0, 0); - you dont really need this funtion. lcd.clear() will always bring the cursor into the (0,0) position, automatically.

  2. check your wiring. The code seems to be correct

  3. Increase the delay to 500 ms or more. You don't have to write faster than 1 seconds to the LCD anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.