Thank you for your donation!


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


Problem: GPIO buttons on moOde 9.1.4
#1
Good day. Today I updated the player from version 8.3.9 to 9.1.4 and I have problems with gpio buttons.
With the GPIO button configured, but not activated the script runs cleanly and printls out the configuration:
Code:
pi@MoOde:/home/pi# sudo /var/www/daemon/gpio_buttons.py
bounce=150ms
btn1, enabled n, gpio 02, pull-up, cmd=sudo,poweroff
btn2, enabled n, gpio 03, pull-up, cmd=mpc,next
btn3, enabled n, gpio 04, pull-up, cmd=mpc,prev
btn4, enabled n, gpio 05, pull-up, cmd=mpc,toggle
btn5, enabled n, gpio 06, pull-up, cmd=mpc,stop
btn6, enabled n, gpio 07, pull-up, cmd=
btn7, enabled n, gpio 08, pull-up, cmd=
btn8, enabled n, gpio 09, pull-dn, cmd=
When the button is enabled:
Code:
pi@MoOde:~ $ sudo /var/www/daemon/gpio_buttons.py
bounce=150ms
btn1, enabled y, gpio 02, pull-up, cmd=sudo,poweroff
Traceback (most recent call last):
 File "/var/www/daemon/gpio_buttons.py", line 60, in <module>
   GPIO.add_event_detect(int(row['pin']), GPIO.RISING, callback=btn_1_event, bouncetime=bounce_time)
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 858, in add_event_detect
   _check_input(mode)
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 249, in _check_input
   raise RuntimeError(msg)
RuntimeError: You must setup() the GPIO channel as an input first
On versions below 9, such a problem did not occur
Reply
#2
Try something other than pin 2
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Tried on pins from 2 to 6
Reply
#4
Code:
pi@MoOde:~ $ sudo /var/www/daemon/gpio_buttons.py
bounce=150ms
btn1, enabled n, gpio 02, pull-up, cmd=sudo,poweroff
btn2, enabled n, gpio 03, pull-up, cmd=mpc,next
btn3, enabled n, gpio 04, pull-up, cmd=mpc,prev
btn4, enabled n, gpio 05, pull-up, cmd=mpc,toggle
btn5, enabled y, gpio 06, pull-up, cmd=mpc,stop
Traceback (most recent call last):
 File "/var/www/daemon/gpio_buttons.py", line 90, in <module>
   GPIO.setup(int(row['pin']), GPIO.IN, pull_up_down=int(row['pull']))
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 696, in setup
   _check(lgpio.gpio_claim_input(_chip, gpio, {
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/lib/python3/dist-packages/lgpio.py", line 755, in gpio_claim_input
   return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i
   raise error(error_text(v))
lgpio.error: 'GPIO busy'
Reply
#5
I mean don't use pin 2 at all.

And if running it from the cmd line its best to first kill any existing process that may be running because of a successful launch from the GPIO Control screen otherwise you get a "GPIO Busy" error


Code:
sudo killall gpio_buttons.py
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
The 3rd pin also needs to be excluded, then everything works fine. Unfortunately, this will require changes to PCB of my device. Given the lack of sound when using the UPNP client, both from the phone and from the computer, I returned to version 8.3.9
Reply
#7
Ok both pins 2 and 3. This is a bug in gpio_buttons.py having to do with the GPIO.setup() function for these pins under PiOS Bookworm.

Try this updated file.

Code:
sudo wget -q https://raw.githubusercontent.com/moode-player/moode/develop/www/daemon/gpio_buttons.py -O /var/www/daemon/gpio_buttons.py
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#8
Now everything works fine. Thanks, Tim. It remains to figure out the upnp client, but that's the topic of another thread
Reply
#9
Hi. Another problem has emerged. When booting, the command specified for pins 2 and 3 is most likely used. This does not occur with every power-up or reboot, but more often than half the time
Reply
#10
Maybe it has something to do with the special configuration of pins 2,3 having fixed pull up resistors and designated as SDA/SCL?

Here's the code block for button 1.
Code:
   if str(row['id']) == '1' and row['enabled'] == '1':
       if row['pin'] in ('2','3'): # Pins 2,3 have fixed pull-up resistors
           GPIO.setup(int(row['pin']), GPIO.IN)
       else:
           GPIO.setup(int(row['pin']), GPIO.IN, pull_up_down=int(row['pull']))
       btn_1_cmd = [x.strip() for x in row['command'].split(',')]
       def btn_1_event(channel):
           time.sleep(0.005) # Edge debounce of 5 ms
           if GPIO.input(channel) == 1: # Only deal with valid edges
               subprocess.call(btn_1_cmd)
       GPIO.add_event_detect(int(row['pin']), GPIO.RISING, callback=btn_1_event, bouncetime=bounce_time)

Might be a good question for the Raspberry Pi Forums.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Forum Jump: