GPIO Pins to control volume

Get help for Volumio here!

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

GPIO Pins to control volume

Postby smartroad » Tue Dec 09 2014 13:07

Hi I was wondering if it is possible to control the volume of Volumio via GPIO pins? I ask as I am making a WiFi speaker and would like to have control on the speaker for volume up/down and mute - just to make it easy to adjust volume rather than having to get phone out :)
Random avatar
smartroad
Sunday DIYer
Sunday DIYer
 
Posts: 40
Joined: Wed Nov 19 2014 14:28

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


GPIO Pins to control volume?

Postby Glop109 » Tue Dec 09 2014 16:04

Hello

I suggest you to add an ask in this message : interface-with-gpio-and-rs232-spi-full-communication-t2192.html
We are a least 2 guy to ask something like that :).
Random avatar
Glop109
Sunday DIYer
Sunday DIYer
 
Posts: 37
Joined: Fri Nov 21 2014 18:08


GPIO Pins to control volume?

Postby MobeyDuck » Tue Dec 09 2014 20:12

Glop109 wrote:Hello

I suggest you to add an ask in this message : interface-with-gpio-and-rs232-spi-full-communication-t2192.html
We are a least 2 guy to ask something like that :).


I believe what you want isn't the same as what Glop asks, or i just didn't understand what you actually want. Glop wants basic control using a few buttons over GPIO. This isn't hard to achieve.

Get some buttons connect them on 3.3v and a GPIO in.
Create a python script, import bash/shell commands and send mpc commands

At least thats the simplest way i can think of, you could skip the bash import with mpc and use python-mpd but then you'll need to install python-mpd.

You could take a loot at this thread for inspiration: detect-when-something-streaming-t2056.html
User avatar
MobeyDuck
Moderator
 
Posts: 482
Joined: Sun Jan 05 2014 20:28
Location: The Netherlands


GPIO Pins to control volume?

Postby Glop109 » Wed Dec 10 2014 08:44

I think that the volume buttons on GPIO is in the same way that I suggeste to configure via GUI the GPIO actions In or Out. (or more deeply within serial communication).

I think it's posible t do that with script and other but it will be "endUser" to propose that on the config in GUI... :D
Random avatar
Glop109
Sunday DIYer
Sunday DIYer
 
Posts: 37
Joined: Fri Nov 21 2014 18:08


GPIO Pins to control volume?

Postby Michael20 » Thu Dec 11 2014 08:38

Buttons shouldn't be a big thing. A volume knob i think is more difficult, but this variant would be nice! :D
Random avatar
Michael20
Fresh off the boat
Fresh off the boat
 
Posts: 9
Joined: Tue Nov 25 2014 07:50


GPIO Pins to control volume?

Postby MobeyDuck » Thu Dec 11 2014 12:26

You could use a rotary encoder to do that. Adafruit sells those they also made a sample script to control windows audio. See http://www.adafruit.com/product/377
User avatar
MobeyDuck
Moderator
 
Posts: 482
Joined: Sun Jan 05 2014 20:28
Location: The Netherlands


GPIO Pins to control volume?

Postby Buckler » Thu Dec 11 2014 13:19

Hi,

A Volume knob is not that difficult!

Hardware:
You need a rotary encoder and some wires. Dupont cables (male/female) are handy, you can solder one side to the encoder and the other side (female connector) can easily be connected with de GPIO connector.

Rotary.jpg
(I have a Pi-Crust board on top of my Pi so I have used the male-connector)
Rotary.jpg (29.62 KiB) Viewed 38527 times


SOFTWARE:

Gpio
To get access to the GPIO-pins you have to install the RPi.GPIO python module:

Download the package from sourceforge
Code: Select all
wget http://sourceforge.net/projects/raspberry-gpio-python/files/raspbian-wheezy/python-rpi.gpio_0.5.8-1_armhf.deb


Install the package
Code: Select all
sudo dpkg -i python-rpi.gpio_0.5.8-1_armhf.deb



Rotary class
You can use the rotary-class from Bob Rathbone source: http://www.bobrathbone.com/raspberrypi_rotary.htm
(Bob has also a fantastic tuturial for building a radio project!)

Save the rotary class in: /home/pi



Script
Then you need some code to control the volume (based on the test-script from Bob):
Code: Select all
#!/usr/bin/env python
#
# Raspberry Pi Rotary Test Encoder Class
#
# Author : Bob Rathbone
# Site   : http://www.bobrathbone.com
#
# This class uses a standard rotary encoder with push switch
#
import subprocess
import sys
import time
from rotary_class import RotaryEncoder

# Define GPIO inputs (BCM)
PIN_A = 23              # Pin 16
PIN_B = 24             # Pin 18
BUTTON = 25     # Pin 22

# This is the event callback routine to handle events
def switch_event(event):
        if event == RotaryEncoder.CLOCKWISE:
              subprocess.call(['mpc', 'volume', '+2' ])
              time.sleep(.2)
        elif event == RotaryEncoder.ANTICLOCKWISE:
              subprocess.call(['mpc', 'volume', '-2' ])
              time.sleep(.2)
        elif event == RotaryEncoder.BUTTONDOWN:
              subprocess.call(['mpc', 'toggle' ])
        #elif event == RotaryEncoder.BUTTONUP:
              #print "Button up"
        return

# Define the switch
rswitch = RotaryEncoder(PIN_A,PIN_B,BUTTON,switch_event)

while True:
        time.sleep(0.5)


Save this script in: /home/pi/VolumeKnob.py

Auto-start the script:
Code: Select all
nano /etc/rc.local


Add this line before the exit 0:

Code: Select all
python /home/pi/VolumioKnob.py &


Reboot the Pi and you can control the volume with the rotary-encoder and with a button press you can pause/play the music!

Succes!

Harry
Last edited by Buckler on Fri Dec 12 2014 06:05, edited 1 time in total.
User avatar
Buckler
Serious Listener
Serious Listener
 
Posts: 65
Joined: Sun Sep 14 2014 08:34
Location: The Netherlands


GPIO Pins to control volume?

Postby balbuze » Thu Dec 11 2014 17:30

Hi!
great !!! that is exactly what I was looking for !!!
But I've got a problem with Volumio 1.5, I can't install python-rpi.gpio. The message is :
Code: Select all
i@volumio-bureau:~$ sudo apt-get install python-rpi.gpio
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python-rpi.gpio
E: Couldn't find any package by regex 'python-rpi.gpio'

Any idea ?
Thanks !
User avatar
balbuze
Moderator
 
Posts: 1807
Joined: Thu May 08 2014 08:42
Location: Isère France


GPIO Pins to control volume?

Postby balbuze » Thu Dec 11 2014 18:14

Ok
I did it following this thread : rpi-volumio-gpio-for-python-t1491.html
It works now ! But I change step from 2 to 4 in the VolumeKnob.py file.
Thanks a lot!
User avatar
balbuze
Moderator
 
Posts: 1807
Joined: Thu May 08 2014 08:42
Location: Isère France


GPIO Pins to control volume?

Postby balbuze » Thu Dec 11 2014 20:22

too bad....
I thought it was ok but after a reboot mpd does not work anymore. No webUI... I can ssh to my pi. Get the following error :
Code: Select all
pi@volumio-bureau:~$ sudo service mpd restart
[ ok ] Stopping Music Player Daemon: mpd.
[....] Starting Music Player Daemon: mpdIllegal instruction
 failed!

What to do to avoid a complete re-install ?
info : At boot time I hear the boot sound of Volumio
User avatar
balbuze
Moderator
 
Posts: 1807
Joined: Thu May 08 2014 08:42
Location: Isère France

Next

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest