Hardware Play/Pause Button

Raspberry Pi related support

Re: Hardware Play/Pause Button

Postby rikardo1979 » 03 Jun 2016, 19:18

rlsten wrote:Thanks, Pete. That makes sense. But coding a switch to act like a mouse might be beyond me.

I may have a simpler solution: a small touchpad like this: http://www.ergonomictouchpad.com/ergonomic_touchpad.php

I would have to shorten the cable significantly and run it inside the enclosure. They make an even smaller version, but inexplicably it has a PS-2 connector and requires a USB adapter -- way too large for my enclosure.

Here is what the enclosure looks like now:
2016-06-01 19.31.13.jpg


It is basically a 3D Printed enclosure for a Raspberry Pi 3, a Chord Mojo portable DAC, 4 SD cards in SD Card readers attached via USB, a 5300 mAh Lithium battery, and a Tontec 3.5" Screen. The Chord Mojo is attached to the Pi via USB. The purpose is to hide all the cabling between the storage, source, battery, and DAC. I'm using the Chord Mojo because it provides tremendous sound quality and is able to drive full-size headphones.

very good DAC ;)

OP2
>>>Please always follow rules and read before you post<<<
User avatar
rikardo1979
 
Posts: 197
Joined: 10 Apr 2016, 14:34

Re: Hardware Play/Pause Button

Postby rlsten » 05 Feb 2017, 18:26

I wanted to set up a plause/play button on the Raspberry Pi Zero, but when I tried the script that worked successfully on the Raspberry Pi 3:

Code: Select all
#!/usr/bin/env python2
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BOARD)

#Select an unused GPIO header pin as input
InputPin = 11

# Set pin to input, and enable internal pull-up
GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Wait for a button press on the selected pin (pin pulled to ground, falling edge)
GPIO.wait_for_edge(InputPin, GPIO.FALLING)

# When pressed, execute the mpc toggle command:
print "*** Button press detected ***" # (print statement added for debugging)
subprocess.call("mpc toggle", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)



I got a message that the RPi.GPIO module was not found.

I know that the PiZero has the same GPIO numbers as the Pi3, but I believe the Rune image I am using is based on the Raspberry Pi 1, which has different GPIO numbers.

Do I need to alter the code, or do I need to install the RPi.GPIO module? If so, how?

Thanks,
Rod
rlsten
 
Posts: 118
Joined: 25 May 2015, 18:06

Re: Hardware Play/Pause Button

Postby hondagx35 » 05 Feb 2017, 23:36

Hi Rod,

Do I need to alter the code, or do I need to install the RPi.GPIO module?

If it is not found, you have to install it.

If so, how?

python-on-rune-audio-t636.html#p4267
Latest version is 0.6.3

Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Hardware Play/Pause Button

Postby rlsten » 06 Feb 2017, 15:10

Hi Frank,

I followed the instructions, and everything seemed to work o.k., but when I tried the script, I got the following:

Code: Select all
[root@runeaudiozero /]# python2 hw_pause_play.py
Traceback (most recent call last):
  File "hw_pause_play.py", line 2, in <module>
    import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO


What can I do now?

Rod
rlsten
 
Posts: 118
Joined: 25 May 2015, 18:06

Re: Hardware Play/Pause Button

Postby hondagx35 » 06 Feb 2017, 17:43

Hi Rod,

and everything seemed to work o.k.

"seemed" is not good enough.

6.
Install RPi.GPIO
Code: Select all
cd RPi.GPIO-0.5.8
python setup.py install

This has installed without errors?

Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Hardware Play/Pause Button

Postby rlsten » 06 Feb 2017, 18:24

hondagx35 wrote:"seemed" is not good enough.

6.
Install RPi.GPIO
Code: Select all
cd RPi.GPIO-0.5.8
python setup.py install

This has installed without errors?


Well, you caught me there. I said "seemed" because there were no errors, but there were several warnings.

I tried python setup.py install again, and got this result:

Code: Select all
[root@runeaudiozero RPi.GPIO-0.6.3]# python setup.py install
running install
running build
running build_py
running build_ext
running install_lib
running install_egg_info
Removing /usr/lib/python3.6/site-packages/RPi.GPIO-0.6.3-py3.6.egg-info
Writing /usr/lib/python3.6/site-packages/RPi.GPIO-0.6.3-py3.6.egg-info


The pause/play script still reports the same error--the RPi.GPIO module not found.

In what directory should it be?

Rod
rlsten
 
Posts: 118
Joined: 25 May 2015, 18:06

Re: Hardware Play/Pause Button

Postby hondagx35 » 06 Feb 2017, 18:43

Hi Rod,

Removing /usr/lib/python3.6/site-packages/RPi.GPIO-0.6.3-py3.6.egg-info
Writing /usr/lib/python3.6/site-packages/RPi.GPIO-0.6.3-py3.6.egg-info

You have installed the python3 version!
[root@runeaudiozero /]# python2 hw_pause_play.py

And try to run it within python2.

It is only a number, but here it matters.

Install the python2 version or use pythen3 and it will work.

Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Hardware Play/Pause Button

Postby rlsten » 06 Feb 2017, 20:09

Frank,

That was the problem! Installed python3 and everything works now.

Thanks again,
Rod
rlsten
 
Posts: 118
Joined: 25 May 2015, 18:06

Re: Hardware Play/Pause Button

Postby sam9s » 09 May 2018, 12:46

Hi All

I am, also trying to get the play pause executed to runeaudio via GPIO. When I execute the script get the error ..

#python2 hw_pause_play.py

File "hw_pause_play.py", line 21
mpc toggle
^
SyntaxError: invalid syntax

If I type mpc toggle on the command line it works but ith script it does not. Below is the script I created


Below is the script I am using ...... CAN anyone assist PLEASE!!!1



#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BOARD)

# When pressed, execute this command:
print "*** Button press detected ***" # (print statement added only for debugging)
subprocess.call("mpc toggle", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PI$

# Select unused GPIO header pin to be used to toggle play/pause
InputPin = 13

# Set selected pin to input, and enable internal pull-up
GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Wait for a button press on the selected pin (pulled to ground, falling edge)
GPIO.wait_for_edge(InputPin, GPIO.FALLING)

# When pressed, toggle play/pause
mpc toggle
sam9s
 
Posts: 1
Joined: 09 May 2018, 12:37

Re: Hardware Play/Pause Button

Postby rlsten » 09 May 2018, 13:15

Hi Sam9s:

Try this script:

Code: Select all
#!/usr/bin/env python
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BOARD)

#Select an unused GPIO header pin as input
InputPin = 13

# Set pin to input, and enable internal pull-up
GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Wait for a button press on the selected pin (pin pulled to ground, falling edge)
GPIO.wait_for_edge(InputPin, GPIO.FALLING)

# When pressed, execute the mpc toggle command:
print "*** Button press detected ***" # (print statement added for debugging)
subprocess.call("mpc toggle", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rlsten
 
Posts: 118
Joined: 25 May 2015, 18:06

support RuneAudio Donate with PayPal

Previous

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 15 guests