Go Down

Topic: LCD Shield not behaving (Read 8819 times) previous topic - next topic

Mar 08, 2012, 06:52 am Last Edit: Mar 08, 2012, 03:21 pm by vanchopski Reason: 1
I've got a 2x16 LCD + keypad shield plugged into a Uno and can't get it to respond properly. With the shield plugged into the Uno the top row of digits is off and the bottom row shows up as a row of solid squares.

Right up front I have zero coding experience so all I'm doing is using example sketches but even with those the LCD isn't doing what it's supposed to.

E.g., I created a sketch using:

Code: [Select]
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16,2);
}

void loop() {
  // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:
  for (int thisChar = 0; thisChar < 10; thisChar++) {
   lcd.print(thisChar);
   delay(500);
  }

  // set the cursor to (16,1):
  lcd.setCursor(16,1);
  // set the display to automatically scroll:
  lcd.autoscroll();
  // print from 0 to 9:
  for (int thisChar = 0; thisChar < 10; thisChar++) {
    lcd.print(thisChar);
    delay(500);
  }
  // turn off automatic scrolling
  lcd.noAutoscroll();
 
  // clear screen for the next loop:
  lcd.clear();
}


but the screen remains as it was when first plugged in. Can anyone tell me what I'm doing wrong?

(Sorry for the ugly code paste. What's the right way to do that?)

EDIT: Thanks. That looks better.

Nick Gammon

Edit your post. Get rid of the code you have there. Paste in your code and then select it and hit the "#" button above to put it into code tags.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

PaulS

Quote
I've got a 2x16 LCD + keypad shield plugged into a Uno

Well, we all know what a Uno looks like, and which pins it uses. Your mysterious shield is a different matter.

Quote
With the shield plugged into the Uno the top row of digits is off and the bottom row shows up as a row of solid squares.

Either the backlight is not adjusted properly, or you have something wired wrong.


Nick Gammon

Transposing a couple of wires will do that. I agree with PaulS. Sounds like a wiring issue.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

The shop I bought the Uno and the shield at said they plug together. The pins all line up only one way.

See attached photos. Thats how the screen looks no matter what I do. The only time it changes is when I reset it and then it blinks off then back on.

Nick Gammon

Well, can you give a link to this shield then please?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Techone

Quote
See attached photos. Thats how the screen looks no matter what I do. The only time it changes is when I reset it and then it blinks off then back on.


Thanks for pictures. At least, I can see the situation.

The first picture tell you that the LCD is "working" fine ( +V, gnd, V adg and background LED is fine )

To display something...

Look at two line :

LiquidCrystal(rs, enable, d4, d5, d6, d7);

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

What do you see ?  Those pins match ? No or Yes. If not, well change the pins numbers in the function. The pins HAVE TO MATCH.  I don't know about the setup of your shield, but my DIY LCD shield match my code. Those pins numbers are not writting in stone. But the LCD is hardwire. You have to figure out those pins numbers.

Anyway, here my LCD shield test code. Just change the pins numbers.

If it still no show, well... press the reset button and see what happen...

Code: [Select]

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,10,9,8,7);

void setup()
{
 lcd.begin(16, 2);
 lcd.clear();
 lcd.print("0123456789012345");
 lcd.setCursor(0,1);
 lcd.print("1234567890123456");
}

void loop()
{

 

floresta

Quote
With the shield plugged into the Uno the top row of digits is off and the bottom row shows up as a row of solid squares.

We know three things for sure.
(1) Your LCD is upside down.
(2) The power and backlight are connected properly.
(3) The LCD controller is not being initialized properly.

The causes for #3 are either problems with the Arcuino/LCD connections or with the program code.


Quote
Can anyone tell me what I'm doing wrong?

Most likely your shield uses different pins than those stated in your sketch.  How did you come up with the values used here:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


Don

floresta

#8
Mar 08, 2012, 11:59 pm Last Edit: Mar 09, 2012, 12:03 am by floresta Reason: 1
That looks like this DFRobot shield: http://www.robotshop.com/dfrobot-lcd-keypad-shield-arduino-1.html.

Look at what it says in the description: "Pins 4, 5, 6, 7, 8, 9 and 10 are used to interface with the LCD"

It would be nice if they also told you which pin was which but at least we know that your values are incorrect.  Whatever you do, don't use the LCD4Bit sketch that they recommend, but do take a look at the sketch and you will probably find the answers that you need.  


Edit:  The schematic has the answer.

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


Don

justone

#9
Mar 09, 2012, 12:13 am Last Edit: Mar 09, 2012, 12:16 am by justone Reason: 1
Just took a look and they do have a support page for that sheild where they do mention which pin does what and some software for it.

http://www.robotshop.com/dfrobot-lcd-keypad-shield-arduino-1.html

Click on useful links.


bperrybap

There is no need to run the 4bit mod library.
You can run the LiquidCrystal library included with the Arduino IDE as long as you use
the correct pins in the LiquidCrystal() constructor.


The example lcd sketches included in the IDE will not work "as is" because they use a different pinout.
You will have to modify the pins in the constructor for your shield.
See Don's post for the correct pins.

--- bill

Wow. Thanks for all the advice! I'll check the pins and everything else tomorrow.

I really appreciate the help with this.

Chops

OK using the pin numbers as supplied by Don, it works!

Thanks to everyone for their various tips. It's nice to be gaining some basic understanding about how this all works together.

As far as the keypad, it says analog pin 0 on the Arduino reads that input. How does one pin read the on/off state of six different buttons??? What would the code that reads that input look like?

Also, where did you find the info that pins Arduino (RS, E, D4, D5, D6, D7) interface with LCD pins (8, 9, 4, 5, 6, 7)?

I found this schematic but I can't see that it provides this info anywhere.

Actually there's a sample of code for reading keypad input right on the wiki:

Code: [Select]
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

/*******************************************************

This program will test the LCD panel and the buttons
Mark Bramwell, July 2010

********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0);      // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50)   return btnRIGHT; 
if (adc_key_in < 195)  return btnUP;
if (adc_key_in < 380)  return btnDOWN;
if (adc_key_in < 555)  return btnLEFT;
if (adc_key_in < 790)  return btnSELECT;   
return btnNONE;  // when all others fail, return this...
}

void setup()
{
lcd.begin(16, 2);              // start the library
lcd.setCursor(0,0);
lcd.print("Push the buttons"); // print a simple message
}

void loop()
{
lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
lcd.print(millis()/1000);      // display seconds elapsed since power-up


lcd.setCursor(0,1);            // move to the begining of the second line
lcd_key = read_LCD_buttons();  // read the buttons

switch (lcd_key)               // depending on which button was pushed, we perform an action
{
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
   case btnSELECT:
     {
     lcd.print("SELECT");
     break;
     }
     case btnNONE:
     {
     lcd.print("NONE  ");
     break;
     }
}

}


I've got lots of questions about this but let's start with these comments:
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741 Where do these values come from?
// we add approx 50 to those values and check to see if we are close  Why do we add approx 50 to each value?

Go Up