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 @Folly
      last edited by

      @Folly said in Syncing button leds with gameplay:

      @hopwon

      I uninstalled my previous install of LEDspice.

      This I what I did :

      cd ~/Downloads/LEDSpicer-development/
      ./autogen.sh
      ./configure --prefix=/usr --sysconfdir=/etc --enable-raspberrypi 
      make
      sudo make install
      sudo usermod -a -G users pi #replace user with your username
      sudo usermod -a -G input pi #replace user with your username
      sudo cp /usr/share/doc/ledspicer/examples/21-ledspicer.rules /etc/udev/rules.d/
      sudo chmod 744 /etc/udev/rules.d/21-ledspicer.rules
      sudo udevadm control --reload-rules && sudo udevadm trigger
      sudo cp /usr/share/doc/ledspicer/examples/ledspicer.conf /etc
      ledspicerd -v
      ledspicerd -d
      sudo ledspicerd -d #seems to be the way to go with RaspberryPi
      

      Running with -d gives :
      Program terminated by error: Empty devices section

      Added the controller name in /etc/ledspicer.conf :

      	<devices
      		name="RaspberryPi"
          		boardId="1"
      >
      	</devices>
      

      or

      	<devices>
      		name="RaspberryPi"
          		boardId="1"
      	</devices>
      

      Still no dice.

      Any help would be appreciated.

      Make sure when you are starting for the first time, run the daemon in foreground (-f) as it is the best way to troubleshoot. Its quite verbose in its output so if there is a problem you should get a good indication of exactly what it is.

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

        @hopwon

        Thanks, will have a look when I am using my pi.

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

          @Folly So I managed to get the command line options passed to lr-mame based on the info you provided. I can now see that (I am using Missile Command as a test), led0=0, led1=0, led0=1 led1=1, repeating in the console for any button press.
          This tells me (I think) that mame is making two led's flash and thats it. No specific output regarding credit or I could be wrong.

          From runcommand.log using -output console

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

          These represent a button press, I think one press = 4 log entries

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

            @hopwon

            Yes indeed that is correct.

            It's jsut how the original hardware worked and that is implemented in mame.
            It's basically the same with the galaga example I used before, only here you have to add 2 credits for 1 player and 4 credits for 2 players.

            What you want is not implemented in mame so you need to get the information in an other way just like you did with inputseeker.
            I tested that and indeed reading event becomes very easy but you need to add a whole script for doing stuff with that information.

            I see the problem getting some uniform data for every game it seems a bit different.
            Basically it could mean that for every game you need to make a script.

            If you want more advanced ways you could look at mame lua plugin scripts.
            With that you might be able to extract data in a different / better way.
            FYI I used them for tests but I never wrote them.

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

              @Folly @MeduZaPaT talks about doing the part to make credit flash here:

              link text

              If there was a way to set a counter or write to an output, then that's the solution...

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

                @hopwon

                Ok, I used your ledspicer.conf and customised it for use with RaspberryPi (GPIO).
                For error sake I made all red, green and blue use the same pin (red=4, green=5 and blue=6) and added an empty profile which is explained over here.

                Now I don't get errors anymore when running :

                ledspicerd -d
                

                Then I tried :

                ledspicerd -f
                

                That gave me :

                2023-09-21 21:23:41 initCheckPermitted: 
                +---------------------------------------------------------+
                |Sorry, you don't have permission to run this program.    |
                |Try running as root, e.g. precede the command with sudo. |
                +---------------------------------------------------------+
                Program terminated by error: Failed to initialized Raspberry PI GPIO
                

                So now I know RaspberryPi needs running with sudo, like this :

                sudo ledspicerd -f
                

                I might have to check ledspicer.conf again for correct values and then I have to add some game profiles.
                Would like to check first if the mame "-output network" is detected without using emulationstation.

                sudo ledspicerd -f should do that trick right ?

                Will have look later again.

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

                  @Folly the -f option runs in foreground so yes, you should see something...

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

                    @hopwon said in Syncing button leds with gameplay:

                    These represent a button press, I think one press = 4 log entries

                    Missed that part.
                    No they aren't really button presses.
                    On the other end you could see it that way but inserting a coin while playing the game does nothing.
                    Taking galaga as example, it's that led0 goes on and off after inserting a coin and when the start button is not pressed yet and not playing the game.
                    For missile that is 2 coins (led0) and 4 coins(led1).

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

                      @hopwon

                      Was able to test the led on GPIO pin 4 with this :

                      pi@raspberrypi:~ $ sudo ledspicerd -l
                      Test LEDs (q to quit)
                      
                      Select a Led (r to reset, q to quit):
                      4
                      
                      Select a Led (r to reset, q to quit):
                      r
                      
                      Select a Led (r to reset, q to quit):
                      q
                      

                      So basically ledspicer is working.
                      Have to look at the game profiles now.

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

                        @hopwon

                        It seems very hard to understand the docs and how everything actually works ;-(

                        I am struggling with creating a single game input xml in /usr/share/ledspicer/profiles/arcade.
                        I added galaga in /usr/share/ledspicer/profiles/profile_arcade.xml like this :

                        <?xml version="1.0" encoding="UTF-8"?>
                        <LEDSpicer
                        	version="1.0"
                        	type="Profile"
                        	backgroundColor="Black"
                        >
                        	<inputs>
                        		<input name="galaga"/>
                        	</inputs>
                        </LEDSpicer>
                        

                        I tried to begin with the example from here.
                        Though I have to edit the file somehow as it is not accepted.
                        Do you have an example for me ?
                        Or, do you know what to edit ?

                        I read over here that you can also use a "craftProfiles" option for multiple games.
                        "LEDSpicer will attempt to use the pre-scraped data from mame (gameData.xml) along with controls.ini (if available) and colors.ini (if available) to set lighting based on the games control scheme. So... one profile_arcade.xml file to manage thousands of roms."

                        They also use the emitter part.
                        Is that nessesary to use ?

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

                          @Folly I use craft profiles, it only works for mame. You need a profile in the profiles dir called profile_arcade.xml and then you call emitter from "runcommand_onstart.sh" with LoadProfileByEmulator

                          Craft profiles really take the heavy lifting out of LEDSpicer config and its an awesome feature.

                          This is my profile_arcade.xml - there is nothing in it...

                          <?xml version="1.0" encoding="UTF-8"?>
                          <LEDSpicer
                          	version="1.0"
                          	type="Profile"
                          	backgroundColor="Black"
                          >
                          </LEDSpicer>
                          

                          After that LEDSpicer takes care of the rest.

                          I'll try and do a bit more of a write up but Friday night is calling! But check out this link for a guide on as I used it to eventually decode and get LEDSpicer running...

                          LEDSpicer on attractmode

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

                            @hopwon

                            I want to get it working before I implement in emulationstation.

                            Ok, so I do need the emitter.

                            First I started with :

                            sudo ledspicerd -f
                            

                            So for galaga I tried the command but got an error :

                            pi@raspberrypi:~ $ emitter LoadProfileByEmulator galaga arcade
                            Error: Failed to open device 0xd209:0x1700 id 1
                            Failed to execute rotator 2 1 '2' 1 1 '2'
                            

                            The led that I attached burns but there is no other effect when starting galaga.
                            Any ideas ?

                            All commands are done over 3 terminal consoles.

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

                              @hopwon

                              I am really not sure if I should spend more time on this.
                              Ledspicer seems a really nice and advanced program but I am missing the bigger picture on how it works and how all configs and xml's are connected to each other.
                              Perhaps I will ditch the elements from the ledspicer.conf except one.
                              That way I can see if 1 element will react if not I will probably stop trying.

                              Ps.
                              I have send a message to @MeduZaPaT hope he can help.

                              MeduZaPaTM 1 Reply Last reply Reply Quote 0
                              • MeduZaPaTM
                                MeduZaPaT @hopwon
                                last edited by MeduZaPaT

                                @hopwon
                                Hey, I just read this, yes you will be able to do this, I read the whole section and looks like you are close:
                                you have this:
                                1 mame is sending the network data
                                2 ledspicer is set and running
                                3 you have a profile to load the galaga input.
                                4 you got the mapping names from mame (led0 and led1)

                                • Create a profile called galaga.xml inside arcade inside profiles
                                • Create a input called galaga.xml inside inputs
                                • test the profile by running ledspicerd -p galaga

                                profile file galaga.xml:

                                <?xml version="1.0" encoding="UTF-8"?>
                                <LEDSpicer
                                	version="1.0"
                                	type="Profile"
                                	backgroundColor="Black"
                                >
                                	<inputs>
                                		<input name="galaga"/>
                                	</inputs>
                                </LEDSpicer>
                                

                                Input file galaga.xml:

                                <?xml version="1.0" encoding="UTF-8"?>
                                <LEDSpicer
                                    version="1.0"
                                    type="Input"
                                    name="Mame"
                                >
                                        <map
                                            type="Element"
                                            target="P1_START"
                                            trigger="led0"
                                            color="White"                      <!-- <<< The color to change -->
                                            filter="Normal"                    <!-- <<< Filter to use -->
                                        />
                                        <map
                                            type="Element"
                                            target="P2_START"
                                            trigger="led1"
                                            color="White"                      <!-- <<< The color to change -->
                                            filter="Normal"                    <!-- <<< Filter to use -->
                                        />
                                </LEDSpicer>
                                
                                

                                you need to place the files in the correct directories:

                                ledspicer
                                   |----animations
                                   |----inputs
                                   |----profiles
                                         |----arcade
                                         |----nes
                                         |----[another emulator system name here and so on]
                                

                                Sorry for the late response, I am working on the LEDSpicer UI to make your life much, much easier

                                LEDSpicer

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

                                  @MeduZaPaT

                                  Thank you for your reply !

                                  I used your xml's.

                                  I understand your post like this :

                                  • create a profile galaga.xml file inside /usr/share/ledspicer/profiles/arcade/
                                  • create an input galaga.xml file inside /usr/share/ledspicer/input/
                                  • run mame with galaga and "-output network" (tested and working)
                                  • run ledspicerd -p galaga to test and get it working (got errors)

                                  Now I got this output :

                                  pi@raspberrypi:~ $ ledspicerd -p galaga
                                  Program terminated by error: Unable to read the file /usr/share/ledspicer/profiles/galaga.xml
                                  Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=/usr/share/ledspicer/profiles/galaga.xml
                                  
                                  • so I moved the profile file one folder up in /usr/share/ledspicer/profiles/ (solved not finding the file)
                                    (edit : another solution is not moving the file and use ' ledspicerd -p arcade/galaga')

                                  Then got this output :

                                  pi@raspberrypi:~ $ ledspicerd -p galaga
                                  Program terminated by error: Unable to read the file /usr/share/ledspicer/inputs/galaga.xml Error=XML_ERROR_PARSING_ELEMENT ErrorID=6 (0x6) Line number=7
                                  

                                  My ledspicer.conf is in /etc/ and I connected one green led to gpio 4 :

                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <LEDSpicer
                                      version="1.0"
                                      type="Configuration"
                                      fps="30"
                                      port="16161"
                                      colors="basicColors"
                                      loglevel="Info"
                                      userId="1000"
                                      groupId="1000"
                                      craftProfile="true"
                                  >
                                      <devices>
                                          <device
                                              name="RaspberryPi"
                                              boardId="1"
                                          >
                                              <element
                                                  name="P1_START"
                                  		green="4"
                                                  red="5"
                                                  blue="6"		
                                  		defaultColor="Green"
                                              />
                                          </device>
                                      </devices>
                                      <layout defaultProfile="profile_arcade">
                                          <group name="Player1">
                                              <element name="P1_START"/>
                                          </group>    
                                      </layout>
                                  </LEDSpicer>
                                  

                                  Can you see where the error is ?

                                  Btw. using "sudo ledspicer -p galaga" did not make any difference.

                                  1 Reply Last reply Reply Quote 0
                                  • MeduZaPaTM
                                    MeduZaPaT @Folly
                                    last edited by

                                    @Folly sorry, I wrote that out of my head :D

                                    Yes, I can see the error "XML_ERROR_PARSING_ELEMENT" means that P2_START does not exist :D

                                    My 1st mistake was with the run command, please run ledspicerd -p galaga, you already solved that by moving the file to the correct place.
                                    My 2nd mistake was to assume that you have a full LEDSpicer config, I added the player 2 start button, but does not exist in the conf (that is why it error out), here is the correct input file:
                                    Input file galaga.xml:

                                    <?xml version="1.0" encoding="UTF-8"?>
                                    <LEDSpicer
                                        version="1.0"
                                        type="Input"
                                        name="Mame"
                                    >
                                            <map
                                                type="Element"
                                                target="P1_START"
                                                trigger="led0"
                                                color="White"
                                                filter="Normal"
                                            />
                                    </LEDSpicer>
                                    

                                    Try that and let me know!
                                    I can help you to setup your ledspicer, do you like to chat with me on slack? I can send you an invitation to the LEDSpicer group.

                                    LEDSpicer

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

                                      @MeduZaPaT said in Syncing button leds with gameplay:

                                      I can help you to setup your ledspicer, do you like to chat with me on slack? I can send you an invitation to the LEDSpicer group.

                                      That's very nice of you. ;)
                                      I wouldn't mind but then nobody can see the progress over here.
                                      There are probably more people in the future that want to use this.
                                      With this topic they will be able to find the information more easily.
                                      Also I will be able to use the information to get using it to a higher level.
                                      Do you agree ?

                                      My 1st mistake was with the run command, please run ledspicerd -p galaga, you already solved that by moving the file to the correct place.

                                      I found that this will also work keeping galaga.xml inside /usr/share/ledspicer/profiles/arcade/ :

                                      pi@raspberrypi:~ $ ledspicerd -p arcade/galaga
                                      
                                      Default Profile:arcade/galaga
                                      * Background color: Black
                                      
                                      * Input plugins:
                                      ------------------------------
                                      Type: Mame
                                      Elements and Groups mapping:
                                      Target: P1_START
                                      Trigger: led0
                                      Color: White
                                      Filter: Normal
                                      
                                      ------------------------------
                                      

                                      So I got a working test output now.

                                      What is the next phase to get the led blink ?
                                      Do I use run mame and use "sudo ledspicerd -f" together with 'emitter LoadProfileByEmulator galaga arcade' ?
                                      Tried above but it didn't work.

                                      MeduZaPaTM 1 Reply Last reply Reply Quote 1
                                      • MeduZaPaTM
                                        MeduZaPaT @Folly
                                        last edited by MeduZaPaT

                                        @Folly I complete agree :)
                                        anything we do, should be posted here for future use.

                                        Based on your results, looks like the profile it is working fine, it passed the test
                                        I discourage running ledspicer with sudo, but is up to you :)

                                        Now we can try it on the real hardware.

                                        The next phase is to run ledspicer daemon and check if that profile is doing what it should do.

                                        • Just to be sure that ledspicer is not running, use this command:
                                        killall -15 ledspicerd
                                        
                                        • Now run ledspicerd in foreground mode, so we can check debug data and errors.
                                        ledspicerd -f
                                        
                                        • That command will launch the ledspicer service and keep the terminal busy displaying some debug data.
                                        • open Galaga with MAME, so we get the MAME output.
                                        • now open a second terminal and type this
                                        emitter LoadProfile arcade/galaga
                                        

                                        or

                                        emitter LoadProfileByEmulator galaga arcade
                                        
                                        • emitter will ask ledspicer to run the Galaga profile.
                                          At this point, you will see the P1_START element been controlled by MAME
                                        • To stop ledspicer just press CONTROL C on the terminal that is running.

                                        Let me know the results.

                                        LEDSpicer

                                        F 2 Replies Last reply Reply Quote 1
                                        • F
                                          Folly @MeduZaPaT
                                          last edited by Folly

                                          @MeduZaPaT said in Syncing button leds with gameplay:

                                          @Folly I complete agree :)
                                          anything we do, should be posted here for future use.

                                          Perfect !

                                          Based on your results, looks like the profile it is working fine, it passed the test

                                          I agree, I think it should work now.
                                          Although in my ledspicer.conf the default color is Green.
                                          Not sure how this works but in the galaga.xml we use White.
                                          Does that matter ?

                                          I discourage running ledspicer with sudo, but is up to you :)

                                          Sure, running without that should be the case.
                                          However the when using the GPIO of the raspberrypi with your program the led doesn't blink using it without sudo.
                                          Here you can find the information of that test.
                                          Perhaps I need to add the GPIO to the user pi group.
                                          Strange thing is that raspi-gpio will work without sudo
                                          Will have a look at that later.

                                          Now we can try it on the real hardware.
                                          Let me know the results.

                                          Edit :
                                          Great !!!
                                          It works ;-)
                                          Will take some time tomorrow to see If I can add some more stuff to it.

                                          Just as you said, I got it working with :

                                          sudo ledspicerd -f
                                          

                                          &

                                          emitter LoadProfile arcade/galaga
                                          
                                          or
                                          
                                          emitter LoadProfileByEmulator galaga arcade
                                          

                                          I looked again at the permissions and groups for gpio.
                                          Seems pi is part of the gpio group, also is dialout as I read that has to be in it as well to use the gpio as regular user.
                                          As raspi-gpio also works without sudo one would expect ledspicer would too.
                                          Is your check ok in LEDSpicer-development/src/devices/RaspberryPiGPIO/RaspberryPi.cpp as this throws a failed to initialized.
                                          (see that there is a typo should be failed to initialise)

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

                                            @hopwon

                                            Are you still around ?

                                            H 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.