Go Down

Topic: how do I interface with a 4x4 keypad/ (Read 7293 times) previous topic - next topic

Grumpy_Mike

Quote
I just need to modify the source code

What source code?

RandallR

Has anyone used a resistor network as a voltage divider and then read the key value off one of the analog input pins?

I read a write up on something like this but it used resistors of odd values.  ( Odd means I didn't have any )

The one I say was set up like a straight ladder and the input came off the mid-point.  I thought that there might be a way to use 8-10 1K resistors in a network to accomplish the same thing.

CrossRoads

Here is what you might have been thinking of.
http://tronixstuff.wordpress.com/2012/02/29/tutorial-analog-input-for-multiple-buttons-part-two/
Expand the network for the number of buttons you want to use.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

RandallR


Here is what you might have been thinking of.
http://tronixstuff.wordpress.com/2012/02/29/tutorial-analog-input-for-multiple-buttons-part-two/
Expand the network for the number of buttons you want to use.


I was actually looking at something like:
http://www.avr-asm-tutorial.net/avr_en/keypad/keyboard.html#adc

This one is for a 3X4 matrix and the math is a pain for selecting the resistor values.  I was hoping some smarter folks than me figured out a way to use only 1 or 2 different values.

alex_001

Hi,
I had already tried to interface with 4x4 keypad with arduino and it works... Currently I am thinking of modifying the source code so that
it can function as a calculator(Simple Calculator with just addition function). But I am not sure how to start with the advises given earlier.
Is it modifying in the void loop function?
Please Advise.

Grumpy_Mike

The whole thing is none trivial.

Start off by putting your key reading code into a function that returns a number.

This is a bit more difficult than you might think. It has to look at keys pressed and accumulate a number building it up from each key press. So the first number is the key, the second press you take the previous number, multiply it by 10 and add the next key pres to it. You continue to do this until you detect a none number key. You then return from the function with the number.

Then your top level loop consists of calling this function twice, and storing the number in a different variable each time. Finally add the numbers up and print out the result.

jc7molina

hi I am new in arduino too, and i want to display numbers 0 to 9, in a 7-segment display using keypads (4x4) and arduino, please let me know if somebody can help me thank you.

CrossRoads

Sure, start here:
http://playground.arduino.cc/Code/Keypad
Once you can read the keys and display them correctly via the serial monitor, come back with more details of how you wish to connect to the 7-segment display, how many digits, etc.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Goranr

One Analog Input to Arduino from a keypad.
I use it, and it works fine (but it's only 3x4 matrix keypad).
http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/

BR
GoranR

RandallR

The link:

http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/

is very similar to:
Quote

http://www.avr-asm-tutorial.net/avr_en/keypad/keyboard.html#adc


The second link also contains a spreadsheet for calculating resistor values.  I modified the spreadsheet to calculate values for a 4x4 matrix.

The problem I have with this solution is that for the 3x4 matrix it uses 7 resistors of 6 different values.  I would like to find a solution that uses 10 or 12 resistor of all the same value.  Or maybe 5 or 6 resistors of one value and 5 or 6 of another value.

The reason I am thinking this might be a better solution is that while the component count is higher, the cost of resistors goes down with volume.    Rather than buy 6 packages of 5 to 10 resistors each, it would be cheaper to by 1 package of 100 resistors. 
Also, the tolerances are important.  If I buy a 100 resistors they they were probably made at around the same time with the same material and if there is an error they are probably all off by about the same amount in the same direction.  So if they are all low by 5% then the errors will probably cancel in a design that uses all the same value.  Rather than 6-8 different values with some high and some low.  Since I don't have a design, this is all assumption.

There may also be an inexpensive SIP or DIP package out there that contains the appropriate resistor network.  I just haven't come across it.

masavee

hello im newbie but i can use thats code good, i test and working ok.



/*Program demonstrating 4x4 Numeric Keypad interfacing with Arduino UNO
Program Written by: Amit Biswal (Speaking Technology)
URL               : http://amitbiswal.blogspot.com       
*/
int r1=A5;
int r2=A4;
int r3=A3;
int r4=A2;

int c1=A1;
int c2=A0;
int c3=10;
int c4=11;

void setup()
{
  Serial.begin(9600);
 
  pinMode(r1,OUTPUT);
  pinMode(r2,OUTPUT);
  pinMode(r3,OUTPUT);
  pinMode(r4,OUTPUT);

  pinMode(c1,INPUT);
  pinMode(c2,INPUT);
  pinMode(c3,INPUT);
  pinMode(c4,INPUT);
 
}
void loop()
{
  int val;
  //setting the columns as high initially
  digitalWrite(c1,HIGH);
  digitalWrite(c2,HIGH);
  digitalWrite(c3,HIGH);
  digitalWrite(c4,HIGH);
 
  //checking everything one by one
  //case 1: col1 =0 while other col as 1
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  //checking each column for row1 one by one
  if(digitalRead(c1)==0)
  {
    Serial.println("key 1 pressed");
  }
  else if(digitalRead(c2)==0)
  {
    Serial.println("Key 2 pressed");
  }
  else if(digitalRead(c3)==0)
  {
    Serial.println("Key 3 pressed");
  }
  else if(digitalRead(c4)==0)
  {
    Serial.println("Key A pressed");
  }
 
  //case 2: col2 =0 while other col as 1
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  //checking each column for row1 one by one
  if(digitalRead(c1)==0)
  {
    Serial.println("key 4 pressed");
  }
  else if(digitalRead(c2)==0)
  {
    Serial.println("Key 5 pressed");
  }
  else if(digitalRead(c3)==0)
  {
    Serial.println("Key 6 pressed");
  }
  else if(digitalRead(c4)==0)
  {
    Serial.println("Key B pressed");
  }
 
  //case 3: col3 =0 while other col as 1
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,LOW);
  digitalWrite(r4,HIGH);
  //checking each column for row1 one by one
  if(digitalRead(c1)==0)
  {
    Serial.println("key 7 pressed");
  }
  else if(digitalRead(c2)==0)
  {
    Serial.println("Key 8 pressed");
  }
  else if(digitalRead(c3)==0)
  {
    Serial.println("Key 9 pressed");
  }
  else if(digitalRead(c4)==0)
  {
    Serial.println("Key C pressed");
  }
 
  //case 1: col1 =0 while other col as 1
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,LOW);
  //checking each column for row1 one by one
  if(digitalRead(c1)==0)
  {
    Serial.println("key F pressed");
  }
  else if(digitalRead(c2)==0)
  {
    Serial.println("Key 0 pressed");
  }
  else if(digitalRead(c3)==0)
  {
    Serial.println("Key E pressed");
  }
  else if(digitalRead(c4)==0)
  {
    Serial.println("Key D pressed");
  }
  //giving delay between keypress
  delay(200);
 
}

but i have proplem, why next code no working,i load arduino examples at net and test better code but compiler stop alltime const byte row (and many many other error have too.why no working because must be have arduino examples code :O ????


this is examples code-->

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

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

void setup(){
  Serial.begin(9600);
}
 
void loop(){
  char key = keypad.getKey();
 
  if (key){
    Serial.println(key);
  }
}

masavee

i has change IDE version 1.01 to 1.03 before thats.

Derkatwork

Rather than make a new thread, I decided to reuse this one since my question falls along these lines.  I am am going to run a RGB LCD (16x2) at the same time as the keypad.  I have an understanding of PWM (http://arduino.cc/forum/index.php?topic=4496.0), and am always triple checking here or google to ensure no complications come up.  I have an ATMEGA 1280 with 54 digital pins (and the lower numbers have PWM).  Will any pins in the digital range (PWM or not) be able to control the LCD or keypad (standard 4x4 from amazon that is compatible)?

Go Up