Go Down

Topic: following the examples in the arduino software ie keypad (Read 605 times) previous topic - next topic

matelot

Hi,
I am trying to learn the various commands and have decided to try the keypad library code.
I have included the keypad.h in the software and it loaded ok.
When I try to run the example program that comes with it, with alterations for my keypad as explained in the comments, I seem to have lost the signal from dig input 1.
Code: [Select]
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
  {'0','4','8'},
  {'1','5','9'},
  {'2','6','*'},
  {'3','7','#'},
};
byte rowPins[rows] = {7, 4, 6, 1};
byte colPins[cols] = {5, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

I fail to read buttons 3 7 and #.
I thought it might be to do with the fact that dig pin 1 is the 'tx' pin. I added instructions to read it on the monitor but that then uses the dig pin 1.
If I change the byte rowPins[rows] = {7, 4, 6, 1,);
to                    byte rowPins[rows] = {7, 4, 6, 8,);
does it not use dig pin 8 instead of 1? It looks to still fail. or what am I missing?
thanks.
Bob.

PaulS

Quote
I seem to have lost the signal from dig input 1.

Only if you are using Serial, which seems to be necessary in order to know that the program is not working.

On the other hand, http://snippets-r-us.com might be able to help you if you can't be bothered to post all of your code.

matelot

#2
Aug 01, 2013, 01:37 pm Last Edit: Aug 01, 2013, 01:39 pm by matelot Reason: 1
I didn't think it would help to post all the code but I have put it here if someone could help me.
Code: [Select]
#include <Keypad.h>

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

const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
 {'0','4','8'},
 {'1','5','9'},
 {'2','6','*'},
 {'3','7','#'},
};
byte rowPins[rows] = {7, 4, 6, 2};
byte colPins[cols] = {5, 3, 1};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

int redPin = 11;
int greenPin = 10;

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

 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 ++;
 }
 
//added recently to try to find what the problem is without having the monitor scrolling
 if (key == '1')
 {
   Serial.print(key);
 }
 if (key == '2')
 {
   Serial.print(key);
 }
 if (key == '3')
 {
   Serial.print(key);
 }
 if (key == '4')
 {
   Serial.print(key);
 }
 if (key == '5')
 {
   Serial.print(key);
 }
 if (key == '6')
 {
   Serial.print(key);
 }
 if (key == '7')
 {
   Serial.print(key);
 }
 if (key == '8')
 {
   Serial.print(key);
 }
 if (key == '9')
 {
   Serial.print(key);
 }
 if (key == '0')
 {
   Serial.print(key);
 }
 if (key == '#')
 {
   Serial.print(key);
 }
 if (key == '*')
 {
   Serial.print(key);
 }
 
 

 if (position == 4)
 {
   setLocked(false);
 }
 delay(100);
}

void setLocked(int locked)
{
 if (locked)
 {
   digitalWrite(redPin, HIGH);
   digitalWrite(greenPin, LOW);  
 }
 else
 {
   digitalWrite(redPin, LOW);
   digitalWrite(greenPin, HIGH);      
 }
}


you may notice I have swapped pins 1 and 2 and the wires on the board. The problem is now with buttons 8,9,# and *. ie the problem is still on pin 1.
The snippets-r-us link says the website can't be found? but I have been trying all sorts of things without success.
Thanks.

AWOL

Quote
the problem is still on pin 1.

Code: [Select]
Serial.begin(9600);
Take a close look at the label by pin 1 on your board.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

matelot

at the side of pin 1 is 'TX'.
Either I don't understand what you are asking me to do or you don't understand what I am asking?
I am asking why it is the example for keypad uses pin 1 and if there is any way of using another pin.
I started with the program that comes with the keypad library and altered the inputs to fit my keypad. I also altered the leds so that if I entered the correct code the led on pin 13 would go out. It didn't. (at this point there was no Serial.begin(9600).
The code is below
Code: [Select]

#include <Keypad.h>

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

const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
  {'0','4','8'},
  {'1','5','9'},
  {'2','6','*'},
  {'3','7','#'},
};
byte rowPins[rows] = {7, 4, 6, 1};
byte colPins[cols] = {5, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

int redPin = 13;
int greenPin = 10;

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

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

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

void setLocked(int locked)
{
  if (locked)
  {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW); 
  }
  else
  {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);     
  }
}

I assume and I have indicated so above, that I can't use the monitor as it uses pin 1.
So, is there any way I can run the keypad library and use a pin other than pin 1. If I try to use pin 8, ie change the line
byte rowPins[rows] = {7, 4, 6, 1};
to
byte rowPins[rows] = {7, 4, 6, 8};
It looks as if it is still using pin 1. As I have said above.
If you are telling me to look at the side of pin1 and see it says tx ie I can't use it as an input then I am asking for help because I am aware of this and don't know how to get around it.
Bob.

jack wp

When you changed the code from pin 1 to pin 8, did you also move the wire from pin one to pin eight?
Good luck, Jack

matelot

#6
Aug 02, 2013, 12:51 am Last Edit: Aug 02, 2013, 01:10 am by matelot Reason: 1
yes


This is the code from the examples in the keypad library, this uses pin 1 as an input and has Serial.begin(9600)?
Code: [Select]
/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

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


 
void loop(){
  char customKey = customKeypad.getKey();
 
  if (customKey){
    Serial.println(customKey);
  }
}




jack wp

If you are using the serial.print to the computer, I think it used D0 and D1.  You will probably want to change both D0 and D1 from the keypad code.

Are you stuck on that keypad? If not, what are your needs for a keypad? all 10 numbers? or less?
I like this LCD Keypad Shield for many apps. http://dx.com/p/lcd-keypad-shield-for-arduino-duemilanove-lcd-1602-118059

Good luck, Jack

matelot

#8
Aug 02, 2013, 01:12 am Last Edit: Aug 02, 2013, 01:14 am by matelot Reason: 1
I can put the keypad outputs to any arduino input but does the keypad library recognise just any inputs?

how do I get at the keypad code to change it?

jack wp

I think such as:
Code: [Select]
change the line
byte rowPins[rows] = {7, 4, 6, 1};
chnaged to
byte rowPins[rows] = {7, 4, 6, 8};
Good luck, Jack

matelot

if I do that and put the wire from 1 to 8 nothing happens at all, if I put the wire back to 1 with the program still on 8 I get the same fault as if I had not altered the program. I have swapped it back and forth quite a few times without any change in those symptoms.
I am sure I am altering the program.

jack wp

If you are using the serial.print to the computer, I think it used D0 and D1.  You will probably want to change both D0 and D1 from the keypad code.
Good luck, Jack

Go Up