Loading...
Pages: [1]   Go Down
Author Topic: How to use this keypad?  (Read 523 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, i bought this http://dx.com/p/5-io-keyboard-matrix-buttons-module-blue-150608
can someone tell me how to interface this keypad with arduino mega?
Logged

Cape Town South Africa
Online Online
Edison Member
*
Karma: 17
Posts: 1123
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

is there a datasheet with it?

It says only 5 I/O lines so should be easy
Logged

We live in the era of the smart phones and stupid people.

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 141
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a very interesting piece of kit.  A PDF of the schematic is here http://www.wvshare.com/downloads/accBoard/5-IO-Keypad.7z.

Because this board contains keys and a joystick you'll need to be just a bit more careful with your programming logic.  But in general what you need to do is...

1.  Wire up the board. Leave board pin 1 unconnected (it doesn't do anything). Connect board pin 2 to arduino GND pin.  Connect board pins IO1 thru IO5 to arduino pins 2 thru 6 them in any order.

2.  In setup() you'll need to enable the internal pullup resistors with pinMode(pinNum, INPUT_PULLUP).

3.  Create a readAllPins() function that does a digitalRead() on each of the arduino pins 2 thru 6 one at a time.

4.  Create a scanKeys() function that does a digitalWrite(pinNum, LOW) on each of the arduino pins 2 thru 6 one at a time and in order.  Then for each arduino pin that you digitalWrite(pinNum, LOW) call your readAllPins() function and store the values into a variable.

5.  Inside loop():  Call your read function first and if any pin is low that means the joystick is being used. You can tell which direction by the arduino pin number that reads low.  If all pins are high then call your scanKeys() function to see if any buttons are being pressed.

You can't use the keys and the joystick at the same time and there's no debouncing. All that can be fixed later once you are more familiar with what I wrote above.

Let me know if you need more detail.  I wouldn't mind playing with the code for this.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks  a lot  smiley  . I will try and inform you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again, i think i made very big mistake  smiley-razz
but very confused now.
What is your advice to make this code more to work?

int val = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(30, INPUT_PULLUP);
   pinMode(31, INPUT_PULLUP);
    pinMode(32, INPUT_PULLUP);
     pinMode(33, INPUT_PULLUP);
      pinMode(34, INPUT_PULLUP);

}
void readAllPins()
{
 
  val=digitalRead(30);
    val1=digitalRead(31);
      val2=digitalRead(32);
        val3=digitalRead(33);
          val4=digitalRead(34);
}
void  scanKeys()
{
   digitalWrite(30, LOW);
   readAllPins();
    digitalWrite(31, LOW);
       readAllPins();
     digitalWrite(32, LOW);
        readAllPins();
      digitalWrite(33, LOW);
         readAllPins();
       digitalWrite(34, LOW);
          readAllPins();
}
void loop() {
   readAllPins();
   if(val||val1||val2||val3||val4==LOW){
     
   }
    if(val&&val1&&val2&&val3&&val4==LOW){
     scanKeys();
     Serial.println(String(val)+String(val1)+String(val2)+String(val3)+String(val4));
   }
}
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 141
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi feveran,

  I wonder if you could tell me what it is you want to accomplish?  Do you want to learn how to make this hardware work or are you just interested in using it for your project?  I can help either way but I am asking because I don't want to take over your project.  I can write the code to make the buttons and joystick work but if that is what you are interested in doing then I can teach you how to write the code and understand the hardware.

  What do you think?

-Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In fact i will use this in my project. I will use this keypad for getting command from user. The keypad is my project's user input device but i never use this before. If you give me more detail, i can understand and use this i think smiley
Logged

Pages: [1]   Go Up
Print
 
Jump to: