LCD and Keypad help

Hello,
I have been trying to figure out how to use an LCD and a keypad together so that the LCD displays “Enter Password” on the top row and the numbers entered with the keypad on the bottom row. I can’t figure out how to make it so that the numbers move to the next column after a key is pressed. What I mean by that is, I got it to display the numbers being entered but if I pressed a number (1), then another number(2), the 2 goes over the 1. I tried to take this code

#include <LiquidCrystal.h>

#include <Keypad.h>

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


const byte rows = 4;
const byte cols = 4;
const char keys [rows][cols] =
{
  {'1','2','3','F'},
  {'4','5','6','E'},
  {'7','8','9','D'},
  {'A','0','B','C'}
};

byte rowPins[rows] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {2,3,4,5}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.noAutoscroll();
  lcd.print("IOBLOCKS 2012");
  lcd.setCursor(0,1);
  lcd.print("Enter>");
  delay(2000);
  keypad.setDebounceTime(20);
}

void initLCDKeys()
{
  for (int i = 0; i < sizeof(rowPins); i++)
    pinMode(rowPins[i],OUTPUT);
  for (int i = 0; i < sizeof(colPins); i++)
  {
    pinMode(colPins[i],INPUT);
    digitalWrite(colPins[i],LOW);
  }
}

void loop(){

  char key = keypad.getKey();
  initLCDKeys();
  delay(50);
  if (key != NO_KEY){
    Serial.println(key);
    if (key == 'F')
    {
      lcd.setCursor(6,1);
      lcd.write("          ");
      lcd.setCursor(6,1);
    } else
      lcd.print(key);
  }

  
}

and make the keypad 3 columns by 4 rows, but now only 1,7,4 and # will show up on the display. Here is my modified version of the code

#include <LiquidCrystal.h>

#include <Keypad.h>

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


const byte rows = 4;
const byte cols = 4;
const char keys [rows][cols] =
{
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};

byte rowPins[rows] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {10,1,0,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.noAutoscroll();
  lcd.print("IOBLOCKS 2012");
  lcd.setCursor(0,1);
  lcd.print("Enter>");
  delay(2000);
  keypad.setDebounceTime(20);
}

void initLCDKeys()
{
  for (int i = 0; i < sizeof(rowPins); i++)
    pinMode(rowPins[i],OUTPUT);
  for (int i = 0; i < sizeof(colPins); i++)
  {
    pinMode(colPins[i],INPUT);
    digitalWrite(colPins[i],LOW);
  }
}

void loop(){

  char key = keypad.getKey();
  initLCDKeys();
  delay(50);
  if (key != NO_KEY){
    Serial.println(key);
    if (key == 'F')
    {
      lcd.setCursor(6,1);
      lcd.write("          ");
      lcd.setCursor(6,1);
    } else
      lcd.print(key);
  }

  
}

Could I get some help?

void loop(){

  char key = keypad.getKey();
  initLCDKeys();
  delay(50);

Why are you calling initLCDKeys() on every pass through loop()?

Why are you calling delay() here? Or anywhere, for that matter.

byte colPins[cols] = {10,1,0,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup(){
  Serial.begin(9600);

Connecting the keypad to the serial port pins and using serial at the same time is a non-starter.

I did not write, the code, I just edited it very slightly to make it have one less column. This was the only LCD and keypad sketch I could find so I just tried using it.

I just edited it very slightly to make it have one less column.

No, you didn't. That would have simply involved removing the last pin number. You changed pin numbers for the last two columns, too, to use pins that are already in use.

How are the pins already in use? Also, how could I get this code to work or get/make a different code to get it to work?

Your declaring Serial.begin(), SO, pins 0 and 1 are already in use. Therefore they can not be used for your keypad.

Oh, okay. All of the other pins are being used, so how can i make room for the pins that are currently on 1 and 0. Could I use analog pins?

Could I use analog pins?

Give it a try.

I changed pins 0 and 1 to A5 and A4 and now the LCD is showing all of the numbers, thanks you. Now all I need to do is have a certain combination of numbers, a "password", that when they are pressed in the right order, something happens, such as an LED turning on.

Do a search for "lcd keypad password" you'll find some good stuff.

I searched for that and I only found 1 example sketch and instructions. I tried using his sketch but the LCD was not displaying anything. I think that happened because he was using one more pin from his LCD to the arduino, I changed the pins to the pins I was already using with the LCD and Keypad, the back light is working in the LCD but no display.

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3',},
  {'4','5','6',},
  {'7','8','9',},
  {'*','0','*',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10,A4,A5}; //connect to the column pinouts of the keypad
const int buttonPin = A3;
int buttonState = 0;

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup(){
   pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
digitalWrite(ledPin, LOW); // sets the LED on
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}

void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.print("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
delay(600);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}


else{
digitalWrite(ledPin,LOW);
lcd.print("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
delay(600);
lcd.clear();
}
}

I like refering back to this code, because I know it works. http://arduino.cc/forum/index.php/topic,137352.30.html

And http://arduino.cc/forum/index.php/topic,140459.0.html

I can't tell how to use that code you linked to to make what I am looking to do. Do you see any problems with the most recent code I posted because that is the closest to succes I have gotten and I dont' see anything wrong with it.

There should be nothing wrong with it, but there are other methods. Do you have that password library?

Yes, I do have the password library.
It might be easier to just add a LCD aspect to this code

#include <Keypad.h>

char* secretCode = "235711";
int position = 0;

const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[rows] = {4, 5, 6, 7};
byte colPins[cols] = {1, 2, 3};

Keypad keypad = Keypad(makeKeymap(keys), 
                       rowPins, colPins,
                       rows, cols);

int redPin = 8;
int greenPin = 9;

void setup()
{

  
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  setLocked(true);
}

void loop()
{
  char key = keypad.getKey();
 
  
  if (key == '*' || key == '#') {
    position = 0;
    setLocked(true);
  }
  
  if (key == secretCode[position]) {
    position++;
  }
  
  if (position == 6) {
    setLocked(false);
  }
  delay(50);
}

void setLocked(int locked)
{
  if (locked) {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
  }
  else {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    //add servo turn 90 degrees.
  }
}

ANy ideas how?

It's actually quite simple, but how do you want it to display? I would imagine you want to see each character as you input them and if it matches, display your response.

To see the chars, set the cursor to zero and with each input increment the array as well as the cursor position.

The way I want it is to have it say "Enter Password" on the top, then display the digits being entered on the bottom row, the digits will go one after the next, not replacing the previous one. I don't know how to do what you are telling me to do, sorry, i'm a newbie.

Your answer is here. http://arduino.cc/forum/index.php/topic,137352.30.html

That does not have the password aspect, in which when the right numbers are pressed in order, a LED turns on, or something like that. Also that code will only display a max of 6 or so numbers and then change to some random negative number and cant be changed.

It does not have the password aspect, no, but it does show you how to store and display your data on the LCD. The password is simple, the data being stored into an array and compared to another array with the set password. If the two arrays match, password accepted, else password is invalid.

There are numerous posts about keypads, LCD and passwords, you just have to know how to word your search. The more specific, the better the results will be.