Moode Forum

Full Version: Use hardware momentary switches to control moOde
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9
Hello,
I just switched from Volumio to Moode and I'm very satisfied, the software is working much better!
I have set up the GPIO button handler to ON and tried to configure the GPIO but it's not working :Sad I know that the hardware is OK because it was working on Volumio (https://github.com/tomatpasser/gpio-buttons). What I tried:
- Pin 16 : mpc stop
- Pin 24 : /var/www/vol.sh up 1
- Pin 17: mpc next


Is there something else I need to do? How could I investigate?

Also, I have another question: is there a possibility to configure different functions if I do a long press? I see for example in https://github.com/bnielsen1965/rpi-gpio-buttons that the option pressed sets the timing.

Thanks for your support!
In GPIO Config does the line below appear under the SAVE button?

"NOTE: Use a comma to delimit arguments in the CMD field. Example: mpc,load,My Playlist"
(04-12-2020, 12:38 PM)Tim Curtis Wrote: [ -> ]In GPIO Config does the line below appear under the SAVE button?

"NOTE: Use a comma to delimit arguments in the CMD field. Example: mpc,load,My Playlist"

Hello Tim, thank you so much for your quick reply, and congratulation again for your work!!

No, this line does not appear under the SAVE button. I tried though (mpc,stop) and it doesn't work either. Any other idea?
I see that the comma delimiter was part of upcoming 6.5.0 release. In 6.4.2 space is the delimiter.

It's odd that the commands are apparently not being executed. The way to troubleshoot is as follows:

1. Turn off GPIO button handler in System config
2. Open an SSH terminal
3. Run it from the command line

Code:
sudo /var/www/command/gpio-buttons.py

4. Press a button
5. Note any errors or debug logging that's printed.
I don't see anything Confused
Code:
pi@moode:~ $ sudo /var/www/command/gpio-buttons.py
2020-04-12 15:51:44 sw_1: pin=16, enabled=1, bounce_time=1000, cmd=mpc stop
2020-04-12 15:51:44 sw_3: pin=25, enabled=1, bounce_time=1000, cmd=mpc stop
2020-04-12 15:51:44 sw_4: pin=17, enabled=1, bounce_time=1000, cmd=mpc next

Also, my setup is that the GPIO button is connected between +3V and GND (EDIT: wrong, I should have written: "GPIO pin is connected to +3V when I press the button"). I don't know if it's useful to know that or not.
The parameters look ok. You will need to add some debug to the python script to see if the callback function that's mapped to the pin is actually being executed.

Code:
sudo nano /var/www/command/gpio-buttons.py

add a print statement to the code block below then save (Ctrl-x y return (or enter)

Code:
       def sw_1_event(channel):
           subprocess.call(sw_1_cmd)
           print('Executed: ' + sw_1_cmd)
I added your lines, it looks like this now:

Code:
# Main
while True:
   time.sleep(1)

def sw_1_event(channel):
          subprocess.call(sw_1_cmd)
          print('Executed: ' + sw_1_cmd)


But I still don't see anything happening when I press any button Sad
That would suggest the code is not detecting any change in the pin state. Below is the code block for button 1.

Code:
   if str(row['id']) == '1' and row['enabled'] == '1':
       sw_1_pin = int(row['pin'])
       sw_1_cmd = row['command'].split(',')
       sw_1_cmd = [x.strip() for x in sw_1_cmd]
       GPIO.setup(sw_1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

       def sw_1_event(channel):
           subprocess.call(sw_1_cmd)

       GPIO.add_event_detect(sw_1_pin,
                             GPIO.RISING,
                             callback=sw_1_event,
                             bouncetime=bounce_time)
       print(str(datetime.datetime.now())[:19] + ' sw_1: pin=' +
             str(sw_1_pin) + ', enabled=' + row['enabled'] +
             ', bounce_time=' + str(bounce_time) + ', cmd=' + row['command'])

Pin numbering used is SoC.
https://raspi.tv/2013/rpi-gpio-basics-4-...and-inputs

Code:
# Use SoC pin numbering
GPIO.setmode(GPIO.BCM)
@sisim

I'm not sure exactly what " my setup is that the GPIO button is connected between +3V and GND" means, but perhaps you need to detect a FALLING transition instead of the RISING transition I see in the code Tim quoted.

Regards,
Kent
The numbering is the one I use as well. For example, the pin 16 in the Moode settings is "physically" the pin 36 on the Pi, right?

Why doesn't it detect anything? I checked again with a multimeter and the buttons are working. Any other idea?
Pages: 1 2 3 4 5 6 7 8 9