Pages: [1] 2   Go Down
Author Topic: My 20x2 LCD doesnt work properly  (Read 2237 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First of all, im Dutch so excuse me for my English if it isnt right.

I bought a 20x2 LCD display with a HD44780 controller on the back of it. I hooked it up to my Arduino and ran some tutorial code to see or it will work. What I get is some not entirely clear to see text, and I can only display up to 7 characters. My question is: Does anyone of you know how to fix this?

Thanks,
Dorus

Some images of my setup and errors and


the code that is running:


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// Command syntax: LiquidCrystal lcd(RS, RW, Enable, D4, D5, D6, D7)
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
int contrast =0;
int ledpin = 13;
int contrastpin = 2;

void setup() {
  // set up the LCD's number of rows and columns:
 contrast = analogRead(contrastpin);
 Serial.begin(9600);
 Serial.println(contrast);


//lcd.begin(20, );
  // Print a message to the LCD.
  digitalWrite(ledpin, HIGH);
  delay(1000);
    digitalWrite(ledpin, LOW);
    delay(1000);
      digitalWrite(ledpin, HIGH);
 
  lcd.print("123456789");
}

void loop() {

  lcd.setCursor(0, 1);
 
}


* 19092011846.jpg (269.89 KB, 2048x1536 - viewed 28 times.)

* 19092011847.jpg (282.4 KB, 2048x1536 - viewed 24 times.)
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need lcd.begin(20,2); in the setup before you can do anything to the display, such as printing to it.
Logged


Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your quick response, but I already knew I had to start the code with lcd.begin(20, 2);
I already tried to run the code with that in it, but it didnt work either. The only change it made was that the characters where a bit more vague, and thats it. It wasnt an improvement, so I left it out, or should I put it back in?
Or are there other solutions?

Thanks,
Dorus
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I already tried to run the code with that in it, but it didnt work either. The only change it made was that the characters where a bit more vague, and thats it. It wasnt an improvement, so I left it out, or should I put it back in?
You will not be able to use the second line without it.  The characters were vague since the same contrast voltage will produce different results when the display is set up for two lines vs one line.

Now, getting back to your original problem....
It looks like you are using the Arduino to control the contrast.  Using a value of 0 is the same as connicting pin 3 to GND when you typically want a small positive voltage on that pin.  Also there is a conflict between the pin you appear to be using for the contrast [int contrastpin = 2;] and the pin you are using for LCD data line D7  [LiquidCrystal lcd(12, 10, 5, 4, 3, 2);].
 
Also, you want to leave loop() empty.  You should move lcd.setCursor(0, 1); to the end of setup() and use another lcd.print() to put some different information on the second line.

If it still does not work then a clear (focused) photograph showing the connections between your LCD and your Arduino will be needed.


Don
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The readings you see in my code:  contrast = analogRead(contrastpin);  is just to see what the value of my contrast pot was. I hooked pin 3 on the LCD screen, which is defined as C (for contrast) to a potentiometer(10K).
But I will centainly try my code with the void loop() empty, thanks for your response. Ill let you know whether it worked or not.

Dorus
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried running the programme with an empty loop() and also added the lcd.begin(20, 2); And printed something on the second row... which resulted in this.
(See pictures)
It's  not even to see what it should be, so here's the code:

#include <LiquidCrystal.h>
// Command syntax: LiquidCrystal lcd(RS, RW, Enable, D4, D5, D6, D7)
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
int contrast =0;
int ledpin = 13;
int contrastpin = 2;

void setup() {
  lcd.begin(20, 2);
  delay(5000);
 //contrast = analogRead(contrastpin);
// Serial.begin(9600);
// Serial.println(contrast);
  digitalWrite(ledpin, HIGH);
  delay(1000);
    digitalWrite(ledpin, LOW);
    delay(1000);
      digitalWrite(ledpin, HIGH);
 
 lcd.print("Hi1234");
   lcd.setCursor(0, 1);
   lcd.print("Hello");
    lcd.setCursor(0, 2);
}
void loop() { 
}

Dorus


* 20092011849.jpg (308.19 KB, 2048x1536 - viewed 27 times.)
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Need to see details of how you connected the lcd to your arduino. I guess some connections were wrong.
Logged


Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a former software/hardware designer over at my house, and he checked the pins and they were right. But this guy didnt know the Arduino environment, so he couldnt help me with that.
Could it be, in some way, that the LCD is broken or something? Or that the Arduino doesnt support a 2x20 display? Because I only saw 2x16 in some tutorial videos.
But this is how I connected it:
VSS - GND
VDD - +5V
C - Pot wiper
RS - pin12
R/W - GND (for a 0V)
E - pin10
DB7 - pin2
DB6 - pin3
DB5 - pin4
DB4 - pin5
Abacklight - +5V
Cbacklight -  GND

Dorus
« Last Edit: September 20, 2011, 10:42:38 am by Dorus » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

all except you should do LCD pin 16-150ohm resistor-gnd. You need the resistor to limit current through the back light. Any amount up to say 2Kohm is good.
Logged


Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ive put a resistor between Cbacklight and the GND, so my wiring should be alright, i guess. Thanks for pointing me at that smiley. So does anyone know that causes the problems I have?
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to set the cursor before you print the data.
Your choices for the line are 0 and 1, not 1 and 2.


Don
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don, do you mean like this:
 lcd.setCursor(0, 0);
 lcd.print("123456789");
   lcd.setCursor(0, 1);
lcd.print("123456789");
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, except that you want to print more than 9 characters on each line and you want to print different information on the second line.  

Don
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 12
You are never to young to start something new
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried it like this:

lcd.setCursor(0, 0);
lcd.print("Hello World!!!");
lcd.setCursor(0, 1);
lcd.print("123456789101112");

But it didnt work. (Again a picture attached) Could it be that I need to use a different library? Because I read something about the LiquidCrystal440 and the LCD4bit.



* 21092011856.jpg (425.64 KB, 2048x1536 - viewed 30 times.)
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So essentially the display showed the right characters, more or less, but with some noise. Maybe it is bad. Do you have another display from a different source/store or maybe borrow one from a friend?
Logged


Pages: [1] 2   Go Up
Jump to: