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.
Note - a few people have noted in the comments that on other models of PiGrrl (such as the Pi Grrl 2) GPIO 26 is already used and have suggested changing this to GPIO 7.
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.cfgScroll down to the bottom and add the following before the </systemList> text:
<system> <fullname>Applications</fullname> <name>Apps</name> <path>~/RetroPie/roms/apps</path> <extension>.sh .SH .py .PY</extension> <command>%ROM%</command> <platform>apps</platform> <theme>esconfig</theme> </system>Save and exit using Ctrl X.
Make a directory in roms to hold the scripts:
mkdir ~/RetroPie/roms/appsCreate a script to mute the amp by setting GPIO 26 to low (0):
nano ~/RetroPie/roms/apps/mute_amp.sh gpio -g mode 26 out gpio -g write 26 0And an unmute script:
nano ~/RetroPie/roms/apps/unmute_amp.sh gpio -g mode 26 out gpio -g write 26 1Make the scripts executable:
chmod +x ~/RetroPie/roms/apps/mute_amp.sh chmod +x ~/RetroPie/roms/apps/unmute_amp.shYou can now test the scripts by running them:
~/RetroPie/roms/apps/mute_amp.sh ~/RetroPie/roms/apps/unmute_amp.shReboot 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.localScroll down and add the unmute command under '/usr/local/bin/retrogame &' but before 'exit 0':
/home/pi/RetroPie/roms/apps/mute_amp.sh &
Hello,
ReplyDeleteThis was a very helpful guide, however there was one mistake. In the file es_systems.cfg:
<command></command>%ROM%
needs to be:
<command>%ROM%</command>
Emulation station would not add the apps tab until I made this change.
Thanks again! =)
Thank you. I wonder how that slipped through my extensive QA process ;)
Deletegreat toutorial. thank you
ReplyDeletehow 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.
Once it has booted up to emulation station, scroll across to the 'Apps' tab you created and select the mute / unmute amp links.
Deletegreat
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteWhoah, there's a lot of codes there. Nevertheless, thank you for your tutorial...
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteWould 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?
ReplyDeleteThank you for the help!
ReplyDeleteThis is a good workaround to an annoying problem. A note for those using this technique for the Pi Grrl 2: GPIO 26 is being used by the down button on the d-pad. Looking through the GPIO pins I noticed that GPIO 7 and 8 weren't being used, so I used GPIO 7 instead of 26. Hopefully, I'm not missing anything, but it seems to work well.
ReplyDeletewhen i try to run the programs after writing them, I get these errors:
ReplyDeletepi@retropie:~ $ ~/RetroPie/roms/apps/mute_amp.sh
/home/pi/RetroPie/roms/apps/mute_amp.sh: line 1: gpio: command not found
/home/pi/RetroPie/roms/apps/mute_amp.sh: line 2: gpio: command not found
pi@retropie:~ $ ~/RetroPie/roms/apps/unmute_amp.sh
/home/pi/RetroPie/roms/apps/unmute_amp.sh: line 1: gpio: command not found
/home/pi/RetroPie/roms/apps/unmute_amp.sh: line 2: gpio: command not found
You need to download and install wiringpi - see the instructions above for a link.
DeleteI want to make it so a button I press turns the mute function on and off (gpio 23 on my pigrrl 2). Is there any way I could do that?
ReplyDeleteDo you mean a physical button? One of the buttons already on your PiGrrl 2?
DeleteYou will still need a physical connection to the shutdown pin on the amp. I suppose you could wire up a pin to the shutdown pin and then create a program which checked the state of your Pi Grrl 2 button and then switched the amp shutdown pin. Sounds do-able if you know a little python.
Hello, I really enjoyed the post. Could you please help me understand what I am doing wrong? I followed your instructions and I have all of the scripts made and ready to go. But after I run the mute or unmute script nothing happens to the amp. I think I may have wired it wrong. I tried to follow your pictures but I am at a loss. I soldered wire to gpio 7 because I have a pi 2. The wire from gpio 7 goes directly to the SD pin of the amp. I changed the script for mute and unmute to reflect that
ReplyDeletenano ~/RetroPie/roms/apps/mute_amp.sh
gpio -g mode 7 out
gpio -g write 7 0
like I said, I think my problem is with the wiring because you mentioned having the wire somehow connect to the A+ pin and the shutdown pin. My wire just goes directly to gpio 7 to the SD pin on the amp. Any help would be great, thanks.
The first thing I would check is that you have definitely wired it to GPIO 7 on the bottom of the Pi as you script looks fine. I found it really difficult to match up the pin as its on the bottom and clearly the position is reversed.
DeleteYou only need to connect a gpio pin to the SD pin on the amp - so providing you have got the right pin you are on the right track.
Thank you for your reply. I successfully soldered the gpio 7 to the shutdown pin and my scripts are running correctly to shutdown the amp and then to re-activate it. I like having the speaker to be muted at boot like your guide indicates. Is there any way you can help me figure out where I should put the script to unmute the speaker so that I get audio right after I launch a emulator/rom? Thank you
DeleteSuper.
DeleteI have never tried, but could you modify the script which launches the game to run the un_mute script before it launches the game and mute after the script it launched?
It'll probably take some investigation. I would start looking at the retropie scripts, although they are likely to be pretty complicated.
Hello again, with a little bit of effort I successfully have made it so that when a ROM is launched with emulationstation it unmutes the speaker on launch. Then when you exit the game properly, the speaker is then automatically muted. To recap, Thanks to your guide I am able to have my PiGRRL 2 be muted on boot by shutting down the AMP. Then by adding some script I am now able to automatically unmute the speaker upon launch of a game and then automatically mute the speaker when exiting the game. I would not have been able to do any of this without your help/guide so once again. Thank you.
DeleteAll I did was create two files in
/opt/retropie/configs/all/
one of the files must be called runcommand-onstart.sh and in the file just put a line of script to direct to the ~/RetroPie/roms/apps/unmute_amp.sh file. Then make another file in that folder called runcommand-onend.sh and put in the following line of script for muting the speaker ~/RetroPie/roms/apps/mute_amp.sh
This will then mute the speaker when your exit the ROM and return to main emulation station menu. Enjoy!
This comment has been removed by the author.
ReplyDelete