Lcd1602 Hello world example prints hello, world but not counting

Hi!
I loaded the Hello world example project to my UNO board, it prints out "hello, world" as it shoud and in the second row it prints a 0 but its not counting. I loaded an another LCD example on the board (Blink) and there I observed that for a random amount of time it works fine (1-15 sec aprox), lcd.noBlink() active for 3 seconds (delay(3000)) and then the lcd.blink() is active for 3 seconds. But then its like those 3 seconds delays is... disappearing? its starts to blink very fast without delay.
In these cases i used the example sketches unmodified and checked the wiring10 times, also replaced all of my wires. (used the original arduino wiring diagram).
Then i modified the Hello world to print the value of millis() to the serial monitor, and it printed a random constant number(usually below 100) and it did not change till i reset then printed another also constant number. I thought my UNO is broken, then i made a new project (with empty setup and loop) and I tried to print the value of millis to serial monitor there and it worked fine.
Then i tried this instead of the millis/1000 in the Hello world example:

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i=0;

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0,1);
  lcd.print(i);
  i++;
  delay(1000);
}

It works for some seconds (10-20 aprox) then it starts to count very fast without the 1s delay, like the delay goes down to 0 from 1000 on its own after working fine for some seconds (I think this isnt what is actually happening, but i can describe it like this).

Maybe my board is bad? or any ideas why is this happening?

@qtrk, your topic has been moved to a more suitable location on the forum.

1 Like

Are you using a breadboard, by any chance? What are you using for power?
Paul

Hi,
does your UNO have the Atmega328 DIP or SMD?

Post a picture of your UNO.

RV mineirin

Yes, I am using a breadboard. To power the LCD I am using the arduino 5V power supply, and I power the arduino from a windows pc.

187342460_195237515665387_3034375101143779865_n
This is my UNO board.

Your sketch runs as supposed in the Wokwi simulator: https://wokwi.com/arduino/projects/298690276166205962.
In the middle-upper of the screen is the start button.

1 Like

Yes, this is how it should work, but for me it works something like this:
https://wokwi.com/arduino/projects/298692059943928333
I edited the code to show you how it works for me. If i use the code you used this is what I see.
Its like my UNOs clock is not working how it should.

1 Like

You logged in at Wokwi, save a copy of my project, and altered the code just to show me what it looks like ? Thank you, that is very cool :sunglasses:

Let me start by saying: It is not possible.

If there was something wrong with the clock, then the Arduino would not run.
Do you have another Arduino board ? Have you damaged this one ? Can you add a capacitor between the 5V pin and the GND ? Can you measure the 5V pin ? It should be above 4V.
Can you upload a sketch that does something completely different, and check that the new sketch actually works.

I do sometimes this:

void setup()
{
  Serial.begin( 9600);
  Serial.println( "My blink sketch version 5");
}
1 Like

Hi,

Make a test by turning off the LCD, and use only the Serial.
Run this sketch and see what happens on the serial monitor.
RV mineirin

int i = 0;
void setup () {
   Serial.begin (9600);
}

void loop () {
  
   i ++;
   Serial.println (i);
     delay (1000);
}
2 Likes


This is what actually happens, above the blue line everything is fine, it goes up by 1 every second, then as you see it just starts counting multiple times in a second. It went up to 2500 withn 10 seconds.
I measured the uno input/output voltage, it was around 5-5.10V.
Unfortunately i dont have another arduino board, but i did some other projects on this one (Im really new to arduino, just learning and expreimenting) and it worked fine, a never had trouble with the delay() function before.

Please, remove LCD lib e all lines for LCD

RV mineirin

2 Likes

If i use the code you gave its working on the serial monitor:


It went up to 400 2 time without any problem.

If i print millis() in the Hello world exemple this is what i get:


its constant 25 or other random constant number, if i print it in a blank project its printing the correct value.

Hi,
I think you have a problem with your LCD library.

RV mineirin

1 Like

You needed to run the exact sketch that @ruilviana showed.
There seems to be a memory problem in your LCD library, possibly overwriting data or stack.

Do you know where the libraries are ?
Did you install something in the Arduino program directory ? I hope not.

The downloaded and user-installed libraries are in the "libraries" folder next to your project folders. In Windows in "Documents / Arduino / libraries".

Can you delete every LCD library from that folder. Also remove all unknown libraries and libraries that are already included with the Arduino IDE.

The "hd44780" library seems to be used a lot these days, but I have not used it myself yet.

Did you install the Arduino IDE from this website (arduino.cc) ?
Is it possible that there was an old version on your computer ? Then you should delete the Arduino folder in the Program Files and delete the hidden "arduino15" folder and reinstall the newest Arduino IDE.

1 Like

I ran that exact code, you can see it above.
I downloaded the IDE like 2 weeks ago, my LCD didnt worked, then i downloaded the new 2.0 IDE (both from the arduino.cc of course), didnt worked with that neither.
So my idea was that i install the IDE on a mac, its fresh, I didnt modified anything, i just downloaded the CH34x driver and the IDE and I get the same problem there. I didnt installed any aditional libraries. So i think the problem is with my UNO or with both of my computers (I hope not).
The only thing in common is the CH34x driver, but i think its unlikely to be the problem.

There are many LCD libraries.
You use the one that is included in the Arduino IDE, with the "Hello World!" example, and it printed random millis()/1000 values.

I'm sorry that you ran into this. I hope you are not disappointed in Arduino. I should not happen. I have not heard of such a problem before.
What do you want to do ? You could do many tests, but it is better to buy a new Arduino board and re-install the Arduino IDE and use another LCD display with another LCD library.

There is a new version of the Arduino IDE, version 1.8.15. It is almost the same as 1.8.13.
It is allowed to install both 1.8.13 or 1.8.15 and the new 2.0-beta. That is no problem.

I suggest to buy a new Arduino board. A clone is okay, but not the same board from the same seller.
There are I2C LCD displays. Then you only need two wires (and also 5V and GND), so there is less chance for a wiring mistake.

If you are willing to do some test, then you could send millis()/1000 to the serial monitor, but be sure that nothing of the LiquidCrystal library is in your sketch and the display is not connected. I'm afraid you can do many tests, without getting anywhere. You need another Arduino board to compare the results.

void setup() 
{
  Serial.begin( 9600);
  Serial.println( "The sketch has started");
}

void loop() 
{
  Serial.println( millis() / 1000);
  delay( 1000);
}

Did you download the CH340G driver from the website of the manufacturer ?
The download button and that page is this:
downloadbutton

Have you measured the voltage of the 5V pin ? If it is too low, it could explain this behaviour. Do you have a multimeter ? Can you find a better USB cable ?

1 Like

To me, it appears that this library: #include <LiquidCrystal.h> is blocking timer0, maybe by suspending interrupts. This causes delay() to spin wildly see [SOLVED] Why does delay() not hang in an ISR?. It could well be that a recent update to the IDE has disturbed the functioning of an old library, especially if some obscure low level programming was used, possibly relying on some non-documented feature.

The results shown in post #13 (no LiquidCrystal library) look good.

Were these tests below on various platforms performed with or without the LiquidCrystal library ?

Interesting would be to try this. It is the code in the OP with one addition.

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i=0;

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0,1);
  lcd.print(i);
  i++;
  interrupts() ; //  RESUME INTERRUPTS TO SEE IF THIS IS THE ISSUE
  delay(1000);
}
2 Likes

Without the LiquidCrystal library it looks like all is working fine:


Its increses as it should.

This was my first idea too, so i tried 2 USB cables and measures the input/output voltages. All voltage was 5V +- 0.1.
If I cant resolve the issue I will borrow one and try with that one to see if it works.