Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

getting the GPIO buttons on the 3.2" screen to switch between HDMI and GPIO screen



  • I'm trying to write a script that when the GPIO push button on the 3.2" screen is pressed. It would disable the USB audio on the portable device and transfer the audio to HDMI, disable the GPIO screen leaving it black and transfer the video to HDMI. If I run my script from the terminal, everything works. If I set it up in the rc.local then reboot. It will not run. I also put the & at the end of the sudo python /home/pi/switch/2button.py & in rc.local. Tried a few other methods to auto start my script. but nothing. This is my script:

    import RPi.GPIO as GPIO
    import os
    
    def onButton(channel):
        if channel == 24:
            os.system("sudo cp switch/alsa-baseusboff.conf /etc/modprobe.d/alsa-base.conf")
            os.system("sudo cp switch/confighdmi.txt /boot/config.txt")
            os.system("sudo cp switch/rc.localblack /etc/rc.local")
            os.system("sudo reboot")
    
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    
    GPIO.add_event_detect(24, GPIO.FALLING, callback=onButton, bouncetime=20)
    
    def onButton(channel):
        if channel == 23:
            os.system("sudo cp switch/alsa-baseusbon.conf /etc/modprobe.d/alsa-base.conf")
            os.system("sudo cp switch/configportable.txt /boot/config.txt")
            os.system("sudo cp switch/rc.localscreen /etc/rc.local")
            os.system("sudo reboot")
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    
    GPIO.add_event_detect(23, GPIO.FALLING, callback=onButton, bouncetime=20)
    
    input()```


  • @md201 Looks like my directories were off. Adding the simple /home/pi/switch to all os.system commands did the trick............ :(



Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.