-
Notifications
You must be signed in to change notification settings - Fork 397
Using GPIO hardware buttons
Add buttons to your jukebox to control volume, skip tracks and more.
Before we start: One of the plus points about this projects, at least in my mind, was the fact that you don't need a soldering iron to build it. Everything is USB, plug and play, thank you, boot and go.
Many, many fellow Phonieboxers have contacted me to push the envelope a bit further and add buttons to the jukebox. Buttons to change the volume and skip between tracks in a playlist.
Enough said, here we go: You will be using push buttons, which are essentially the same as arcade buttons, meaning: when you press them down, they are ON, when you let go, the are OFF. So skipping a track is tapping a button once, changing the volume, each tap changes it a bit. GPIO control has the option to hold down the volume buttons and change every 0.3 seconds the volume according to the configured volume steps.
On your RPi there are pin numbers printed on the board. In the following we are not referring to the board numbers, but the Broadcom (BCM) pin numbering for the GPIO pins. You can find more information on this issue on the pin numbering section of the GPIO Zero documentation site.
Any pin marked βGPIOβ in the diagram above can be used as a pin number. A button attached to βGPIO17β would be specified in the script as pin number 17 rather than 11 (which would be the count on the board).
Ok, you asked for it, roll up your sleeves and read these before you start:
GPIO control provides pull_up_down=pull_up
for all pins (not needed for shutdown pin see bcm2835 Datasheet table 6-31 on page 102)
There are a number of different ways to connect a button. The easiest one is well explained on O'Reilly's RPi site:
- Connecting a Push Switch, O'Reilly
- Watch the Connecting a Push Switch with Raspberry Pi video on YouTube
Since 2.1 we have packed all GPIO stuff into GPIO control.
Please follow the instructions there to configure your GPIO devices. This includes also rotary encoder, like the KY-040.
- Connect buttons to a GPIO pin (see below) and a Ground (GND) pin.
- Update the pins (use the GPIO number!) here:
~/RPi-Jukebox-RFID/settings/gpio_settings.ini
. Donβt add the Ground pins to the settings file! - Then restarting the service with
sudo systemctl restart phoniebox-gpio-control
will activate the new settings.
In general you can choose freely which GPIOs you want to use for which (type of) button. Some best-practice GPIO usage examples are listed here, you can use these a reference / starting point.
For example, this is how to connect the buttons using the flexible pinout:
- Volume Down GPIO6 (PIN31) and GND
- Volume Up GPIO5 (PIN29) and GND
- Play/Pause/Halt (or how you call it) GPIO27 (PIN13) and GND
- Next GPIO23 (PIN16) and GND
- Previous GPIO22 (PIN15) and GND
-
Shutdown (you need to hold button for 2 secs) GPIO3 (PIN5) and GND (PIN6)
- Using these exact pins allows you to also wake the Raspberry Pi up again
After you completed your wiring, you only have to activate the respective button(s) in the GPIO config file (settings/gpio_settings.ini
).
Since the sample file already contains many standard buttons, you can probably use one of the existing entries and only need to activate it by changing the parameter enabled
from False
(default) to True
:
[PlayPause]
enabled: True
Type: Button
Pin: 27
pull_up_down: pull_up
functionCall: functionCallPlayerPause
If you chose different GPIO ports you can also edit this directly.
If you like Phoniebox, consider: buy me a coffee or PayPal
- Code: https://github.com/MiczFlor/RPi-Jukebox-RFID
- Phoniebox home page: English | Deutsch
Phoniebox is a contactless jukebox for the Raspberry Pi, playing audio files, playlists, podcasts, web streams and spotify triggered by RFID cards. All plug and play via USB, no soldering iron needed. Update: if you must, it now also features a howto for adding GPIO buttons controls.
Visit Phoniebox.de
π₯ Version 3
- β Releases
- π΅ Install Jukebox Version 3
- π Report a bug
- π Propose a feature
- βοΈ Feature Status
- π Documentation
- π©βπ» Development
- βοΈ Contributing
- π¦ Code
πΆ Version 2
- β Releases
- π΅ Install Jukebox Version 2
- π Report a bug
- βοΈ Features
- π Documentation
- βοΈ Contributing
- π¦ Code
Version 2 Pages
-
Setup / Upgrades
- Synchronising Phonieboxes in a local network
- Smart Home remote control with MQTT
- Hardware Pinout Overview
- Systemwide Equalizer
- Phoniebox with read-only Filesystem
- HiFiBerry Soundcard Details
- WM8960 Hi-Fi HAT
- PAM8403 Amplifier Power Off
- TPA3118 Amplifier Power Off and EMI improvement
- External Non USB Audio DAC ES9023, PCM5102, etc.
- On-board LEDs with fibre optics
- Setting GPIOs at boot time
- Stop on removal with USB RFID Reader
- Firmware update improves audio out
- Architecture