Skip to content

Using GPIO hardware buttons

T0bi79 edited this page Sep 17, 2021 · 12 revisions

Control Jukebox with buttons / GPIO

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.


Pin numbering on the RPi

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 below can be used as a pin number. For example, if an LED was attached to “GPIO17” you would specify the pin number as 17 rather than 11.

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)


How to connect the buttons

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 for shutdown) GPIO3 (PIN5) and GND

!!! IMPORTANT Only when using the above listed pins for wiring your shutdown pin you will be able to power-up the Raspberry PI from firmware halt. !!!

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.

Circuit example(s) for the button wiring

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.

There are a number of different ways to connect a button. The easiest one is well explained on O'Reilly's RPi site:

Use GPIO in Phoniebox

Since 2.1 we have packed all GPIO stuff into GPIO control.

Please follow the instructions there to configure your GPIO devices.

Quick Start

  1. Connect buttons to a GPIO pin (see above) and a Ground (GND) pin.
  2. 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!
  3. Then restarting the service with sudo systemctl restart phoniebox-gpio-control will activate the new settings.

You can find more examples here: https://github.com/MiczFlor/RPi-Jukebox-RFID/tree/develop/components/gpio_control/example_configs


(Optional Step): Wire hardware pullup resistor - not needed anymore

You will be running wires from the RPi board to another board where the buttons will be connected. The following image is what this looks like in a successful project.

The extra board to connect the RPi with the buttons using resistors on the extra board.

ATTENTION this example doesn't fit exactly to the code and wiring in How to connect the buttons. On the above image you can also see the pin numbering, in this case containing both: the RPi board numbering on the RPi3 and the Broadcom (BCM) pin numbering used for the code.

Clone this wiki locally