Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide Use hardware momentary switches to control moOde
#51
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!
Reply
#52
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"
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#53
(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?
Reply
#54
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.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#55
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.
Reply
#56
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)
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#57
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
Reply
#58
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)
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#59
@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
Reply
#60
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?
Reply


Forum Jump: