LCD Shield not behaving

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:

// 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.

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.

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.

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.

Transposing a couple of wires will do that. I agree with PaulS. Sounds like a wiring issue.

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.

Well, can you give a link to this shield then please?

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...

#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()
{

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.

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

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

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.

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:

//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?

First. By looking at the code, the push buttons use the analog pins, not the digital pins.

my buttons when read are centered at these valies: 0, 144, 329, 504, 741

Those values are the analog value. A number between 0 = 0 V to 1023 = 5 V

The way the buttons is connected and the need a read which key is press based on the value being measured by the analog adc.

In my opinion anyway...

vanchopski:
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?

It's a voltage divider. So the total resistance is 2K + 330 + 620 + 1K + 3.3K which is 7250 ohms.

So if the top switch is pressed we get a voltage of 0 since we are grounding the ADC through the 2K resistor.

The next switch down will give (330 / (2000 + 330)) * 1024 = 145.

The next switch will give ((330 + 620) / (2000 + 330 + 620)) * 1024 = 329.

And so on.

I presume we add 50 to give a "fudge factor" so that the voltage doesn't have to be spot on, but within the range of this switch, compared to the next one in sequence.

vanchopski:
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.

Look closely at the schematic.
See the red/brown "D4", "D5", "D6", "D7" going to the 1602 DB4 to DB7?
The "D4" is Arduino digital pin 4, "D5" is Arduino digital pin 5, etc...
Also note D8 going to RS and D9 going to E.

As a bonus look over on the right at the transistor,
Arduino digital pin 10 controls the transistor so you can control the backlight with pin 10.
(Pin 10 supports PWM so you should be able to use analogWrite() and dim the display backlight)

You can also reference their document which has this information in it as well:
http://www.robotshop.com/dfrobot-lcd-keypad-shield-arduino-1.html
See the user guide then page through until you get to the LCD&Keypad shield.

--- bill

The switches on the shield are all connected to +5V and the analog in pin with a resistor in between. The resistors are different sizes, so the voltage that the analog pin sees depends on which switch is pressed.

The analogRead() function reports that voltage as an integer value in the range 0 to 1023 corresponding to 0 to the reference voltage (usually +5V).

So, the code is showing the usual value that would be read at each pin, if the reference voltage is exactly 5.000V and the resistor is exactly the nominal value and the switch is ultraclean (provides no resistance). Since none of these assumptions is true, the value actual reported will only be close to the nominal value shown.

Therefore a fudge factor is added in.

vanchopski:
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.

You've got the first part backwards - Arduino pins (8, 9, 4, 5, 6, 7) interface with LCD pins (RS, E, D4, D5, D6, D7).

Sorry I'm late, Bill already answered the second part, but here it is again. On the schematic look at the IC in the upper right section. If you follow the wire from the RS pin (LCD pin 4) you will see the term 'D8' which stands for Arduino digital pin 8. The other pins have similar information.

Don