Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Senior Member
    Join Date
    Dec 2017
    Location
    PARIS, Fr
    Posts
    212

    Play Pause picoreplayer gpio usb

    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
    The Earth Has Music For Those Who Listen

  2. #2
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Location
    Nottingham, UK
    Posts
    2,095
    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 button can control any player - if your father has more than one player you can put its MAC address in the script so that it controls the desired player. If he only has one player, you can remove the -M option from the command in the last line.

    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"]
    You'll need to install the sbpd extension, and I'm not sure if that also installs pigpio as a dependency - if not, install that too.

    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.

  3. #3
    Senior Member
    Join Date
    Dec 2017
    Location
    PARIS, Fr
    Posts
    212
    Quote Originally Posted by chill View Post
    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
    
    sbpd -v -M $PLAYER_MAC -f /home/tc/sbpd_commands.cfg b,$SW1,$SH1,2,0,$LO1,$LMS1
    The button can control any player - if your father has more than one player you can put its MAC address in the script so that it controls the desired player. If he only has one player, you can remove the -M option from the command in the last line.

    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"]
    You'll need to install the sbpd extension, and I'm not sure if that also installs pigpio as a dependency - if not, install that too.

    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.
    Thank you very much,
    now it is a lot clearer to me, how this is supposed to work.
    I will try to get a momentary switch in the next few days and then will try to do it:-)

    Regards
    Pommes
    The Earth Has Music For Those Who Listen

  4. #4
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Location
    Nottingham, UK
    Posts
    2,095
    Quote Originally Posted by chill View Post
    You'll need to install the sbpd extension, and I'm not sure if that also installs pigpio as a dependency - if not, install that too.
    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.

  5. #5
    Senior Member
    Join Date
    Dec 2017
    Location
    PARIS, Fr
    Posts
    212
    Quote Originally Posted by chill View Post
    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.
    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
    Pommes
    The Earth Has Music For Those Who Listen

  6. #6
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Location
    Nottingham, UK
    Posts
    2,095
    Quote Originally Posted by Pommes View Post
    Thing is: now i am at his place where parts like buttons and knobs are not readily available.
    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.

  7. #7
    Senior Member
    Join Date
    Dec 2017
    Location
    PARIS, Fr
    Posts
    212
    Quote Originally Posted by chill View Post
    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.
    i found some old iphone headsets with headphone remote buttons, but no soldering iron, lets see, maybe i can ducktape the wires ...
    ill keep you posted:-)
    The Earth Has Music For Those Who Listen

  8. #8
    Senior Member
    Join Date
    Jul 2020
    Posts
    261
    Quote Originally Posted by Pommes View Post
    i found some old iphone headsets with headphone remote buttons, but no soldering iron, lets see, maybe i can ducktape the wires ...
    ill keep you posted:-)
    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.

  9. #9
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,961
    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

  10. #10
    Senior Member
    Join Date
    Jan 2010
    Location
    Hertfordshire
    Posts
    6,594
    Quote Originally Posted by Pommes View Post
    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
    Another option would be voice control.
    https://forums.slimdevices.com/showthread.php?p=959650

    Sent from my Pixel 3a using Tapatalk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •