brettmclean / pad4pi

Interrupt-based matrix keypad library for Raspberry Pi
GNU Lesser General Public License v3.0
51 stars 19 forks source link

Double key presses #2

Closed gijsstat closed 8 years ago

gijsstat commented 8 years ago

Hi, thanks for writing this nice code, it should help me getting the CPU usage of my pi down!

However, I am running in to an issue which I am finding hard to debug: (almost) every time I press a key it is registered as a double press. Is there anything I can do about that?

Thanks!

brettmclean commented 8 years ago

Hi gijsstat. Thanks for opening an issue.

I'd like to get some information about your setup.

  1. What kind of matrix keypad are you using? If you bought it online you can link to the product page.
  2. What model is your Raspberry Pi?
    • Raspberry Pi 1 Model A
    • Raspberry Pi 1 Model A+
    • Raspberry Pi 1 Model B
    • Raspberry Pi 1 Model B+
    • Raspberry Pi 2 Model B
gijsstat commented 8 years ago

Thanks for your help in advance!

This is my keypad:

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemVersion&item=181307220641&view=all&tid=1403724059008

I am using the Raspberry Pi 1 Model B+.

And some more info: It was working OK with this script https://github.com/tkmaker/RaspberryPiHomeAlarm/blob/master/keypad.py but I prefer your method due to the vastly lower CPU usage. I have tried to increase the bouncetime in your script, but this only results in a period if inactivity after the two presses are registered.

Thanks!

brettmclean commented 8 years ago

I tried that eBay link and it asked me to log in. When I did, it told me that information for that item was no longer available.

Would you be able to find the same keypad you're using and send me a different link? You can probably just find it within current eBay listings and send me a link to one of those.

gijsstat commented 8 years ago

It is a simple 4x4 one, like this:

http://www.ebay.com/itm/4-x-4-Matrix-Array-16-Key-Membrane-Switch-Keypad-Keyboard-for-Arduino-AVR-PI-C-/310511616357?hash=item484bef4165

On 30 September 2015 at 16:38, Brett McLean notifications@github.com wrote:

I tried that eBay link and it asked me to log in. When I did, it told me that information for that item was no longer available.

Would you be able to find the same keypad you're using and send me a different link? You can probably just find it within current eBay listings and send me a link to one of those.

— Reply to this email directly or view it on GitHub https://github.com/brettmclean/pad4pi/issues/2#issuecomment-144432070.

brettmclean commented 8 years ago

Hmm. That looks pretty much the same as what I have, except mine is a 3x4 keypad.

I'm happy to hear that you played with the bouncetime to rule out a bouncing signal.

Does the "double key press" problem happen with every key or just some of them?

Could you provide me with a code sample which uses pad4pi and reproduces this problem?

gijsstat commented 8 years ago

It is with all the keys. I have used the demo code and just changed the GPIO's to my setup. Would you like the exact code? I can't access it right now but tonight should be OK.

Gijs

On 1 October 2015 at 03:56, Brett McLean notifications@github.com wrote:

Hmm. That looks pretty much the same as what I have, except mine is a 3x4 keypad.

I'm happy to hear that you played with the bouncetime to rule out a bouncing signal.

Does the "double key press" problem happen with every key or just some of them?

Could you provide me with a code sample which uses pad4pi and reproduces this problem?

— Reply to this email directly or view it on GitHub https://github.com/brettmclean/pad4pi/issues/2#issuecomment-144593438.

brettmclean commented 8 years ago

It's a bit of a long shot, but I would like to see the exact code you're using just so I can rule it out. Thanks!

gijsstat commented 8 years ago

This is the code I am using. See below what happens when I press all the keys once. I repeated the 3,6, A and B and for some reason these do not seem to be affected...

Does it help?

Gijs

!/usr/bin/python

from pad4pi import rpi_gpio import time KEYPAD = [ [1,2,3,"A"], [4,5,6,"B"], [7,8,9,"C"], ["*",0,"#","D"] ]

ROW = [21,20,16,12] COLUMN = [26,19,13,6]

def print_key(key): print(key) try: factory = rpi_gpio.KeypadFactory() keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW, col_pins=COLUMN)

    keypad.registerKeyPressHandler(print_key)

    print("Press buttons on your keypad. Ctrl+C to exit.")
    while True:
            time.sleep(1)

except KeyboardInterrupt: print("Goodbye") finally: keypad.cleanup()

Press buttons on your keypad. Ctrl+C to exit. 1 1 2 2 3 4 4 5 5 6 7 7 8 8 9 9 0 0 # # D D C C B A

And this Press buttons on your keypad. Ctrl+C to exit. 1 1 3 6 A

brettmclean commented 8 years ago

Hi Gijs,

I tried pad4pi with my 3x4 keypad using the same pins you're using and I'm not experiencing double key presses on any buttons. I wanted to make sure there wasn't something inherently different about those pins.

It sounds like the 3, 6, A and B keys all work consistently for you (no double key presses). This must mean that the 1st & 2nd rows and 3rd & 4th columns are working correctly on your keypad. Given that the other buttons are giving you trouble, that suggests to me that there's something wrong with the 3rd & 4th rows and 1st & 2nd columns.

The problem could be the keypad itself, the pins on your Pi or the wiring from the keypad to the pins. Speaking of which, how are you connecting your matrix keypad to your Raspberry Pi? I'm using male-to-female jumper wires to connect it directly.

Could I ask you to try your keypad again using RaspberryPiHomeAlarm with the current wiring configuration? I want to make sure the keypad definitely works with the current wiring and pins.

If that works, could I then ask you to try rewiring your keypad to different pins and trying pad4pi again? Do the same 4 keys work while the other 12 register double presses?

Thanks for all the effort you've put into helping me figure this out.

Brett

gijsstat commented 8 years ago

Hi Brett,

yes, I think your analysis makes sense. I tried it with the other method and the keypresses work perfectly for all of them. I have switched to different GPIO's (all of the wires) and the behaviour is exactly the same.

I do not have them wired directly, there is a bit of UTP kable in between, but as it works perfectly on the other code I am doubtful that is the cause. Perhaps I should give it a go with a 3x3 matrix, they are not expensive anyway. I will order one, but it will take a while before I receive it I'm sure.

Thanks for your help,

Gijs

On 3 October 2015 at 08:09, Brett McLean notifications@github.com wrote:

Hi Gijs,

I tried pad4pi with my 3x4 keypad using the same pins you're using and I'm not experiencing double key presses on any buttons. I wanted to make sure there wasn't something inherently different about those pins.

It sounds like the 3, 6, A and B keys all work consistently for you (no double key presses). This must mean that the 1st & 2nd rows and 3rd & 4th columns are working correctly on your keypad. Given that the other buttons are giving you trouble, that suggests to me that there's something wrong with the 3rd & 4th rows and 1st & 2nd columns.

The problem could be the keypad itself, the pins on your Pi or the wiring from the keypad to the pins. Speaking of which, how are you connecting your matrix keypad to your Raspberry Pi? I'm using male-to-female jumper wires to connect it directly.

Could I ask you to try your keypad again using RaspberryPiHomeAlarm with the current wiring configuration? I want to make sure the keypad definitely works with the current wiring and pins.

If that works, could I then ask you to try rewiring your keypad to different pins and trying pad4pi again? Do the same 4 keys work while the other 12 register double presses?

Thanks for all the effort you've put into helping me figure this out.

Brett

— Reply to this email directly or view it on GitHub https://github.com/brettmclean/pad4pi/issues/2#issuecomment-145209210.

brettmclean commented 8 years ago

Hi Gijs,

I've ordered a 4x4 matrix keypad to test whether the double key press problem is specific to it. However, it could take a couple of weeks to arrive.

Pad4pi uses the RPi.GPIO library to fire an event whenever a button is pressed, but I can't seem to figure out why that event is firing twice for you instead of just once. This ticket seems to describe our problem, but it doesn't arrive at any definite conclusions: http://sourceforge.net/p/raspberry-gpio-python/tickets/77/

I just wrote debouncing into pad4pi to try to accommodate for this situation. Please upgrade pad4pi to 1.1.1 on your Raspberry Pi by running:

sudo pip install pad4pi --upgrade

Please let me know whether you're still experiencing double key presses after this upgrade.

gijsstat commented 8 years ago

This works perfectly!!!!

Gijs

On 4 October 2015 at 08:56, Brett McLean notifications@github.com wrote:

Hi Gijs,

I've ordered a 4x4 matrix keypad to test whether the double key press problem is specific to it. However, it could take a couple of weeks to arrive.

Pad4pi uses the RPi.GPIO library to fire an event whenever a button is pressed, but I can't seem to figure out why that event is firing twice for you instead of just once. This ticket seems to describe our problem, but it doesn't arrive at any definite conclusions: http://sourceforge.net/p/raspberry-gpio-python/tickets/77/

I just wrote debouncing into pad4pi to try to accommodate for this situation. Please upgrade pad4pi to 1.1.1 on your Raspberry Pi by running:

sudo pip install pad4pi --upgrade

Please let me know whether you're still experiencing double key presses after this upgrade.

— Reply to this email directly or view it on GitHub https://github.com/brettmclean/pad4pi/issues/2#issuecomment-145323474.

brettmclean commented 8 years ago

Excellent! I'm glad this workaround meets your needs.

Thank you for all of your help and patience with this. Feel free to file another issue if you need support in the future.