Offline
Newbie
Karma: 0
Posts: 18
|
 |
« on: March 08, 2012, 12:52:09 am » |
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.
|
|
|
|
« Last Edit: March 08, 2012, 09:21:59 am by vanchopski »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #1 on: March 08, 2012, 02:21:38 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35478
Seattle, WA USA
|
 |
« Reply #2 on: March 08, 2012, 10:04:16 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: March 08, 2012, 02:41:21 pm » |
Transposing a couple of wires will do that. I agree with PaulS. Sounds like a wiring issue.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #4 on: March 08, 2012, 05:23:03 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #5 on: March 08, 2012, 05:28:37 pm » |
Well, can you give a link to this shield then please?
|
|
|
|
|
Logged
|
|
|
|
|
Toronto, Canada
Offline
Edison Member
Karma: 2
Posts: 1233
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
|
 |
« Reply #6 on: March 08, 2012, 05:39:40 pm » |
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() {
|
|
|
|
|
Logged
|
|
|
|
|
Western New York, USA
Online
Faraday Member
Karma: 17
Posts: 3464
|
 |
« Reply #7 on: March 08, 2012, 05:51:44 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Western New York, USA
Online
Faraday Member
Karma: 17
Posts: 3464
|
 |
« Reply #8 on: March 08, 2012, 05:59:03 pm » |
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
|
|
|
|
« Last Edit: March 08, 2012, 06:03:55 pm by floresta »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 117
|
 |
« Reply #9 on: March 08, 2012, 06:13:59 pm » |
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.htmlClick on useful links.
|
|
|
|
« Last Edit: March 08, 2012, 06:16:46 pm by justone »
|
Logged
|
|
|
|
|
Dallas, TX USA
Offline
Edison Member
Karma: 25
Posts: 1617
|
 |
« Reply #10 on: March 08, 2012, 08:56:34 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #11 on: March 09, 2012, 12:08:23 am » |
Wow. Thanks for all the advice! I'll check the pins and everything else tomorrow.
I really appreciate the help with this.
Chops
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #12 on: March 12, 2012, 09:38:15 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #13 on: March 12, 2012, 09:49:57 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #14 on: March 12, 2012, 10:00:40 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
|