Vector Graphics for Space Commander – Learn to Code Your Own Games
20th May 2021Raspberry Pi Zero Sound Output – Add Analog Sound Through a Headphone Socket and Speaker
27th May 2021Using GPIO Pins For Button Inputs in RetroPie – Building Your Own Retro Gaming Handheld
(This page is part of the Raspberry Pi Handheld Games Console series. Please click here for the full project.)
Stopping GPIONext Interfering With Our Other Pin Functions
In building up my handheld Raspberry Pi Zero powered retro games console I had endless problems getting the sound to work. What should be a relatively simple task just wouldn’t work. Every time I tried to play a sound I would get around 1 second of playback before the Raspberry Pi crashed.
I tried this with the standard analogue sound output and using an I2S sound system. But both would simply fail to work.
Initially I thought it might be a power issue. The Raspberry Pi can be touchy about having too little power. But using a branded 2.5A power supply and disconnecting the LCD screen and anything else that could draw power didn’t fix the problem.
Starting from Scratch
The project was at the stage where both the LCD screen and GPIO based game controller were fully installed. So taking the Raspberry Pi back to the initial setup stage would let me see if there was a clash of software drivers.
I created a fresh SD card with RetroPie and installed that.
The first add on was to install the sound outputs. Everything worked fine!
So I now knew that both the hardware and software for audio output worked correctly.
I then added in the LCD screen. Everything still worked fine.
Bad GPIONext!
I then added in the GPIONext driver for the game controller. And the problem resurfaced!
So GPIONext was the culprit.
Thinking about it this makes sense. Sound on the Raspberry Pi Zero has to be routed to the GPIO pins. GPIONext tampers with the pins to make the controller buttons work with RetroPie.
Fixing the Sound By Specifying the Pin Settings
It took me a while to work out out that there are a number of other configuration options that can be used to limit the pins that GPIONext works with. Once I’d found the instructions it turned out to be a simple 2 command fix!
The Fix
So, GPIONext allows you to specify what pins you want it to control, rather than giving it full access to the whole GPIO header.
If you’ve installed the repository in your pi user home directory,
sudo python3 /home/pi/GPIOnext/config_manager.py --pins 3,5,7,8,10,11,13,15,29,31,32,33
will run the configuration manager using only the pins you specify.
gpionext set pins 3,5,7,8,10,11,13,15,29,31,32,33
will tell the daemon to only use the specified pins and leave the rest alone.
gpionext reload
will reload the daemon so that it remembers our pin settings.
If you then reboot the Raspberry Pi GPIONext should keep itself out of the way of any other pin assignments you make.