1

this is a beginners question, I suppose. How can I write a python code that allows the use of 2 (or more) push buttons connected to the GPIO? Each button should start a different shell script. The buttons are connected to the 3.3V pin and through a resistor to a GPIO pin. Also, I think, de-bouncing is necessary for the plan. All the simple tutorials deal only with one button and the more complex projects have a lot of code I don't understand. I tried a bit of copy/pasting, but without success. Help would be appreciated. Bye SG

2
  • 3
    Do the simplest project for one button. Get that working. Understand how it works. It will then be trivial to add another button/script.
    – joan
    Dec 4 '20 at 11:19
  • post your code and explain hiw it does not work as expected
    – jsotola
    Dec 4 '20 at 17:21
1

Almost sounds like a homework issue :-) As such (and that this is not really a programming site) I would break the problem down as follows:

  1. Understand how to import the GPIO Zero, time and subprocess modules into your program
  2. Understand how to use the sys module to call to trigger the shell scripts AND report their return codes (assuming they do)
  3. Understand how to use the basic button function of GPIO Zero using the wait option. Test pull up / down, wait and bounce options. Check both switches work the way you want by testing each in its own program
  4. Create a basic loop in Python that waits till you press ctrl-c and end without an error message
  5. Change the loop with sleep so other things can run
  6. Change one of the button functions to use the callback capability to action the call to the script
  7. Change the final button function to use the callback to run the other script

Try not to use copy and paste (though I guess we all do) - it never teaches you the basics of coding or how to solve problems...

Done - voted close as the issue was way too wide ranging.

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .