Problems with 16x2 LCD - writes fine but after 10s disintegrates to weird chars

Hello all,

I really hope you help me figure out what I'm doing wrong.

I have an 16x2 LCD which I have used for many other projects but in this one I get some weird response.

I have written a small program that illustrates it:

#include <LiquidCrystal.h>

//---------LCD---------
LiquidCrystal lcd(11, 10, 9, 8, 7, 6);
const int contrastPin = A0;

void setup(){
	analogWrite(contrastPin, 20); //Setting the contrast
	//LCD
	lcd.begin(16, 2);
	lcd.setCursor(0, 0);
	lcd.print("Ideart");
	lcd.setCursor(0, 1);
	lcd.print("Homelab Exp");
}

void loop(){
	lcd.setCursor(0, 0);
	lcd.print("Dette er skrevet");
	delay(1000);
	lcd.setCursor(0, 1);
	lcd.print("i loop.");
}

When I run this I get the first picture as expected:

But after about 10 seconds or so it turns into this:

Do any of you have idea about what could be the issue. I'm completely lost in this. If I only use lcd.print in the setup - I have no problems at all...

Hi Muppo.

Your code is pretty standard, so i'm not sure what's wrong here.
So do check your hardware, especially the wiring.
Tip: help yourself to debug this.
"after about 10 seconds or so" isn't very helpful.
So add a counter and print its value to the 2nd line on your display, it's an easy hack to your code so far.

And about this:

const int contrastPin = A0;
.
.
.
  analogWrite(contrastPin, 20); //Setting the contrast

Did you connect the contrast pin directly to the A0 analog input pin ?
And are you trying to control the contrast by sending a PWM value of some 8 % ?
Do check (by measurement) to see that does what you are expecting it to do, i'm curious about that.

What happens if you remove everything between the { } brackets in loop()?

Don

MAS3:

const int contrastPin = A0;

.
.
.
  analogWrite(contrastPin, 20); //Setting the contrast

Yeah, that ain't gonna work.

Talk to us about your power source. How are you powering the LCD? How are you powering arduino?

Yeah, that ain't gonna work.

Just curious, how do you explain the fact that the characters on his screen appear to have acceptable contrast?

Don

I don't know. But I do know that analogWrite of 20 on A0 is equivalent to digitalWrite A0 to LOW.

... But I do know that analogWrite of 20 on A0 is equivalent to digitalWrite A0 to LOW.

That puts the contrast level at 0V which is acceptable for many displays, as evidenced by his photographs.

Don

Why would anyone want to Analogwrite to the contrast pin?
A 470R resistor would be simpler. A potentiometer if you want something more complex.

I doubt if the rest of the LCD wiring appreciates having sharp edged pulses on the contrast pin. An RC low-pass filter would be kinder.

I bet that improving the electrical environment would solve your problems.

Mind you, your intententional text looks like gobbledygook to me.

David.

Hey everyone,

First of all thank you for time here. Let me try to explain some of the questions you have.

Using A0 to control the contrast is something I have used many times and have no problems with, so saying it won't work is, I'm sorry to say so, just plain wrong. Doing it this way makes you able to control the contrast via software instead of hardware. However, the reason it says 20 is because I was testing it out and I do not ha e the control I want in this application just yet. But as you can clearly see, I have no issues what so ever with writing to the lcd in the setup routine and it will stay on the screen for as long as I leave the Arduino turned on. That is also why I am so perplexed with this.

In regards to the power, I use a LM7805 to regulate my input voltage of 12 V down to 5V to power the Arduino and the lcd. I have installed a 220 nF capacitor between the input and ground on the LM7805.

Again, I have measured the voltage supplied to the lcd (app. 4.7V) so I wanna power it more directly from the 7805 as right now it's via a homemade PCB, but it still makes me wonder why it works fine if just within the setup routine.

The intentional text basically just says "This is written in the loop" the "Exp" is just a remnant from what I wrote in the setup.

I can easily do a milis() and print it to the second line but I am away with work so I won't be able to implement it before next Monday. The time it took just seemed so arbitrarily as I did nothing new and it just fails after those app. 10 seconds.

Sure you can use A0 for the contrast if you want and it works for you. But use digitalWrite on it and just write it low. If you will go and look at the source code for analogWrite you'll see that is what happens when you try to analogWrite a value less than 128 to a non-PWM pin. It just bails out and calls digitalWrite with LOW.

You can claim all you want that you know it works. But we all have the source code and we all have the datasheet for the chip and we all know what really happens there. It's not in any way ambiguous.

Muppo:
Using A0 to control the contrast is something I have used many times and have no problems with, so saying it won't work is, I'm sorry to say so, just plain wrong.

So you are claiming that you can adjust the contrast using the A0 pin and analogWrite() ?
What Arduino board have you done this with?
None of the Arduino boards I've seen support PWM on the A0 pin.
(Which is what Delta_G has been saying as well)

--- bill

It is not possible to see what Arduino you are using.
God designed the Uno with a regulator and appropriate capacitors.
The original 7805 was unstable with the wrong input and output capacitors.
Providing you have an appropriate current limiting resistor on the 16x2 backlight, the regulator will not have a high power dissipation.

My suggestion that raw PWM might cause electrical noise interference does not apply for A0. It is beig used as Digital pin.

Seriously, the 16x2 should be stable if you have sensible wiring layout.
Please post a photo of your pcb and soldering.

David.

In terms of what is going on. I'd predict some kind of power supply issue.
The reasoning being.
Your first photo shows that the LCD is wired correctly, and that the Arduino s/w is able to initalized the LCD and print characters to it with acceptable contrast.
The 2nd photo show a display that appears to be in its default powerup state.
If the contrast had suddenly changed to something bad, then all the character positions should look the same.
That isn't the case.

Also,

In regards to the power, I use a LM7805 to regulate my input voltage of 12 V down to 5V to power the Arduino and the lcd. I have installed a 220 nF capacitor between the input and ground on the LM7805.

That is not the recommended way to hook up a LM7805 according to the datasheet.

My guess would be that the power supply voltage failed in some way but then came back to an acceptable level at least for the LCD and the Arduino is not happy enough with the power to run so the LCD is in an un-initialized state.

How about giving us a full schematic of what you using?

-- bill

It's a custom PCB build with an Arduino nano and a separate LM7805 (thus not he one actually on the board) . As I wrote I am away with work so I won't be able to post the schematics until I am back home Monday but I will for sure when I can.

As I said I did have problems with the contrast control on this particular application but have used it successfully on other projects (hence the 20 I write with analogWrite in order to test it) but at this point I just want it to work properly and I am trying to learn to make the PCB in a decent way and implement it into a complete solution so it's not always just breadboard projects

The display is working fine (picture 1) and then 'disintegrates". Fortunately this disintegration is not literal (American movies: lots of sparks coming out of the poor display accompanied by cracking and smoking).

It looks as if contrast in the upper line goes all the way up and that in the lower line all the way down (pictures 2). In other woreds: the display displays your text, but the text cannot be read because the contrast screws up! This points towards a contrast issue -- hence the remarks on the A0.
I recommend two actions:

  1. Show a wiring diagram and/or a picture as detailed as picture 1 and 2 of the back of your unit.

  2. I would certainly recommend to connect the wiper of a 10 pot meter to pin #3 of the LCD display and run the sketch you provided us with.

  3. I learned at school that if the problem keeps appearling after replacing the 'faulty' decvce (i.c. the LCD display) with a similar one, then it is most probably a wiring problem or a software problem.
    Hearing from you when you have returned home !

photoncatcher:
It looks as if contrast in the upper line goes all the way up and that in the lower line all the way down (pictures 2). In other woreds: the display displays your text, but the text cannot be read because the contrast screws up! This points towards a contrast issue -- hence the remarks on the A0.

But that isn't possible given the way the contrast on the LCD works.
The contrast for all rows is the same. i.e. is not possible to have different contrast on different lines.

Like I said earlier it really looks like the LCD has power cycled and then hasn't been re-initialized.
An uninitialised LCD will display a row of blocks just like what is in the second photo.

--- bill

Muppo:
As I said I did have problems with the contrast control on this particular application but have used it successfully on other projects

Not using pin A0 since A0 is not a PWM pin. And that is what several of us keep trying to explain to you.

--- bill

I'd say don't discuss, just rebuild it using the recommended and standard way to control the contrast.
Just so you can rule out (or not) that this leads to your issue.

Also, if you are using a breadboard, either re-wire it using other contacts, or get rid of it for now.
Breadboards are nice for quick and easy prototyping, but always expect poor contacts.

All of us can't wait for you to return home so you can go on with your experiments.
So do tell us about what you found, when you find out what's going on.

Still waiting for an answer to the question in reply #2.

Don

Tried to duplicate your experience with an arduino Nano and a parallel (12,11,5,4,3,2) 16x2 LCD display with A0 connected to pin 3 (contrast) of the display.
This the result: steady image "Dette er skrevet i loop. Exp". No desintegration whatsoever!