Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 30

Hybrid View

  1. #1

    Feature request picoreplayer: Play state to GPIO

    Hi,

    maybe i have overseen some threat here, otherwise maybe a new useful feature:

    "When PiCorePlayer is playing a GPIO Port ist pulled up or down"

    My use case: Swithing the Amp with the already configurable "Power GPIO" i would like to use a second GPIO to switch a two way relay for toggling the line input of the amp to external source, when picoreplayer is paused.

    Thanks and
    best Regards
    Axel

  2. #2
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    2,203
    hi Aki7,

    This should be possible with a simple shell script. People have been doing similar things to a drive LEDs etc.

    Use wiringPi to set GPIO (or shell commands).

    Use $pcp mode to determine if squeezelite is play/stop.

    I assume you know about the hardware for a relay. A GPIO can not drive a relay directly.

    In the home directory there are a couple of scripts that should give you some ideas.

    https://www.picoreplayer.org/how_to_..._via_ssh.shtml
    https://www.picoreplayer.org/pcp_cli.shtml

    regards
    Greg

  3. #3
    Hi Greg,

    thanks for the fast response. Relays used already, no problem with this.

    Need some help with:

    On play -> GPIO high
    On pause -> GPIO low

    Event driven. So i think in my small knowledge, squeezelite code has to be changed. I am not a linux freak, but lot of programming in former days.

    Axel

  4. #4
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    2,203
    hi Axel,

    Although not a good as an interrupt solution a simple loop inquiry of LMS may be OK.

    The command "pcp mode" returns "play" or "stop". Do the inquiry every second and set relay appropriate. This only create a 1% load on CPU and little network traffic, not enough to cause problems.

    regards
    Greg

  5. #5
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    4,008
    The code used to be almost that way, but it was causing more problems than anything. So it was changed to what it is now.

    I would recommend installing the powersave plugin to LMS and that will power down your player if it is paused for a period of time.

    *Edit* read the OP, we are not doing two GPIO's, so you need to use the script method Greg mentioned, or build your own version of squeezelite. Source code is here

    https://github.com/ralph-irving/squeezelite

    Take a look at gpio.c and then also look at all sections of the code flagged with #if GPIO

    You can also have a look at the commit https://github.com/ralph-irving/sque...c6dff0283a05a1 that removed the gpio trigger on a pause event.
    Last edited by paul-; 2019-03-05 at 17:59.
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  6. #6
    Hi Greg, hi Paul,

    thanks for your input.

    @Greg: Polling from the LMS ... feels not so elegant for me ;-) and will result in delayed sound on play start in my use case. There seems to be some code, discussed on this forum. Not shure if it has worked finally.
    @Paul: Have taken a look at your 2nd link. Maybe my misunderstanding, but i would like to set a GPIO according to play state, not reading a GPIO and doing something afterwards.
    I have neither linux nor c knowledge, so creating my own fork seems not so realistic for me :-) Anyway, do you have a hint, in which module squeezelite is receiving commands from the LMS? My idea would be first stage, writing or deleting a file (or some flag variable) according to play state. So polling this file or "global environment variable" could be done asynchron by other modules, local on the "machine". Maybe every 1/10 s.

    Setting the GPIO synchron from squeezelite may have introduced some timing problems? On the other hand, there should be time enough, when squeezelite changes his play state.

    regards
    Axel

  7. #7
    Junior Member
    Join Date
    Jul 2020
    Posts
    29
    Quote Originally Posted by Greg Erskine View Post
    hi Axel,

    Although not a good as an interrupt solution a simple loop inquiry of LMS may be OK.

    The command "pcp mode" returns "play" or "stop". Do the inquiry every second and set relay appropriate. This only create a 1% load on CPU and little network traffic, not enough to cause problems.

    regards
    Greg
    Do you happen to know why "pcp mode" does not distinguish "stop" and "power off" state? It returns "stop" in either state.

    Code:
    tc@Konyha:~$ pcp play
    tc@Konyha:~$ pcp mode
    play
    tc@Konyha:~$ pcp pause
    tc@Konyha:~$ pcp mode
    pause
    tc@Konyha:~$ pcp stop
    tc@Konyha:~$ pcp mode
    stop
    tc@Konyha:~$ pcp play
    tc@Konyha:~$ pcp mode
    play
    tc@Konyha:~$ pcp power off
    tc@Konyha:~$ pcp mode
    stop
    tc@Konyha:~$
    Last edited by sakos; 2020-08-07 at 09:47. Reason: add output

  8. #8
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    2,203
    hi sakos,

    Generally speaking the "pcp commands" are only a simple interface into LMS commands. They can only respond as LMS responds.

    Having said that, reading the documentation we should get an "undefined" value. Maybe we have coded a default value of stop.

    Code:
    <playerid> mode ?
    
    The "mode" command allows to query the player state and returns one of "play", "stop" or "pause". If the player is off, "mode ?" returned value is undefined.
    
    Example:
    
    Request: "04:20:00:12:23:45 mode ?<LF>"
    Response: "04:20:00:12:23:45 mode stop<LF>"
    I have added your post to the list of things todo.

    regards
    Greg

Tags for this Thread

Posting Permissions

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