(This brief guide and python script is adapted from savetheclocktower’s project found on GitHub.)
Purpose
This script is meant for whom that want a physical hardware volume knob on a Recalbox project, such as arcade machines. This script is useful for arcade cabinets with speakers that don't have their own hardware volume knob, or would have difficulty moving the speaker control knob near the user.
This script utilizes a standard 5 pin rotary encoder and has been tested on the encoder from Adafruit. 5 wires are required for this rotary encoder: three for the knob part (A, B, and ground), and two for the button part (common and ground). Here’s a reference for the Raspberry pi’s GPIO pins.
Description | BCM # | Board # |
knob A | GPIO 26 | 37 |
knob B | GPIO 19 | 35 |
knob ground | ground pin below GPIO 26 | 39 |
button common | GPIO 13 | 33 |
button ground | ground pin opposite GPIO 13 | 34 |
You can use whichever pins you want; just update the volume-monitor.sh script if you change them. If you lack the push button in your rotary encoder then leave pins unoccupied.
Volume daemon
The script below works as the following: it listens on the specified pins, and when the knob is turned one way or another, it uses the states of the A and B pins to figure out whether the knob was turned to the left or to the right. That way it knows whether to increase or decrease the system volume in response, which it does with the command-line program amixer.
To install the script into your recalbox:
mount -o remount, rw /boot
nano /recalbox/scripts/volume-monitor.py
This is a note for Substring or others. Please make one of those nice script boxes here with the contents of the monitor-volume script from savetheclocktower’s GitHub. BUT!!!!!! Change line one from #!/usr/bin/env python3 to: #!/usr/bin/env python2, and change line #25 from from queue import Queue to from multiprocessing import Queue
chmod +x /recalbox/scripts/volume-monitor.py
touch ~/custom.sh && chmod u+x ~/custom.sh
nano ~/custom.sh
python /recalbox/scripts/volume-monitor.py
reboot
This is a note for Substring or others. I tried to make this guide to not use the change directory (ie: cd command), or any other unnecessary commands, so it's as simple as “copy, paste, enter” all the way through. Please test on your recalbox to make sure this guide works as I have written it. If not, please make the modifications needed. Also, please convert bolded sections and other, “it’s meant to be terminal commands” to the write formating in the mini how-to guide. Thank you.