Sunday, 10 January 2016

Pocket PiGRRL - adding a mute

I recently made myself a Pocket PiGRRL based on Adafruit's tutorial - it really is a great machine and a brilliant learning experience.

There was one aspect though that I didn't like, the speaker hisses, not particularly loud and when your playing a game its not that noticeable but if you have got the volume down it is really annoying. Its all down the Raspberry Pi's noisy analogue audio out so there isn't a great deal you can do to clean it up.

My solution was to add the ability to shutdown the amp, effectively muting it when I didn't want any sound.

The PAM8302A amp breakout board has a shutdown (SD) pin which when a ground (logic zero) is connected it puts the amp into idle mode, muting the amp and reducing power consumption.

I soldered a piece of wire between GPIO 26 on the bottom of the A+ and the shutdown pin on the PAM8302A ampl.

This gave me a way of triggering the shutdown pin next I needed some software and a way of running it.

Using this tutorial as the basis I added an 'Apps' tab to emulation station where I could run 2 scripts to mute and unmute the amp.

If you want to configure your Pocket PiGRRL to do the same, you can follow the instructions below.

Download and install wiring pi
The software uses wiringpi's gpio command line utility, so download and install it.

Configure emulation station
Copy the emulation station default settings file to the pi user's emulation station configuration:
cp /etc/emulationstation/es_systems.cfg ~/.emulationstation/
Add the 'apps' tab to the settings file:
nano ~/.emulationstation/es_systems.cfg
Scroll down to the bottom and add the following before the </systemList> text:
    <extension>.sh .SH .py .PY</extension>
Save and exit using Ctrl X.

Make a directory in roms to hold the scripts:
mkdir ~/RetroPie/roms/apps
Create a script to mute the amp by setting GPIO 26 to low (0):
nano ~/RetroPie/roms/apps/

gpio -g mode 26 out
gpio -g write 26 0
And an unmute script:
nano ~/RetroPie/roms/apps/

gpio -g mode 26 out
gpio -g write 26 1
Make the scripts executable:
chmod +x ~/RetroPie/roms/apps/
chmod +x ~/RetroPie/roms/apps/
You can now test the scripts by running them:
Reboot and the Apps tab will appear in emulation station with 2 options to mute and unmute the amp.

I wanted the amp to be muted by default, so I added the script to be run at boot by editing /etc/rc.local:
sudo nano /etc/rc.local
Scroll down and add the unmute command under '/usr/local/bin/retrogame &' but before 'exit 0':
/home/pi/RetroPie/roms/apps/ &


  1. Hello,
    This was a very helpful guide, however there was one mistake. In the file es_systems.cfg:


    needs to be:


    Emulation station would not add the apps tab until I made this change.

    Thanks again! =)

    1. Thank you. I wonder how that slipped through my extensive QA process ;)

  2. great toutorial. thank you
    how do you switch it on / off when you booted up? can you expand your toutorial with some hints to bind the mute function to one of the tft buttons? would be great.

    1. Once it has booted up to emulation station, scroll across to the 'Apps' tab you created and select the mute / unmute amp links.

  3. This comment has been removed by the author.

  4. Whoah, there's a lot of codes there. Nevertheless, thank you for your tutorial...

  5. This comment has been removed by the author.

  6. Would this work for a PiGrrl2 as it looks like GPIO26 is used for the down button and can't see any other GPIO pins spare?