RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Syncing button leds with gameplay

    Scheduled Pinned Locked Moved Help and Support
    led buttonsled cledspicer
    68 Posts 5 Posters 7.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hopwon
      last edited by

      Hi

      I want to set up a routine whereby, when the credit on a game runs out the Credit buttons should start flashing. I am using LEDSpicer on RPI4.
      Has anyone done this and can anyone point me to some examples or how to on the web
      I've looked without success. This will be for Mame games because Mame will spit out events over the network but I have no idea where to start...

      Any help always massively appreciated.

      F G MeduZaPaTM 4 Replies Last reply Reply Quote 0
      • F
        Folly @hopwon
        last edited by Folly

        @hopwon

        Interesting question !

        I did some searching and found this old topic :
        https://retropie.org.uk/forum/topic/22407/read-out-game-state-for-led-control-for-making-start-coin-buttons-to-blink
        This however will not reveal much but it actually says that some games will output some data and that it's possible.
        Another search gave me this :
        https://github.com/mamedev/mame/issues/5998
        Which will lead us to the mame command line docs :
        https://docs.mamedev.org/commandline/commandline-all.html#mame-commandline-output
        So I tested this with galaga with my own runcommand and added -output console like this (with verbose disabled) :

        /opt/retropie/emulators/mame/mame -rompath /home/pi/RetroPie/BIOS/mame\;/home/pi/RetroPie/roms/arcade -output console -c -ui_active -statename arcade/"galaga"   "galaga"
        

        And when coins are inserted the leds will be blinking in the console/log and stop after pressing start like this :

        led0 = 0
        led0 = 1
        led0 = 0
        led0 = 1
        led0 = 0
        

        So now we need to figure out how to extract this information and pass it to a gpio.
        -output network can also be used.
        Perhaps it's easier to read out if we know how this works.

        Btw. I used the latest mame0258

        H 1 Reply Last reply Reply Quote 1
        • H
          hopwon @Folly
          last edited by

          @Folly Awesome stuff thanks! I'll try the -network and I hope that gives me the output I need. This is really helpful as I have somewhere to start from now. Watch this space, I'll try this out this week and update later...

          F 1 Reply Last reply Reply Quote 0
          • F
            Folly @hopwon
            last edited by Folly

            @hopwon

            The mame network is on the localhost :
            http://127.0.0.1:8000/

            Outputting with curl did not work correctly but showed some response now and then :
            (--http0.9 was needed to get it working)

            curl --http0.9 http://127.0.0.1:8000/
            

            Wget did more showing 1 led status but probably not enough :
            (-nv is silent mode)

            wget -nv -O -  http://127.0.0.1:8000/
            

            I tried this program ( commenting out the serial and arduino stuff so it would start) :
            https://github.com/KabukiFlux/MAME-outputs-lamp-to-Arduino
            However it has an issue when mame stops it doesn't detect that.
            It should go to try and reconnect.
            I am not that good with python but if you are you could add your gpio stuff to it.

            1 Reply Last reply Reply Quote 0
            • F
              Folly @hopwon
              last edited by

              @hopwon

              It seems LEDspicer is the way to go but it's very daunting :
              https://retropie.org.uk/forum/topic/21573/ledspicer-led-animation-controller-for-linux
              https://sourceforge.net/p/ledspicer/wiki/Deployment/

              H 1 Reply Last reply Reply Quote 0
              • H
                hopwon @Folly
                last edited by

                @Folly I am using LEDSpicer and I want to get it working as discussed. LEDSpicer does have a PulseAudio plugin to make cool VUE Meter type animations etc but I am not using PulseAudio :)
                So I need to make it work via maybe a program to watch a log file and when it see's "0" it runs a profile/animation to light the credit button.
                Not the most elegant solution but I am not going to use a ton of this type of animation/interaction so just for one or two situations I think is fine

                F 2 Replies Last reply Reply Quote 0
                • F
                  Folly @hopwon
                  last edited by Folly

                  @hopwon

                  I configured with --enable-raspberrypi and compiled.
                  But the files are looked up in /usr/local.
                  So I copied the rules files and the config file to that prefix and added the user to the groups.
                  This command didn't seem to work :

                  sudo udevadm control --reload-rules && udevadm trigger
                  

                  After that I am lost.

                  If you get it working let me know how you did it.


                  I was only able to extract the led info if I used -output console.
                  When using -output network and using wget, curl, netcat, telnet or socat I can't extract the data because it's refreshed on the same line.
                  Very tricky to find a simple solution ;-(

                  H 1 Reply Last reply Reply Quote 0
                  • H
                    hopwon @Folly
                    last edited by

                    @Folly
                    sudo udevadm control --reload-rules && sudo udevadm trigger - missing sudo. I installed it as a Service, its just more convenient.
                    I will try tonight when I get home but does the command spit out error codes as we can use them...

                    F 2 Replies Last reply Reply Quote 0
                    • F
                      Folly @hopwon
                      last edited by Folly

                      @hopwon

                      It took me more than 4 hours to find a solution in bash readout the socket info correctly.
                      The problem is that every line send by mame ends with /r (carriage return) only.
                      Therefor no new line is written to the sdio and so the info cannot be grabbed to do something.
                      Have looked a numerous options like sed, awk etc but nothing worked.
                      With this I came a bit further, showing more lines and the \r :

                      netcat 0 8000|od -c
                      

                      But piping it again did not work good enough.
                      Instead of netcat I found socat which will work somewhat the same and still had the same issue using it like this :

                      socat - TCP4:localhost:8000
                      

                      Now I found this site :
                      https://superuser.com/questions/942217/how-do-i-interactively-type-r-n-terminated-query-in-netcat
                      Which explaines to use ,crnl at the end.
                      I figured I only try ,cr and that worked like this :

                      socat - TCP4:localhost:8000,cr
                      

                      Now we can read the led info and do something with it :

                      socat - TCP4:localhost:8000,cr|while read line;do echo $line;done
                      

                      echo $line can be replace by an if function to enable/disable leds on the gpio pins.

                      The socat command can be reduced using 0 for localhost like this :

                      socat - TCP4:0:8000,cr
                      

                      Edit :
                      I have it running for 1 led :

                      socat - TCP4:localhost:8000,cr|while read line;do [[ $line == "led0 = 1" ]] && raspi-gpio set 4 op pn dh;[[ $line == "led0 = 0" ]] && raspi-gpio set 4 op pn dl ;done
                      
                      1 Reply Last reply Reply Quote 1
                      • F
                        Folly @hopwon
                        last edited by

                        @hopwon said in Syncing button leds with gameplay:

                        does the command spit out error codes as we can use them...

                        With the -d option it gives an error something about a device missing.
                        Have to look again when I get home.

                        H 1 Reply Last reply Reply Quote 0
                        • H
                          hopwon @Folly
                          last edited by hopwon

                          @Folly Just looking at my (default) runcommand output:

                          /opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so --config /opt/retropie/configs/arcade/retroarch.cfg "/home/pi/RetroPie/roms/arcade/1944.zip"
                          
                          

                          To integrate into this would probably mean recompiling with support for mame output features.
                          I see you are just launching mame with a different cli, default mame, if there is such a thing.
                          I think I am in above my head here!!
                          I might see what I can do with LEDSpicer. I have it working to the point that, when a game starts both start and credit flash until credit is pressed at which point it stays steady. Maybe a simple counter output to a file when the button is pressed and watched by a background process so that when it gets to 0 again, I can issue an Emitter command to make it flash again... just some draft thoughts!

                          Just looking into this:

                          LED Spicer Docs

                          F 1 Reply Last reply Reply Quote 0
                          • F
                            Folly @hopwon
                            last edited by Folly

                            @hopwon

                            Indeed I use mame standalone for this.
                            Could be that lr-mame supports it too but it needs adding the options.
                            Will look at it later.

                            Edit :
                            I used my script to produce lr-mame runcommands for arcade :
                            https://retropie.org.uk/forum/topic/29682/development-of-module-script-generator-for-lr-mess-lr-mame-and-mame-standalone
                            (used mamedev.sh, the other is not updated anymore, installed arcade from the category menu item)
                            This will produce configs and runcommands where we can add the -output network option :

                            lr-mame-basename = "/opt/retropie/emulators/retroarch/bin/retroarch --config /opt/retropie/configs/arcade/retroarch.cfg --appendconfig /opt/retropie/configs/arcade/retroarch.cfg.basename -S /home/pi/RetroPie/roms/arcade -s /home/pi/RetroPie/roms/arcade -v -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so 'mame  -cfg_directory /opt/retropie/configs/arcade/lr-mame -c -ui_active -rompath /home/pi/RetroPie/BIOS/mame;/home/pi/RetroPie/roms/arcade/ '%BASENAME%''"
                            lr-mame-basename-network = "/opt/retropie/emulators/retroarch/bin/retroarch --config /opt/retropie/configs/arcade/retroarch.cfg --appendconfig /opt/retropie/configs/arcade/retroarch.cfg.basename -S /home/pi/RetroPie/roms/arcade -s /home/pi/RetroPie/roms/arcade -v -L /opt/retropie/libretrocores/lr-mame/mamearcade_libretro.so 'mame  -cfg_directory /opt/retropie/configs/arcade/lr-mame -output network -c -ui_active -rompath /home/pi/RetroPie/BIOS/mame;/home/pi/RetroPie/roms/arcade/ '%BASENAME%''"
                            
                            

                            Manually added in the second !
                            Testing it reveals THAT THIS WORKS !!!! ;-)

                            1 Reply Last reply Reply Quote 1
                            • F
                              Folly @hopwon
                              last edited by

                              @hopwon said in Syncing button leds with gameplay:

                              does the command spit out error codes as we can use them...

                              pi@raspberrypi:~ $ ledspicerd -d
                              Program terminated by error: Empty devices section
                              
                              H 1 Reply Last reply Reply Quote 0
                              • G
                                gomisensei @hopwon
                                last edited by

                                @hopwon If no ones suggested it yet, advanceMame has a scripting system that can take actions on emulated external outputs such as Led's, and other hardware...

                                https://www.advancemame.it/doc-script here is the documentation for the scripting and outputs.

                                1 Reply Last reply Reply Quote 1
                                • H
                                  hopwon @Folly
                                  last edited by

                                  @Folly The computer is telling the truth, you need to populate the /etc/ledspicerd.conf file :)

                                  But this is fantastic, I will have a go at compiling and then give LR-mame a go. I looked at various scripting options last night and while I can create a counter which will increment every time the credit button is pressed, I could not find a way to decrement it, so I went to bed!

                                  F 1 Reply Last reply Reply Quote 0
                                  • F
                                    Folly @hopwon
                                    last edited by

                                    @hopwon

                                    On which hardware do you run retropie ?
                                    lr-mame can be installed from binary when using rpi.

                                    Tell me, what script did you make to count the inserted coins and do you use a joystick or keyboard ?

                                    mituM H 3 Replies Last reply Reply Quote 1
                                    • mituM
                                      mitu Global Moderator @Folly
                                      last edited by

                                      @Folly said in Syncing button leds with gameplay:

                                      On which hardware do you run retropie ?

                                      First post:

                                      ... I am using LEDSpicer on RPI4.

                                      1 Reply Last reply Reply Quote 1
                                      • H
                                        hopwon @Folly
                                        last edited by

                                        @Folly said in Syncing button leds with gameplay:

                                        Tell me, what script did you make to count the inserted coins and do you use a joystick or keyboard ?

                                        A bit nasty but:

                                        I used inputseeker running in background to grep for a credit button being pressed on(6=P1, 7=P2 in my case) and when it successfully finds a 6 or 7 it increments a counter +1.
                                        You can do it with awk also but I got tired and when to bed :)

                                        1 Reply Last reply Reply Quote 1
                                        • H
                                          hopwon @Folly
                                          last edited by

                                          @Folly said in Syncing button leds with gameplay:

                                          lr-mame can be installed from binary when using rpi.

                                          Installing it now

                                          F 2 Replies Last reply Reply Quote 0
                                          • F
                                            Folly @hopwon
                                            last edited by

                                            @hopwon

                                            I will look at ledspicer with inputseeker again.
                                            Seem a really nice package but I have to take some time to dig into it.
                                            Hopefully I will grasp it.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.