Skip to content

Audio RotaryKnobVolume

Micz Flor edited this page Feb 3, 2020 · 14 revisions

Rotary knob for volume control (Drehknopf fΓΌr LautstΓ€rke)

Taken from the Phoniebox@GitHub issues forum

  • Tested with this rotary know hardware
  • Three files in the repo are dedicated to this feature:
    • RPi-Jukebox-RFID/scripts/rotary-encoder.py
    • RPi-Jukebox-RFID/scripts/ky040.py
    • RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-rotary-encoder.service.sample
  • See below in this document for info on how to change the direction of the rotary knob

Circuit diagram

(capacitors are optionally)

Tested version: Used 3.3V Pin on Raspberry Pi. Connected everything without Capacitors.

  .---------------.                      .---------------.
  |               |                      |               |
  |           CLK |------o---------------| GPIO 5        |
  |               |      |               |               |
  |           DT  |------)----o----------| GPIO 6        |
  |               |      |    |          |               |
  |           SW  |      |    |          |               |
  |               |      |    |          |               |
  |           +   |------)----)----------| 3.3V          |
  |               |      |    |          |               |
  |           GND |------)----)----------| GND           |
  |               |      |    |          |               |
  '---------------'      |    |          '---------------'
       KY-040            |    |              Raspberry
                         |    |
                        ---  ---
                  100nF ---  --- 100nF
                         |    |
                         |    |
                         |    |
                        ===  ===
                        GND  GND

Once you've got the hardware done, install the scripts the following way:

sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-rotary-encoder.service.stretch-default.sample /etc/systemd/system/phoniebox-rotary-encoder.service 
sudo chown root:root /etc/systemd/system/phoniebox-rotary-encoder.service
sudo chmod 644 /etc/systemd/system/phoniebox-rotary-encoder.service
# enable the services needed
sudo systemctl enable phoniebox-rotary-encoder
sudo reboot

sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
sudo reboot 

The reboot is needed to enable the service and start it.

The scripts now also provide support for a second knob to navigate through the tracks of a folder. Please not that you may use the switch also for other functionality. See the pin out page for details.

If you want to use the button of the knob see/edit gpio-button.py e.g. replace one ordinary button with the knob-button.

Changing the rotary direction

If you want to swap clockwise and counter clockwise, you can edit the code. This is the original:

def rotaryChangeCWVol(steps):
    check_call("./scripts/playout_controls.sh -c=**volumeup** -v="+str(steps), shell=True)
def rotaryChangeCCWVol(steps):
    check_call("./scripts/playout_controls.sh -c=**volumedown** -v="+str(steps), shell=True)

And this is the version with the behaviour in the opposite direction:

def rotaryChangeCWVol(steps):
    check_call("./scripts/playout_controls.sh -c=**volumedown** -v="+str(steps), shell=True)
def rotaryChangeCCWVol(steps):
    check_call("./scripts/playout_controls.sh -c=**volumeup** -v="+str(steps), shell=True)

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