Thank you for your donation!


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


Solved: GPIO buttons on moOde 9.
#1
I have a single GPIO button defined on my Pi3A+ based player but alas it's no longer working in moOde 9.

On another thread, Tim found this:

Code:
pi@moode9:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-20 07:44:17 bounce_time=1000
Traceback (most recent call last):
File "/var/www/daemon/gpio_buttons.py", line 43, in <module>
  print(str(datetime.datetime.now())[:19] +
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can only concatenate str (not "NoneType") to str

A bit of search on the interweb tells me that "NoneType" is Python for "null" so I'm not sure why that applies to the output from datetime..  Anyway, I did a bit of digging in my own system and find different errors.

With the GPIO button configured, but not activated the script runs cleanly and printls out the configuration:

Code:
master@prometheus:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-20 15:45:21 bounce_time=1000
2024-05-20 15:45:21 row1, pin27, enabled=0, pull=GPIO.PUD_UP, command=/home/master/StartStop.sh
2024-05-20 15:45:21 row2, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row3, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row4, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row5, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row6, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row7, pin2, enabled=0, pull=GPIO.PUD_UP, command=
2024-05-20 15:45:21 row8, pin2, enabled=0, pull=GPIO.PUD_UP, command=
Killed
The Killed at the end is when I enabled the button through the UI.

When the button is enabled:

Code:
master@prometheus:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-20 15:46:33 bounce_time=1000
2024-05-20 15:46:33 row1, pin27, enabled=1, pull=GPIO.PUD_UP, command=/home/master/StartStop.sh
Traceback (most recent call last):
 File "/var/www/daemon/gpio_buttons.py", line 50, in <module>
   GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down=btn_1_pull)
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 647, in setup
   raise ValueError(
ValueError: Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN
From which I understand I just need to set the value of the "pull" variable to be PUD_UP rather than GPIO.PUD_UP.  I think this is set in the configuration database via the UI, so hopefully someone can point me at where that happens and I can test to see if that fixes things.

I have no idea why Tim got the NoneType error when I didn't though...
----------------
Robert
Reply
#2
I think it could be that the cfg_gpio table has null values in the empty columns. This and your other error are most likely the result of insufficient QA. I must speak with that guy ;-)
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
(05-20-2024, 07:09 PM)Tim Curtis Wrote: I think it could be that the cfg_gpio table has null values in the empty columns. This and your other error are most likely the result of insufficient QA. I must speak with that guy ;-)

Ah, give that guy a break, Getting moOde 9 out at all is a seriously amazing thing, and where's the fun if there aren't deliberate mistakes for us to find?
----------------
Robert
Reply
#4
(05-20-2024, 07:51 PM)the_bertrum Wrote:
(05-20-2024, 07:09 PM)Tim Curtis Wrote: I think it could be that the cfg_gpio table has null values in the empty columns. This and your other error are most likely the result of insufficient QA. I must speak with that guy ;-)

Ah, give that guy a break, Getting moOde 9 out at all is a seriously amazing thing, and where's the fun if there aren't deliberate mistakes for us to find?

Besides, all us early-adopters had ample chances to explore these nooks and crannies in the code during the pre-releases season. Seems to me you can spread the guilt around.


And don't forget the sysadmin's motto from back in the day, "never install the x.0 version; always wait for the point release".

Regards,
Kent
Reply
#5
lol, you are all guilty!
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
I never thought to try the pre releases on my system with buttons...
----------------
Robert
Reply
#7
Run the sql commands below to fix up the cfg_gpio table.

Code:
moodeutl -q "UPDATE cfg_gpio set pin='' WHERE pin IS NULL"
moodeutl -q "UPDATE cfg_gpio set enabled='' WHERE enabled IS NULL"
moodeutl -q "UPDATE cfg_gpio set pull='' WHERE pull IS NULL"
moodeutl -q "UPDATE cfg_gpio set command='' WHERE command IS NULL"
moodeutl -q "UPDATE cfg_gpio set param='' WHERE param IS NULL"
moodeutl -q "UPDATE cfg_gpio set value='' WHERE value IS NULL"
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#8
OK, well I'm really stumped.
The NULL condition only occurs when no button assignments have been set, as soon as those are configured I see no more null errors, although Tim's commands also work for fixing that condition of course.
The issue now is that as soon as button assignments are set, the GPIO.setup() function fails because it doesn't like the value of the pull_up_down parameter.  The error message is "ValueError: Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN".  So I did some hacking.  With the button set up using the UI on a clean system that never had any buttons set previously I see this:
Code:
master@apollo:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-21 08:00:44 bounce_time=1000
2024-05-21 08:00:44 row1, pin27, enabled=1, pull=GPIO.PUD_UP, command=command
Traceback (most recent call last):
 File "/var/www/daemon/gpio_buttons.py", line 50, in <module>
   GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down=btn_1_pull)
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 647, in setup
   raise ValueError(
ValueError: Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN
OK, so pull_up_down needs to be PUD_UP but is set to the value of btn_1_pull which is set to the value of 'pull' which is GPIO.PUD_UP.  So:

Code:
master@apollo:~ $ moodeutl -q "UPDATE cfg_gpio set pull='PUD_UP'"
That should do the job...

Code:
master@apollo:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-21 08:01:26 bounce_time=1000
2024-05-21 08:01:26 row1, pin27, enabled=1, pull=PUD_UP, command=command
Traceback (most recent call last):
 File "/var/www/daemon/gpio_buttons.py", line 50, in <module>
   GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down=btn_1_pull)
 File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 647, in setup
   raise ValueError(
ValueError: Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN
But, but, just.... grrrr
Let's see if setting the value directly in the code works:

Code:
master@apollo:~ $ sudo nano /var/www/daemon/gpio_buttons.py

        GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down='PUD_UP')

master@apollo:~ $ sudo /var/www/daemon/gpio_buttons.py
2024-05-21 08:11:36 bounce_time=1000
2024-05-21 08:11:36 row1, pin27, enabled=1, pull=PUD_UP, command=command
Traceback (most recent call last):
  File "/var/www/daemon/gpio_buttons.py", line 50, in <module>
    GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down='PUD_UP')
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 647, in setup
    raise ValueError(
ValueError: Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN

This is why I'm now a manager, not a technician.
----------------
Robert
Reply
#9
Then most pertinent search result for that error....

This post. Sigh.
----------------
Robert
Reply
#10
Right, well.  I'm sure there's a reason for this, but I can't imagine what it might be.

The GPIO.setup() function is defined in /usr/lib/python3/dist-packages/RPi/GPIO/__init__.py and the error I see is there:
Code:
       if pull_up_down not in (PUD_UP, PUD_DOWN, PUD_OFF):
           raise ValueError(
               'Invalid value for pull_up_down - should be either PUD_OFF, '
               'PUD_UP or PUD_DOWN')


But hang on, that array of possible values is an array of variables!  Sure enough up there at the top:
Code:
PUD_OFF = 20
PUD_DOWN = 21
PUD_UP = 22
I don't know, maybe they want to do some sums with these at some point....

Back in /var/www/daemon/gpio_buttons.py, I did this:

Code:
       GPIO.setup(btn_1_pin, GPIO.IN, pull_up_down=22)
And lo and behold, the button now works.  Although it is is sluggish, but that's for another day.

I'm not sure what the best place to "fix" this is, probably easiest to set the numeric values into the GPIO table perhaps.  Hard coding in the gpio_buttons.py works for me for now though since I only have one button and I don't need to change it's direction.
----------------
Robert
Reply


Forum Jump: