Skip to content

Using GPIO hardware buttons

lenlennart edited this page Nov 28, 2021 · 18 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: 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.


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)

Circuit example(s) for the button wiring

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 below) 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

Which pins to use

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

Activate a button

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.

Home

πŸ”₯ Version 3

Version 3 Pages

Nothing yet

🎢 Version 2

Version 2 Pages

Installation

Specials

RFID Reader

Sound card configurations

Hardware Buttons

Displays (LED, LCD, Matrix, etc.)

Hacks

Bluetooth

AirPlay

MPD tricks

For Developers

Clone this wiki locally