laurentalacoque / TouchSelfie-extended

Open Source Photobooth based on the official Raspberry Pi 7" Touchscreen
55 stars 33 forks source link

Hardware Buttons not recognized? #88

Closed Anekd0t closed 4 years ago

Anekd0t commented 4 years ago

Hi! Thank you for a great project.

However I can for the love of my life not get the hardware buttons to work. I am using this button from adafruit: [https://learn.adafruit.com/press-your-button-for-raspberry-pi/assembly] with the same suggested wiring.

I have tried putting the wire on both 8, 10 and 12 pins. I have also tried changing them to 11, 13 and 15 in without any difference. Tried different wires and different switches. I have tried both pull_up and pull_down and changed active state in constants.py. The led on the button is working but upon quitting photo booth, I am presented with: “No hardware buttons found, generating software buttons” every time.

Anyone have some input on what I am doing wrong? Cheers

laurentalacoque commented 4 years ago

Hey @Anekd0t 😉 Are you sure that you installed the gpio python module? You can check this by launching the python interpreter and importing the module.

$ python
>>> import RPi.GPIO as GPIO

If this raises an exception, then you don't have it and should install it.

sudo apt-get install python-rpi.gpio

Should do the trick

Anekd0t commented 4 years ago

Hey @laurentalacoque !

Thank you for the quick reply!

Ok, so I ran “python”, then “import RPi.GPIO as GPIO” in the terminal, and I was not presented with any errors, so I figure it was already imported?

If I run “sudo apt-get install python-rpi.gpio” it said it was already installed.

Still getting “No hardware buttons found” error..

Question: I am also only using 1 button as of now if that matters? Question: I can change pins while photobooth.sh is running right, since it’s polling for hardware buttons every 100ms it should remove the software button where corresponding pin is connected?

Cheers

laurentalacoque commented 4 years ago

Hey @Anekd0t Ok, simplest thing to do is to debug Buttons interface independently. Luckily enough, you can do this by launching the module itself. For this:

$ cd scripts
$ python hardware_buttons.py

This script reports button presses and releases.

You might want to change the preassigned buttons pins, for this change line 105 from

    buttons = Buttons()

to

    buttons = Buttons(buttons_pins=[12,13]) # change with your actual pins numbers
    # note: it's ok to have a long list of pins, put any pin you want or even list(range(25)) to be sure

Then restart hardware_button.py and check if the key presses reports any event.

Anekd0t commented 4 years ago

Hey again @laurentalacoque ,

Ok, so I’m not sure if I’m following your directions accurately, but I ran hardware_button.py in the terminal before and after the change of line 105. I changed the pins to 10,8 and 12. Button is connected to pin 8. This is what I got: D090956E-FBBA-4771-A18B-AF2519305072

Cheers

laurentalacoque commented 4 years ago

it's buttons = Buttons(buttons_pins=[12,13]) (mind the final s at buttons in buttons_pins) My bad.

Anekd0t commented 4 years ago

Hey @laurentalacoque ,

Sorry, added the s.

Also, I noticed that in constants.py on line 173 it says “button_pins”, without an extra s in the end. Is this correct?

However, still similar error: 3775DA28-1FBE-45A4-907C-6ADD1A3F3C3E

Is the ”Unknown pull_up_down mode 21” normal? Noticed it’s been there from the start.

If I run it in the python editor(?) I get this as response: BA88F10E-A57A-4097-A3A9-9AA7C4DE2D05

Cheers for helping out! :)

Anekd0t commented 4 years ago

Hey @laurentalacoque Had any time to look at the previous comment?

Cheers

Anekd0t commented 4 years ago

Hey @laurentalacoque I just wanna say I figured it out, it seems the script is not recognizing my buttons since they don’t send a signal to the pins unless grounded. That’s probably why the script says “no hardware buttons found”. If I hold down the buttons while starting photobooth, the software buttons are removed. So I went ahead and commented out the “if no hardware buttons” in user_interface.py, since I know I have buttons configured - then changed active state to 0. Now it all works as intended :]

Might be a good idea to add this as a comment to the installation instructions regarding what type of buttons one can or should use.

Cheers

laurentalacoque commented 4 years ago

Hey @Anekd0t Nice you figured it out! I'll improve the hardware button script to facilitate the discovery (one day, hopefully)