go_away

Author Topic: [Solved]12 button keypad to Axon MC  (Read 2422 times)

0 Members and 1 Guest are viewing this topic.

Offline 325ciTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
[Solved]12 button keypad to Axon MC
« on: November 08, 2010, 07:29:01 PM »
I'm trying to implement this keypad in to the Axon MC. I'm having so much trouble with this. Wherever i research it always gives me the assembly language code or cpp code.
I need a .c code to work with this I also don't know which port to hook it up.
Help would be appreciable.

Here is the keypad I have from this website;
Code: [Select]
http://www.robotshop.com/sfe-keypad-12-button.html
« Last Edit: November 15, 2010, 07:22:37 PM by 325ci »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: 12 button keypad to Axon MC
« Reply #1 on: November 09, 2010, 11:04:37 PM »
Ok, here is what you do.

First, study the picture on the first page of this:
http://www.robotshop.com/content/PDF/PIC-HEX-Pad-Tutorial-COM-08653.pdf

Don't bother reading the datasheet, my instructions are easier to follow.

Now, lets say you push the button labeled '1'. What happens? Well, if you follow the lines, COL1 and ROW1 get activated at the same time. Make sense?

Well, your code needs to see which COL and which ROW get activated to figure out which button was pushed.

Now, load up WebbotLib Project Designer for your Axon.
On the left, click Basic, then drag Digital Input into your project. A window comes up . . .
Name the input (COL1, COL2, ROW1, etc), select an input pin, and check the button that says 'Use Internal pullup resistor'.

Now after you have it generate your code (Tools -> Generate...), write some IF statements to have it figure out which button was pushed. The generated code will give you examples of how to see if an input was activated.

Anyway, hope that gave you enough clues to get started!

Offline 325ciTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Re: 12 button keypad to Axon MC
« Reply #2 on: November 10, 2010, 01:05:25 PM »
Any chance I can do that without the webbot?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: 12 button keypad to Axon MC
« Reply #3 on: November 10, 2010, 01:14:05 PM »
Yeap. If you are using the old Axon code, you'd use this: http://societyofrobots.com/axon/axon_function_list.shtml#digital_input

And make sure you configure ports properly, setting the digital inputs to have pull-up resisters:
http://societyofrobots.com/axon/axon_function_list.shtml#port_config

But the old code is very limited and I no longer update it - WebbotLib is much much much better.

Offline 325ciTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Re: 12 button keypad to Axon MC
« Reply #4 on: November 11, 2010, 11:34:07 AM »
Got it ! Thank you. internal resistors cut the noise pretty good.
Thank you for the help.
webbotlib didn't work for some reason, just did it on old school way and works.

Offline 325ciTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Re: [SOLVED]12 button keypad to Axon MC
« Reply #5 on: November 15, 2010, 07:21:56 PM »
Here is a working code for this pad, if someone else deals with it here is the code i did.
I didnt need the 789 so i didnt include them but you can easily understand whats going on.
Code: [Select]
int keypad(void)
{
sbi(DDRE,PE4);
cbi(DDRE,PE4);
sbi(DDRE,PE6);
cbi(DDRE,PE6);
sbi(DDRE,PE2);
cbi(DDRE,PE2);
int k=0;
int tempkey[1];

for(int i=0;i<2;i++)
{
PORT_OFF(PORTE,7);
PORT_OFF(PORTE,5);
PORT_ON(PORTE,3);
delay_ms(50);

if(bit_is_set(PINE,4))
{
key=1;
}
else if(bit_is_set(PINE,2))
{
key=2;
}
else if(bit_is_set(PINE,6))
{
key=3;
}

PORT_OFF(PORTE,3);
PORT_OFF(PORTE,7);
PORT_ON(PORTE,5);
delay_ms(50);
if(bit_is_set(PINE,4)){
   key = 10;
}
else if(bit_is_set(PINE,2)){
key = 0;
}
else if(bit_is_set(PINE,6)){
key = 11;
}

PORT_OFF(PORTE,5);
PORT_OFF(PORTE,3);
PORT_ON(PORTE,7);
delay_ms(50);
if(bit_is_set(PINE,4)){
   key = 4;
}
else if(bit_is_set(PINE,2)){
key = 5;
}
else if(bit_is_set(PINE,6)){
key = 6;
}


tempkey[k]=key;
k++;

}

if(tempkey[0]==tempkey[1])
key=tempkey[1];
else
key=15;

return(key);
}


Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: [Solved]12 button keypad to Axon MC
« Reply #6 on: November 15, 2010, 09:36:02 PM »
Looks good :)

FYI - I did something similar to this on another micro controller (Basic Atom Pro) in Basic for the DIY Remote control up on Lynxmotion. 

Like the pic tutorial, we hooked up pull-up resistors to the 4 rows.  With this setup there was some concern that if multiple buttons were pressed, that we could cause some connections between IO pins that were pulled high and others that re pulled low, which probably would not cause problems, but we decided to not take a chance as it was easy to change the code to avoid it.

What I did was convert the code that instead of setting a column high I would simply set the IO line to input and let it float, which if connected would be a 1 from the pull-up resistor.  Hope that makes sense.

Again great stuff
Kurt

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #7 on: April 12, 2011, 12:52:14 PM »
This is perfect. I've been wanting to attempt the 16-button version, but was a little unsure how to go about doing a couple of things. I think this thread contains exactly what I needed to know. Hooray and stuff. I'll let you know how it goes.

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #8 on: April 12, 2011, 10:40:10 PM »
Quote
Now, lets say you push the button labeled '1'. What happens? Well, if you follow the lines, COL1 and ROW1 get activated at the same time. Make sense?
Yes.

Quote
Now, load up WebbotLib Project Designer for your Axon. On the left, click Basic, then drag Digital Input into your project. A window comes up. Name the input (COL1, COL2, ROW1, etc), select an input pin, and check the button that says 'Use Internal pullup resistor'.
Done.

However, I have come across conflicting information that I would like clarification on. When plugging the keypad into the Axon II which row do I plug the pins into? The Project Designer blinks the ground and signal rows, while some other places indicate I should plug into the voltage row. I'm confused. Please help. Thanks!

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #9 on: April 13, 2011, 12:28:01 PM »
Great! Now I am getting conflicting information with regards to code as well. Can somebody please at least tell me if this concept is correct?
Code: [Select]
set all column pins to high

for each row pin
{
set row pin to high

     for each column pin
     {
     if column pin is low, button was pressed. do something
     }

set row pin to low
}

Do I at least have *this* part right?  ???

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: [Solved]12 button keypad to Axon MC
« Reply #10 on: April 13, 2011, 12:38:47 PM »
Doesn't look right to me.
Reading the docs then the column pins should be set as inputs (with pullup resistors). The row pins should all be output pins and default to high.
Then:
Make all column pins into input with pullups enabled
Make all row pins into outputs and set them high
For each row
   Make this rows output pin low
   For each column
      Read the input pin for this column
      If its low then the button at this row and column has been pressed
   Next Column
   Make this rows output pin high again
Next Row
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #11 on: April 13, 2011, 02:26:50 PM »
Input. Output. Low. High. Up. Down. Forward. Backwards. Horizontal. Vertical. Young Elvis. Old Elvis. What ever happened to the good old days of On and Off? ;D

I'm glad to see that I had at least part of it right. I'll give this another shot when I get home tonight.

Thanks for the input. :D

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #12 on: April 16, 2011, 05:30:45 PM »
There were a couple of more things to it in my case, but I would like to thank Webbot for his help. Everything seems to work like a charm now. I was just terribly confused by what pins started high, low, up, down, and so on.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: [Solved]12 button keypad to Axon MC
« Reply #13 on: April 16, 2011, 07:10:28 PM »
IF you want to send me your code then I can try to build it into WebbotLib so others can benefit - you will of course get a credit in the source code comments.
Note that I tend to have to re-engineer most submitted code a bit since WebbotLib would allow you to add 'many' such devices. Since I don't have the keypad then I may need to ask you to run/test my code.
If you are interested then send me a personal message - if not then I understand.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #14 on: April 16, 2011, 10:43:09 PM »
I'm more than happy to help. I have sent a PM with code and some other stuff. Have at it and let's see what happens. Hopefully, it'll be something good.

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: [Solved]12 button keypad to Axon MC
« Reply #15 on: April 17, 2011, 08:17:57 AM »
As I mentioned earlier, did the same thing for DIY remote control now with XBEE on a different processor.  When I first coded it up, I was concerned with the logic described that if the user pressed multiple buttons, it could direct two IO lines to each other where one is high and the other is low.  Was concerned that the dead-short might be detrimental to the processor and changed the logic...  With the Pull-up resistors installed instead of pulling the IO pins high, I instead let the pull-ups do this and turned those IO pins into inputs instead.  So the logic became:

Reading the docs then the column pins should be set as inputs (with pull up resistors). The row pins should all be output pins and default to high.
Then:
Make all column pins into input with pull ups enabled
Make all row pins into inputs
For each row
   Make this rows an output and set it low
   For each column
      Read the input pin for this column
      If its low then the button at this row and column has been pressed
   Next Column
   Make this rows pin input again
Next Row

As I mentioned it may not be a major problem, but I was being caustious...

Kurt

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #16 on: April 17, 2011, 11:17:40 AM »
I really don't think it would be a major problem; but if you want to be cautious, that's okay. With that said, I went ahead and added code that breaks out of all loops if a button is pushed (i.e.: once a pressed button is discovered, don't scan any further).

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #17 on: April 27, 2011, 01:02:50 PM »
I *FINALLY* got the keypads and some other stuff that I had ordered...six days after they were supposed to arrive. Regardless, I have soldered on some pins and have wired the thing up. Of course, I am at work right now and cannot tell you whether this part of the project was a success or failure. I guess I'll just have to keep you waiting...which reminds me:

I wonder how Admin's new project is going?  ;D

Offline tzankoff

  • Full Member
  • ***
  • Posts: 118
  • Helpful? 0
Re: [Solved]12 button keypad to Axon MC
« Reply #18 on: April 27, 2011, 05:19:28 PM »
Hi. This is Tony's computer.

Tony is too busy pushing buttons on his keypad and expressing excitement as a result to post right now due to the fact that he finally got his 16-button keypads in the mail AND it got them soldiered corrected on the first try (something he is not the greatest at) AND got it wired up correctly AND the fact the thing actually works.

He'll be back in a few days...maybe.  ;D

 


Get Your Ad Here