GPIO on Volumio

Hi,

I got a Raspberry PI 4B with Volumio 2.681 and IQaudio DAC+. And I got a python script which is successfully tested on raspberry pi OS but it don’t work on Volumio:

import RPi.GPIO as GPIO
import time

button1 = 13
button2 = 16
button3 = 18
button4 = 22
button5 = 37
led    = 11


def setup():
       print("Setup Buttons")
       GPIO.setmode(GPIO.BOARD)
       GPIO.setup(button1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
       GPIO.setup(button2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
       GPIO.setup(button3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
       GPIO.setup(button4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
       #GPIO.setup(button5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
       GPIO.setup(led, GPIO.OUT)
       print("Setup finished")

def loop():
        while True:
              buttonPushed(button1)
              buttonPushed(button2)
              buttonPushed(button3)
              buttonPushed(button4)
              #buttonPushed(button5)

def endprogram():
         GPIO.output(led, False)
         GPIO.cleanup()

def buttonPushed(pin):
         buttonState = GPIO.input(pin)
         if buttonState == 0:
             GPIO.output(led, True)
             print("Button on GPIO " + str(pin) + " pushed")
             while GPIO.input(pin) == 0:
                time.sleep(0.2)
         else:
             GPIO.output(led, False)

if __name__ == '__main__':

          setup()

          try:
                 loop()

          except KeyboardInterrupt:
                 print ('keyboard interrupt detected')
                 endprogram()

A simple program to test the buttons, but I only get the message “Button on GPIO 13 pushed”. It seems there’s something wrong with my setup. Is there something I have to know about Volumio and GPIOs or do I need an update on wiringpi? I haven’t found anything in the forums and docs.

Any help would be appreciated.

Carsten

PS: I don’t want to use the GPIO plugin :wink:

Hi,

Looking at the pinout for the IQaudio DAC+ it looks like several of your buttons collide with pins used by the DAC. These will be used in the DT overlay and therefore probably not available for you to use in wiringpi.

But why does it work on Raspberry Pi OS?

But why does it work on Raspberry Pi OS?

Did you enable the DT overlay for the DAC in Raspberry Pi OS? If so, how?

I checked it and added/updated the following lines to my /boot/config.txt (Raspberry Pi OS)

#dtparam=audio=on
dtoverlay=iqaudio-dacplus

And it still works.

If you are on Volumio 2.xx the GPIO rules may not be the most updated.
Check which version you have installed with

apt-cache policy raspberrypi-sys-mods
volumio@volumio:~$ apt-cache policy raspberrypi-sys-mods
raspberrypi-sys-mods:
  Installed: 20170519
  Candidate: 20170519
  Version table:
 *** 20170519 0
        500 http://archive.volumio.org/debian/ jessie/main armhf Packages
        100 /var/lib/dpkg/status

pi@raspberrypi:~ $ apt-cache policy raspberrypi-sys-mods
raspberrypi-sys-mods:
  Installiert:           20201026
  Installationskandidat: 20201026
  Versionstabelle:
 *** 20201026 500
        500 http://archive.raspberrypi.org/debian buster/main armhf Packages
        100 /var/lib/dpkg/status

Can update with rpi-update?

Can update with rpi-update?

That’s not normally recommended. I don’t know what state Volumio would be in afterwards.

update you can …upgrade you can’t it will screw up your system…

sudo pip3 install RPi.GPIO --upgrade

Upgrade does the trick!

i hope nothings broken…

sadly you are right. The system doesn’t start. I take a backup and try again. Perhaps some of my previous tries damaged the system.

only use update … upgrade will kill it most of the times …

No, that would upgrade your kernel leaving you with a non bootable device.

That should work without bricking the system…

RPi.GPIO --upgrade makes my script work but after starting it Volumio hangs up. Only a reboot makes Volumio working again.

A partial success :slight_smile:

So it seems to be a problem with my script? Or the import of RPi.GPIO?

Perhaps the best idea is to buy a raspberry pi 3B+ and wait until 4B is supported.

https://volumio.github.io/docs/FAQs/General.html

Now it works. I moved button3 to pin 38 and it works. It seems that pin is preallocated.