Pages: 1 [2]   Go Down
Author Topic: how do I interface with a 4x4 keypad/  (Read 6205 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34122
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just need to modify the source code
What source code?
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 322
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27069
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 322
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

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.

* CustomKeypad1.ino (0.88 KB - downloaded 25 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34122
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27069
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

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
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 322
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The link:
is very similar to:
Quote

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.
Logged

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

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);
  }
}
Logged

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

i has change IDE version 1.01 to 1.03 before thats.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)?
Logged

Pages: 1 [2]   Go Up
Jump to: