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

    Powering off via UI while using a Mausberry Circuit

    Scheduled Pinned Locked Moved Help and Support
    mausberrypower offcircuitmenuled
    72 Posts 4 Posters 19.6k 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.
    • cyperghostC
      cyperghost
      last edited by cyperghost

      @caver01

      With that possibility in mind, and recognizing that I am a bit of a GPIO novice, is there a way to force the signal on the GPIO pin itself so that the MB circuit hardware really DOES detect something? This would get picked up by the script too.

      You send a trigger to the MB script! Every second the MB checks the state of the GPIO! So I would extend the sleep timer in the script posted above to at least 2 seconds.

      Type:
      nano /opt/retropie/supplementary/emulationstation/emulationstation.sh
      and just add this one line between the if-then-by es-shutdown clause

      sudo echo "1" > /sys/class/gpio/gpio$GPIOpin1/value && sleep 3
      

      Please definate $GPIOpin1 value! I can't see it as my glass globe is broken now. The modified MB-script checks existance of ES-running and some emulators and then exits and gives command back to the original ES-shutdown script. As there is no emulator running and ES is already shutting down the MB script will take command back to ES and ES ends as usual but the GPIOPin from MB is changed!

      It will still keep the MB circuit itself in limbo and the Pi will be off/asleep, but not completely powered off. In other words, I am predicting no change.

      No - I'm pretty sure it works - maybe not by this attempt but in general it should ;)

      caver01C 1 Reply Last reply Reply Quote 0
      • caver01C
        caver01 @cyperghost
        last edited by caver01

        @cyperghost said in Powering off via UI while using a Mausberry Circuit:

        Please definate $GPIOpin1 value!

        Sorry, I don't know what this means.

        Thanks for the added explanation. I understand how the updated Mausberry script works. It's so great that it looks for emulator PIDs now and does a graceful shutdown.

        My point was that if all we are changing is the value of a variable defined by the script--and not an actual pin voltage-- I wonder how the outcome would be any different--as it still leads to a sudo poweroff.

        But, if changing that variable also triggers a voltage change on the GPIO PIN itself, we are probably good to go.

        What I suspect happens when the physical button is used is more than just falling out of the sleep loop. I may be mistaken, but the mausberry hardware is actually cutting power to the Pi and going into a dormant state itself--something it doesn't seem to do if I just trigger a software shutdown. That makes me think the circuit is doing something in hardware when it detects a voltage change on the pin it is monitoring IN ADDITION to our script getting triggered. Even the LED stays brightly lit from the Mausberry circuit. It "thinks" the Pi is still running. We need to send the signal to the circuit to trick it into thinking the button has been pressed.

        In any case, I won't be able to test this until I get home in 5-6 hours.

        My 4-player cocktail style cabinet built as a custom "roadcase"

        cyperghostC 1 Reply Last reply Reply Quote 0
        • cyperghostC
          cyperghost @caver01
          last edited by

          @caver01 Well it could be that the switch triggers some hardware thing to the mausberry. But keep in mind

          with echo 1 the GPIO sends 3,3V to the mausberry
          with echo 0 the GPIO sends 0,0V to ther mausberry

          You can connect a simple LED to a GPIO and ground directly and just send 1 to let the LED glow and send 0 to switch it off ;)
          I'm pretty sure it works....

          In theory there is no difference if you press the button to send the 1 to the Pie or do it via software and tell the GPIO - set to 1 now ;)
          Maybe you're right and the hardware button does something with the mausberry but as far as I understood the mausberry works with permanent and momentary switches ;) So it just triggers the GPIO ....

          caver01C 1 Reply Last reply Reply Quote 0
          • caver01C
            caver01 @cyperghost
            last edited by

            @cyperghost said in Powering off via UI while using a Mausberry Circuit:

            ATTENTION! Definate correct GPIOPin!

            Are you saying we should adjust the line as it applies to our setup--so if we used pin 23 for the for GPIOpin1 as suggested by Mausberry, the line should be:

            sudo echo "1" > /sys/class/gpio/gpio$GPIOpin23/value && sleep 3 #<-- very likely here

            My 4-player cocktail style cabinet built as a custom "roadcase"

            1 Reply Last reply Reply Quote 0
            • cyperghostC
              cyperghost
              last edited by

              No!
              sudo echo "1" > /sys/class/gpio/gpio23/value && sleep 3

              caver01C 1 Reply Last reply Reply Quote 0
              • caver01C
                caver01 @cyperghost
                last edited by

                @cyperghost Ok, so setting this value really does affect the pin voltage. That's was my hope, fearing that it might just be a script variable.

                My 4-player cocktail style cabinet built as a custom "roadcase"

                cyperghostC 1 Reply Last reply Reply Quote 0
                • cyperghostC
                  cyperghost @caver01
                  last edited by

                  @caver01 You can just test without altering any script. Quit ES and type in terminal the command above. Maybe the sudo command is not needed :) (I doubt it but let us find out)

                  caver01C 3 Replies Last reply Reply Quote 0
                  • caver01C
                    caver01 @cyperghost
                    last edited by

                    @cyperghost said in Powering off via UI while using a Mausberry Circuit:

                    No!
                    sudo echo "1" > /sys/class/gpio/gpio23/value && sleep 3

                    Hahaha. Gotcha. Ok. I will give this a try later. Thanks so much, and especially for your patience. You were way ahead of me, going straight for the pin itself.

                    If this works, as I now suspect it will, you just closed the last little loop as I can see with using this circuit on a RetroPie setup. Thanks in advance!

                    @madmodder123 I hope you are following along and can try this too. I think we were having the same issue (actually, everyone who uses a MB circuit can benefit).

                    My 4-player cocktail style cabinet built as a custom "roadcase"

                    1 Reply Last reply Reply Quote 0
                    • caver01C
                      caver01 @cyperghost
                      last edited by

                      @cyperghost said in Powering off via UI while using a Mausberry Circuit:

                      @caver01 You can just test without altering any script. Quit ES and type in terminal the command above. Maybe the sudo command is not needed :) (I doubt it but let us find out)

                      Good idea. Consider that my first test. I will report back later.

                      My 4-player cocktail style cabinet built as a custom "roadcase"

                      1 Reply Last reply Reply Quote 0
                      • caver01C
                        caver01 @cyperghost
                        last edited by

                        @cyperghost I tried the command at CLI. got an error:
                        echo: write error: Operation not permitted

                        My 4-player cocktail style cabinet built as a custom "roadcase"

                        1 Reply Last reply Reply Quote 0
                        • caver01C
                          caver01 @cyperghost
                          last edited by

                          @cyperghost after a little reading I tried something else:
                          First, I considered the fact that pin 23 is exported and set to input. That may have been preventing me from setting the value, so I tried changing it to output with:
                          sudo echo "out" > /sys/class/gpio/gpio23/direction
                          then I tried setting the value to 1 with
                          sudo echo "1" > /sys/class/gpio/gpio23/value
                          this immediately triggered the shutdown. However, the LED wired to the mausberry is still lit, the Pi is sleeping but power still on. And in this state, the power switch is non-functional, as if the MB circuit still thinks the Pi is on, like it has not seen a button press.

                          It strikes me that the power button is wired to the MB circuit, not to a GPIO pin. The MB circuit is wired to pins 23 INPUT and 24 output. So, the button tells the circuit to shutdown and the circuit triggers the input on pin 23 which kicks off the script. I honestly don't know what pin 24 is doing. I expect the MB is monitoring this pin, so when the power goes out, it sees that the pin is no longer set to "1", but it appears that the circuit does not bother to look at 24 unless it has received a button press from the wired button.

                          I am starting to think I need a transistor in this equation, or that the MB circuit is not as versatile as I wish it was. It should detect if the pi is shutdown, not just when the button gets used.

                          My 4-player cocktail style cabinet built as a custom "roadcase"

                          cyperghostC 1 Reply Last reply Reply Quote 0
                          • cyperghostC
                            cyperghost
                            last edited by cyperghost

                            @caver01
                            I See .... That is because the switch is labeled as input.
                            So there is no chance to with an simple echo AS it expects an input. I will report in a few hours ...
                            I have a small test circuit available at home. One LED connected with a button.

                            1 Reply Last reply Reply Quote 0
                            • cyperghostC
                              cyperghost @caver01
                              last edited by cyperghost

                              @caver01 I was on the wrong track - sorry!
                              But there is an solution... you need a Solid State Relais like this and connect the output in parallel direction to your switch. So you can use the switch or the SSR...

                              The innput for the SSR is annother GPIO in ouput direction... if you set now echo 1 command in this GPIO direction.. LED inside the relais will glow and switch is closed.

                              So you have 2 switches ... the physical and one software remoted. I have some of these bought cost 1$ each and work fine.

                              @caver01 What happens if you change direction to the second GPIO?

                              caver01C 1 Reply Last reply Reply Quote 0
                              • caver01C
                                caver01 @cyperghost
                                last edited by caver01

                                @cyperghost

                                What happens if you change direction to the second GPIO?

                                If we change direction on pin 24, I can’t write to it. I tried change the value too and it does nothing.

                                I think I will look into the relay option. Do I need any other components such as resistors connected anywhere? I don’t think I have ever hooked up a relay before.

                                My 4-player cocktail style cabinet built as a custom "roadcase"

                                cyperghostC 1 Reply Last reply Reply Quote 0
                                • cyperghostC
                                  cyperghost @caver01
                                  last edited by cyperghost

                                  @caver01 I'll be back ;)

                                  I tried change the value too and it does nothing.

                                  I can't get this... Was there an error message? So can you please test if you change status uf $GPIOpin2 with sudo command
                                  sudo echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
                                  It is setted to 1 what happens if it is setted to 0?

                                  I don't get what the purpose. It seems like a check state... for, is the Pie is running!
                                  As the mausberry contains a AVR µc I can't get it why the developer sends voltage output and does not wait for receiving a signal?

                                  As you mentioned:

                                  is there a way to force the signal on the GPIO pin itself so that the MB circuit hardware really DOES detect something? This would get picked up by the script too.

                                  and I said:

                                  Maybe you're right and the hardware button does something with the mausberry but as far as I understood the mausberry works with permanent and momentary switches

                                  the mausberry sends a high signal to the Pie..... sadly!

                                  I tested with a switch and LED and I was able to trigger the switch by change input to output direction. But as the MB sends the signal.... it won't work like that.


                                  About the opto-mosfet... yes you will need a resistor to not damage the build in LED. For 3.3 V I used 330 Ohm. But those values are in the data sheet delivered with the IC. I think that will be the nicest way to get the mausberry full working and you need just to plug one more GPIO. And this device acts as a switch... I think the resistance is just 1 Ohm... that's a very bad value for a "switch" but it will surly work.

                                  caver01C 1 Reply Last reply Reply Quote 0
                                  • caver01C
                                    caver01 @cyperghost
                                    last edited by

                                    @cyperghost
                                    If I set the gpio2 (actually, it's wired to 24) to "0" it does nothing.

                                    That pin gets set to "1" in the script, so it must be for monitoring. When the Pi finishes the soft shutdown, the pin will drop, and the MB circuit should see that, right? But my thinking is that the MB circuit doesn't check GPIO2 for drop to "0" until AFTER it detects a button press. Because, if it DID check all the time, it would immediately cut power before the script gets executed that sets it to "1"!

                                    My 4-player cocktail style cabinet built as a custom "roadcase"

                                    cyperghostC 1 Reply Last reply Reply Quote 1
                                    • cyperghostC
                                      cyperghost @caver01
                                      last edited by cyperghost

                                      @caver01 Yes this behaviour sounds logical.
                                      Man... it could be so easy but I think the SSR is also a good catch. I use one to activate and deactivate the monitor from LCD by switching on/off the video input via GPIO. So in fact it is just the same approach as to toggle a LED on/off.

                                      1 Reply Last reply Reply Quote 0
                                      • caver01C
                                        caver01
                                        last edited by

                                        It's hard to blame the design--if all you ever do is use the power button, it's fine. But if you do a soft shutdown without using the button, it seems as though the mausberry has no way to detect that, and it sits in a powered state.

                                        My 4-player cocktail style cabinet built as a custom "roadcase"

                                        cyperghostC caver01C 2 Replies Last reply Reply Quote 1
                                        • cyperghostC
                                          cyperghost @caver01
                                          last edited by cyperghost

                                          @caver01 We will change this via SSR-GPIO software switch ;)

                                          caver01C 1 Reply Last reply Reply Quote 0
                                          • caver01C
                                            caver01 @caver01
                                            last edited by caver01

                                            What I need is a normally open switch that closes when power gets cut. If I wired that in parallel with the power button, it will trigger when the Pi shuts down without any need for a GPIO command to be sent.

                                            <EDIT> ha ha I just read the first sentence on the link to the SSR. Says it is a normally open switch. . . I may have to pick one up.

                                            My 4-player cocktail style cabinet built as a custom "roadcase"

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