Go Down

Topic: Which Libraries are needed for LCD KeyPadShield? (Read 3 times) previous topic - next topic

floresta

#5
Dec 10, 2012, 04:59 pm Last Edit: Dec 10, 2012, 05:06 pm by floresta Reason: 1
Quote
The problem was much the same and I got a result with the line

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);


Do you understand how this change (from the end of reply # 1) affects the operation of the library and how it does or does not affect your particular shield?  

I know the answer to the first part but not the second.

Post a link to the datasheet or schematic diagram for your shield and I can help you answer the question.


Don


floresta

In my haste to try and help the helper I forgot the original question.

"Which Libraries are needed for LCD KeyPadShield?"

It looks like you should use the LiquidCrystal library to deal with the display and use the library provided in the 'Download Link' at the SainSmart website for the keypad.  

Disregard any references to a 4bit Arduino LCD library, that library is ancient history.

I know that this information about the keypad conflicts with that offered in reply #1 (
"No extra libraries are needed for the buttons") so use your common sense to decide who to believe.

Don

NickPyner

#7
Dec 10, 2012, 05:44 pm Last Edit: Dec 10, 2012, 05:51 pm by NickPyner Reason: 1


You should modify your example code to have:

LiquidCrystal lcd(8,9,4,5,6,7);

I see NickPyner already told you the same but somehow he forgot to mention this particular pin arrangement is derived directly from the seller-provided document found at that link I provided above. Might be an overlook.

@NickPyner, I suggest you base your comment on more solid reasoning.


There is no somehow about it, and it wasn't an overlook. I don't have a sainsmart shield, just one that looks the same, as I made very clear, and it came with no documentation.

As I also surely made very clear, I determined the pin assignment by reading the back of the circuit board, hence the comprehensive list in my reply #1, and the two configuration lines compared. I would have thought that was reasoning solid enough on which to base my comment.  You may find that reasoning not solid enough, but I'm not sure I want hear about that.

I might also point that the comment on the buttons was as casual as was surely implied. With that configuration, the button sketch worked for me, it might for the OP, and it costs nothing if it doesn't. I didn't write it, I'm not interested in buttons. But I will correct what I said to "No extra libraries were required for the buttons.........  

Code: [Select]
/*
  The circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD BL pin to digital pin 10
* KEY pin to analog pin 0        (14)  THIS IS THE BUTTON PIN
*/

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

char msgs[5][16] = {"Right Key OK ",
                    "Up Key OK    ",               
                    "Down Key OK  ",
                    "Left Key OK  ",
                    "Select Key OK" };

int adc_key_val[5] ={50, 200, 400, 600, 800 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;

void setup()
{
    Serial.begin(9600);
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("ADC key testing");
}

void loop()
{ //1


  if (key != oldkey)   // if keypress is detected "!=" means not equal!!
   {//2
    delay(50);  // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor
    key = get_key(adc_key_in);    // convert into key press
    if (key != oldkey)   
    {//3   
      lcd.setCursor(0, 1);
      oldkey = key;
      if (key >=0){//4
           lcd.print(msgs[key]);
      Serial.println(key);
     
      if (key == 2)
{
  Serial.println("            down  ");
}
     
     
lcd.setCursor(15,1); 
lcd.print(key);

      }//4
    }//3

   }//2
  /*
if (key = 800)
{
   delay(2000);
   lcd.clear();
  }
*/
delay(100);

}//1

// Convert ADC value to key number
int get_key(unsigned int input)
{
    int k;
   
    for (k = 0; k < NUM_KEYS; k++)
    {
      if (input < adc_key_val[k])
{
            return k;
        }
   }
   
    if (k >= NUM_KEYS)k = -1;  // No valid key pressed
    return k;
}

floresta

Quote
I might also point that the comment on the buttons was as (sic) casual as was surely implied.


With my background I tend to concentrate my responses based on what is stated, not what is implied. 

Now that you have posted some relevant code your statement that "No extra libraries are needed for the buttons" is correct.  You haven't mentioned where it came from but the code that you posted uses the LiquidCrystal library to deal with the display but it also contains the code required to read the keypad.  So your statement is correct for your implementation.

Is the OP using the same code as you?  I don't know and you probably don't either. 

I know that you are trying to be helpful but you should think about how your posts are being interpreted by others. In some instances you have passed along information that worked for you, which is fine, but in my opinion you should not say or imply that that is the correct or the best solution.

Have you given any thought to the question about pin 13?

Don

bperrybap

torstenv,
In terms of your core original question, as to which library can be used to drive the LCD.
The LiquidCrystal library that comes with the IDE since about IDE 0016 or so will work.
The issue you will have is that all the examples that come with the LiquidCrystal library use
a different pin wiring to the LCD than the shield you have. That is why you can't simply
use any of the examples. They do work, they just won't work "as is" with your LCD-keypad shield
since the internal wiring on the PCB of the shield hooks up different Arduino pins to the LCD than
what the examples are configuring the LiquidCrystal library to use.
You can either go directly modify the LCD constructor in the LiquidCrystal library examples directory
to use the pins for your shield pins or make copies of them and modify the copies.


The "libraries" directory referred to is underneath where ever you installed the Arduino s/w.
i.e. in this case the examples are located:
{installdir}/libraries/LiquidCrystal/examples

The IDE wants to see the directory name and sketch name in the examples directory match.
So if you make copies under an existing directory, you need to make sure the directory and sketch match.
You also must exit and re-start the IDE every time you create a new directory with a sketch.

You can also put them in your private sketch area which also can have a "libraries" area.
Simply copy examples from the LiquidCrystal library area and put them in your private
sketch are and leave the originals alone.
This is a better approach as your private area will continue to show up for future
IDE installs vs just being in the release you happen to modify/update.
To locate your private sketch area location, bring up the IDE and click on
[File]->[Preferences]
It is there in the Sketchbook location box.
What I do to make it simpler and more obvious and to plan for the future,
is to go to that location and create 3 sub-directories:
hardware
libraries
sketches

hardware - is used for alternate cores like attiny, 644/1284 etc... ( you might not ever use this)

libraries - can be used for 3rd party libraries that you may like and collect over time say:
IRremote, temperature, OneWire, RTC, etc...

sketches
- well that is where you create directories for your sketches.

The nice thing about using this structure is that you only have to set it up once
and then it will show up on all future IDEs.
To use the sketches, from your private area in the IDE simply click on
[File]->[Sketchbook]->
Then you can click on "libraries" or "sketch" then drill down to pick the desired
sketch.

Hope that helps.
BTW, take note of the backlight control issue in the thread mentioned
at the bottom of this reply.
Some of newer LCD shields have fixed this issue but many have not so
it is worth a read to understand the potential issue.


--- bill




I don't have a sainsmart shield, just one that looks the same, as I made very clear, and it came with no documentation.

As I also surely made very clear, I determined the pin assignment by reading the back of the circuit board, hence the comprehensive list in my reply #1, and the two configuration lines compared. I would have thought that was reasoning solid enough on which to base my comment.  You may find that reasoning not solid enough, but I'm not sure I want hear about that.


Nick,
So you are saying that your LCD-keypad shield is not the same as the sainsmart LCD-keypad
shield in that the R/W line is wired to Arduino pin 13 (the Arduino LED) on your shield?

It's possible, (I've seen some crazy things out there in Arduino land)
but so far I've not seen an LCD-keypad shield that has done this. All the ones I've seen, including the SainSmart,
YwROBOT, LinkSprite, DFRrobot, Emartee, and many other LCD-keypad shields, hardwire the LCD R/W pin to gnd
so they do not waste and Arduino pin. This is a good design decision
since the Arduino supplied LiquidCrystal library does not use BUSY polling and
sets R/W pin (if specified) to ground anyway.


Many of the LCD-keypad shield designs seem to have copied one another all the way down to a hardware
design issue with respect to controlling the LCD backlight - on the boards that allow backlight control.
See this thread for issues related to that issue:
http://arduino.cc/forum/index.php/topic,96747.0.html

With respect to backlight control. I would encourage anyone using the shields backlight control
capability to be very careful using it (i.e. don't use it) until you know if the shield has
a proper backlight circuit.
Many of the lcd shields out there have a bad circuit and are overloading the pin
being used for backlight control when controlling it using simple digitalWrite() functions
or analogWrite() for dimming.



Go Up