Dear forum,
I am looking for the easiest solution, to play and pause on a picoreplayer with a switch, by just connecting wires to GPIO pins, and using something like a (light)switch to play or pause the player.
I found the thread announcing SqueezeButtonPi, but I didn’t understand that much.
This is for my old father-in-law, he is almost blind, but I can put audiobooks into the playlist for him and I would like him to play and pause by himself.
Another option I could think of would be some kind of USB device to switch between play and pause, that is all he would need.
If you could explain to me in easy how to do, how I could achieve this solution, please?
Thank you very much,
Regards
Pommes
Results 1 to 10 of 14
Thread: Play Pause picoreplayer gpio usb
-
2021-03-03, 09:44 #1
- Join Date
- Dec 2017
- Location
- PARIS, Fr
- Posts
- 212
Play Pause picoreplayer gpio usb
The Earth Has Music For Those Who Listen
-
2021-03-03, 11:10 #2
This should be straightforward. You'll need a 'momentary' switch, rather than a toggle switch, because the action associated with a button is triggered when the gpio pin is earthed briefly. You can set it up so that the button issues the 'pause' command when it is pressed. 'Pause' will pause the player if it is playing, and release the pause if it is paused.
Pick a suitable gpio pin that isn't being used by anything else, such as an audio hat. In my example I'll use gpio24. This is a cut down version of the script that I use for a button board and a rotary encoder - I've trimmed out most of the bits you don't need, but left it so that you can add other buttons if you wish.
This particular version of the script will issue the 'pause' command with a short press, and the 'stop' command with a press longer than half a second (500 millisec).
Code:#!/bin/sh # start pigpiod daemon pigpiod -t 0 -f -l -s 10 # wait for pigpiod to initialize - indicated by 'pigs t' exit code of zero count=10 # approx time limit in seconds while ! pigs t >/dev/null 2>&1 ; do if [ $((count--)) -le 0 ]; then printf "\npigpiod failed to initialize within time limit\n" exit 1 fi # printf "\nWaiting for pigpiod to initialize\n" sleep 1 done printf "\npigpiod is running\n" # load uinput module - required to be able to send keystrokes # then set the permission to group writable, so you don't need to run sbpd with root permissions sudo modprobe uinput sudo chmod g+w /dev/uinput PLAYER_MAC=aa:bb:cc:dd:ee:ff # button SW1 SW1=24 # GPIO pin number SH1=PAUS # command for SHORT press LO1=STOP # command for LONG press LMS1=500 # milliseconds for long press # rotary ROT1=21 ROT2=20 MODE=2 # Detent mode - Assumes 1 dial click is x steps. 1=Step Mode (default) sbpd -v -M $PLAYER_MAC -f /home/tc/sbpd_commands.cfg \ b,$SW1,$SH1,2,0,$LO1,$LMS1 \ e,$ROT1,$ROT2,VOLU,$MODE
The commands should be defined in a file in your home directory called sbpd_commands.cfg. This is my version - I've left all the commands I use in there, so feel free to experiment.
Code:# # <CODE>=<JSON Formatted lms cli command> # # CODE - MUST be a 4 character code, to be reference on command line when # # For commands reference the LMS cli documentation, commands are to be JSO # # Default commands PAUS=["pause"] VOL-=["button","voldown"] VOL+=["button","volup"] PREV=["button","rew"] NEXT=["button","fwd"] POWR=["power"] MIX+=["mixer","volume","+5"] MIX-=["mixer","volume","-5"] VMAX=["mixer","volume","100"] MUTE=["mixer","volume","0"] PLAY=["button","rew.single"] STOP=["stop"] SHUF=["button","shuffle.single"] RSRT=["restartserver"] PRE1=["button","preset_1.single"] PRE2=["button","preset_2.single"] PRE3=["button","preset_3.single"] PRE4=["button","preset_4.single"] PRE5=["button","preset_5.single"] PRE6=["button","preset_6.single"] PRE7=["button","preset_7.single"]
To use this:
1) wire your momentary switch so that it connects gpio24 (in this case) to one of the GND pins.
2) Put the above script into a file in your home folder, e.g. sbpd-script.sh, and make it executable ('sudo chmod +x sbpd-script.sh').
3) Put '/home/tc/sbpd-script.sh' into one of the user commands on the tweaks page.
4) Put 'sbpd_commands.cfg' into your home folder.
Reboot and the button should work.
EDIT: Script edited to include a rotary encoder example.Last edited by chill; 2021-03-03 at 11:58.
-
2021-03-03, 11:36 #3
- Join Date
- Dec 2017
- Location
- PARIS, Fr
- Posts
- 212
-
2021-03-03, 11:53 #4
I just checked - the pcp-sbpd.tcz extension does install pigpio.tcz as a dependency.
The -v option in the command in the last line is for 'verbose' output. Not strictly necessary once it's up and running, but useful for debugging your setup.
Regarding the button - does your father have an easy way to control the volume? If not, you could use a rotary encoder with a push-button function (most have this). The rotary function can be used to control the volume (I'll add an example), and the push-button can be the 'pause' button.
-
2021-03-03, 12:00 #5
- Join Date
- Dec 2017
- Location
- PARIS, Fr
- Posts
- 212
Thanks for helping.
Volume control is not necessary, full Volume does it:-)
Thing is: now i am at his place where parts like buttons and knobs are not readily available. I think i will have to wait and built everything at home and then bring it to him later this year when we go for visit again. Sure i will get the rotary in this case.
Or i will try to improvise with parts i can find laying around.
But anyway, big thumbs up for pushing me in the right direction and for your script as well!!!
Regards
PommesThe Earth Has Music For Those Who Listen
-
2021-03-03, 12:32 #6
If you only have, say, a light switch available I guess you could make it work with that, but you'd have to make it clear that the switch would have to be toggled one way and then the other (closed then opened) in quick succession for a single 'press'. Since you only need the 'pause' function, you could leave out the 'stop' function, or define the long press to be so long (say 3000 milliseconds) that there's no danger of it accidentally being triggered. Or you could define the long press to be the same 'pause' function. Or you could just leave the long press undefined, so it's never triggered. Several options, but from memory I believe that the event is only triggered once the pin is ungrounded - I could be wrong there - so it would be important that the switch is always toggled both ways, and left in the 'open' position.
-
2021-03-03, 13:11 #7
- Join Date
- Dec 2017
- Location
- PARIS, Fr
- Posts
- 212
-
2021-03-03, 14:53 #8
- Join Date
- Jul 2020
- Posts
- 261
You could also consider a small USB numeric keyboard or a USB volume button? I use one of these on a PiZero and that works great.
Last edited by jeroen2; 2021-03-03 at 15:00.
-
2021-03-04, 02:05 #9
- Join Date
- Apr 2005
- Location
- UK/London
- Posts
- 3,940
or add an infrared sensor via GPIO and then control it with a regular IR remote.
That is convenient if the listener is not next to the player ... but inconvenient if the remote cannot be located quickly.
A remote with very few keys or keys that have a distinctive shape make it even easier to use.Paul Webster
http://dabdig.blogspot.com
Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland
-
2021-03-04, 02:12 #10
- Join Date
- Jan 2010
- Location
- Hertfordshire
- Posts
- 6,580
Another option would be voice control.
https://forums.slimdevices.com/showthread.php?p=959650
Sent from my Pixel 3a using Tapatalk