Beginner problems with 1602

Hi,
I’m fairly new to Arduino scene - I just received my starter kit, and I decided to dive into it by trying to follow some of the tutorials. Right now I’m trying to connect LCD display (1602a 2.0) to my Arduino Uno, but I’m struggling to display anything at all. Rather than my text, I just see two lines of boxes - one full height, and one smaller. What am I doing wrong?

Here is a photo of my wiring:

And here is pretty simple code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("hello");
}

You have at least two problems.

The easy one is the code. You do not want to keep printing your message over and over again, especially with no delay in your loop. Move the lcd.print(...) statement into setup and leave loop() empty for now.

The hard one is the fact that your LCD display itself may have a problem and it is certainly not being initialized properly, possibly due to one or more bad wires.

Try removing the six LCD control and data wires leaving just pins 1, 2, 3, 15, and 16. You should be able to adjust the contrast until you have a single row of blocks, without the 'smaller height' row that you presently have. If you can't get this then nothing you do with your code will help.

If that is OK then reconnect your data and control lines and run the revised code.

Don

And in regard to the code, the more general concept you need to grasp.

There are two sections. "setup()" is the "do once" part. Things you do to - well, set up things - ready to do your work.

"loop()" is the "worker" part - it gets the job done.

How it gets the job done is to perform a set of tasks really fast - it literally runs in a loop again and again - at machine speed, which means thousands or just possibly millions of times each second. This is much faster than mechanical things can operate, certainly vastly faster then a human can think or act (for relatively straightforward computational tasks at least) and in fact, faster than a LCD (of this sort at least) can possibly respond.

So using the loop means making decisions - fast decisions - and not literally confusing the code. As has been pointed out, if you want to print "hello" once - to start with - then put it in setup(). If however, you need to print it at some other time, then it requires a decision branch within the loop(). You would say if a certain condition occurs, then you print it, but you then set a flag to say you have printed it. Then next time round the loop (which will be almost instantaneous because you should never waste time anywhere in the loop; you do not use "delay()" in any but the most basic demonstration sketches;) you check not only the event for which you needed to print the certain message, but also the flag to tell that you have already printed that message and therefore do not attempt to print it again.

While this might seem a trifle tedious, this approach is the prerequisite for performing more than one task apparently simultaneously.

Thank you for your help.

floresta:
The easy one is the code. You do not want to keep printing your message over and over again, especially with no delay in your loop. Move the lcd.print(…) statement into setup and leave loop() empty for now.

Revised code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

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

void loop() {
}

floresta:
The hard one is the fact that your LCD display itself may have a problem and it is certainly not being initialized properly, possibly due to one or more bad wires.

Try removing the six LCD control and data wires leaving just pins 1, 2, 3, 15, and 16. You should be able to adjust the contrast until you have a single row of blocks, without the ‘smaller height’ row that you presently have. If you can’t get this then nothing you do with your code will help.

If that is OK then reconnect your data and control lines and run the revised code.

I left only pins 1, 2, 3, 15 and 16. I was able to adjust the contrast, and indeed, single row of blocks was visible. Photo:

I also checked (using a LED) that all data wires are working properly.

Unfortunately, after reconnecting data wires and running the code, I see only single row of squares. I tried messing with the lcd constructor (LiquidCrystal lcd(12, 11, 5, 4, 3, 2)) and change numbers there, but it didn’t do anything. Also, I tried changing parameters in begin and setCursor invocations, but the only difference it made was that sometimes there were 2 rows of squares instead of one.

Quite honestly, the wiring from the photo in message #1 looks correct. Thankyou for using different coloured wires. Obviously you should double-check for yourself.

I suspect that one of your jumper wires is broken. Replace one wire at a time.

Adjust your contrast so that you only just see the boxes. This will be when pin#3 is at 0V or so.

David.

Edit. Thanks, Paul. I have corrected the pin number.

david_prentice: Adjust your contrast so that you only just see the boxes. This will be when pin#2 is at 0V or so.

Actually, it is pin 3 and it wil generally want to be between 0.2 and 0.5 V for a 5 V supply.

I can't spot a problem. :'(