RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Multi Switch Shutdown Script!

    Scheduled Pinned Locked Moved Ideas and Development
    shutdown scriptshutdown switchcyperghost
    272 Posts 40 Posters 117.5k 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.
    • G
      gollumer
      last edited by

      Update: I opened up the nespi+, turned the switch from ON to OFF, then back to ON, and now it's saving metadata! Seems that it wasn't completely in the ON position. Also, RESET from within an emulator now works as well. (I think the issue with that before was I was just pressing it quickly, not holding it for a second...)

      So, problem solved.

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

        @gollumer Perfect! As I said - some people like @meleu @TMNTturtlguy and me spent tons of time to elaborate a working solution! So I was pretty sure the script works!

        Annother questions:
        Do you have a fan installed in your system?
        Do you load the script per autostart.sh or via rc.local? Both versions do work but I prefer always the autostart solution.

        1 Reply Last reply Reply Quote 0
        • G
          gollumer
          last edited by

          Yes, I have a fan. I installed it on the 3.3v connector instead of 5v so that it's not as loud. I'm loading the script in autostart.sh.

          cyperghostC 1 Reply Last reply Reply Quote 1
          • C
            cloudlink
            last edited by

            I installed this script with my Nespi+ case and it works perfectly!
            I also have a fan. If I plug it into a 3.3v pin, what scripts are available to control it?

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

              @gollumer Good catch ;)
              But you have to connect it to the FAN connection position in the NESPi+ case
              Even if it's loud! Directly connected to 3,3V will affect nothing

              I assume it's not powered down even the Raspberry is shutdown.

              Therefore... can you exit ES to terminal and then write:
              raspi-gpio set 4 op dl
              This will powerdown GPIO 4 and may also shuttoff the fan!
              But please exit ES to terminal first. I don't want that you will loose data as I don't know what happens.

              If this works you can uncomment line 184 from script!
              and then NESPi+ is 100% working

                  # PowerOff LED, Poweroff PowerCtrl
                  raspi-gpio set $GPIO_lediodectrl op dl
              #    raspi-gpio set $GPIO_poweronctrl op dl #Really have no clue what it does!
              
              # Initiate Shutdown per ES
              

              @cloudlink
              Same question: I think the fan isn't powered off so it will always run.
              Maybe that's the magic of GPIO4!

              But you have to connect it to the FAN connection position in the NESPi+ case
              Even if it's loud! Directly connected to 3,3V will affect nothing

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

                @cloudlink said in Multi Switch Shutdown Script!:

                If I plug it into a 3.3v pin, what scripts are available to control it?

                Then you can use raspi-gpio to powerdown that PIN - if you use a GPIO that let's the fan run! But this is not the recommended way ;) Usually those devices are connected to 5V rail (because this delivers 2.5A!) and a GPIO controls a switch to powerdown/poweron that device. Keep in mind ... the 3.3V GPIO rail only delivers 0.10 or 0.05A! That's much enough for a few LEDs and lots of microcontrollers but maybe not enough for a fan.

                But I assume the NESPI+ fan connector itself is switchable. Because I've really NO idea why we need GPIO 4 (POWERONCTRL?)

                If you want to make the fan switchable I would recommend you:

                1. Try the connector into the case, this is maybe switchable (maybe GPIO 4 will do it's job)
                2. Try to connect your fan to 5.0V or 3.3V line (that's PIN1 = 3.3 and PIN2,4=5V) and then use a MOSFET connected to a GPIO that switches fan on or off. Therefore raspi-gpio can be used.
                1 Reply Last reply Reply Quote 0
                • G
                  gollumer
                  last edited by

                  Lol. Yeah, I originally had the fan connected to the fan connector, but recently changed it due to the noise. You're right: the fan doesn't shut down. I'm not at home right now, but when I get home I'll try the command you suggest (raspi-gpio set 4 op dl) from the terminal and see what happens.

                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • C
                    cloudlink
                    last edited by

                    My fan is connected to GPIO pin 17. Will this make it so the fan runs when the Pi is on but the fan is off when the Pi is off?

                    G 1 Reply Last reply Reply Quote 0
                    • G
                      gollumer @cloudlink
                      last edited by

                      @cloudlink said in Multi Switch Shutdown Script!:

                      My fan is connected to GPIO pin 17. Will this make it so the fan runs when the Pi is on but the fan is off when the Pi is off?

                      That's the same pin I used...pin 17.

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

                        @gollumer said in Multi Switch Shutdown Script!:

                        Lol. Yeah, I originally had the fan connected to the fan connector, but recently changed it due to the noise. You're right: the fan doesn't shut down. I'm not at home right now, but when I get home I'll try the command you suggest (raspi-gpio set 4 op dl) from the terminal and see what happens.

                        Yes, thank you. I think that's the way the GPIO is intended for.

                        @cloudlink
                        About GPIO17, of course both of you can shutoff the fan by uncommenting line 184 in my script and then edit the call in line 311

                         NESPiPlus 2 3 4 14
                        
                        to
                        
                         NESPiPlus 2 3 17 14
                        

                        But I assume GPIO 4 shutoff the fan if installed in case connector!

                        1 Reply Last reply Reply Quote 0
                        • G
                          gollumer
                          last edited by

                          Ok, I tried aspi-gpio set 4 op dl from the terminal, and nothing happened (as expected).

                          I then uncommented line 184, and edited line 311 as shown (replaced 4 with 17). I rebooted, then shutdown using the button. Shutdown is fine, but the fan is still working. So...perhaps I do need to go back to using fan connector.

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

                            @gollumer Yes I think the fan connector works with GPIO4, so please uncomment the line 184 and set the number back to 4. I think then it's possible to shutoff the fan.

                            Do you really use GPIO 17 or do you mean PIN 17 (That's a 3.3V Pin) and can't be shutoff! So this does not work at all! I would assume to the old connection provided by the case itself ;) GPIO 4 and the connector on the NESPi+ board ;)

                            G 1 Reply Last reply Reply Quote 0
                            • C
                              cloudlink
                              last edited by

                              Thank you cyperghost.
                              I connected my fan to the Nespi+ fan pins. I uncommented line 184 in /home/pi/RetroPie/scripts/multi_switch.sh. Now my fan turns on when I power on the system and my fan turns off when I power off the system.
                              I have the issue though where my fan is way too loud, spinning way too fast. Is it possible to control the power level?

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

                                @cyperghost said in Multi Switch Shutdown Script!:

                                @gollumer Yes I think the fan connector works with GPIO4, so please uncomment the line 184 and set the number back to 4. I think then it's possible to shutoff the fan.

                                Do you really use GPIO 17 or do you mean PIN 17 (That's a 3.3V Pin) and can't be shutoff! So this does not work at all! I would assume to the old connection provided by the case itself ;) GPIO 4 and the connector on the NESPi+ board ;)

                                EDIT: Ok, I see...pin 17 on the GPIO board isn't the same as GPIO 17. I'm connected to pin 17.

                                https://pinout.xyz/

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

                                  @cloudlink Okay NESPi+ is 100% supported now, thank you.
                                  About the spinning speed.... Well I would not use resistors because you will likely need some that resists to 1-2Watts. The easiest way imho is to use 1 or 2 simple Si diodes. Each drops the voltage up to 0.7V so you have 4.3V if you use one or 3.6V if you use two diodes. That's a dirty hack but will work - 1N4001 and higher are a good choice.
                                  The cleanest (cheap) way would be a step down regulator. The masters/professional way is a PWM regulator together with NTC/PTC ;)

                                  @gollumer Yes we talk about BCM numbers and physical PINs there are also wPi numbers for complete confusion! But you're right use the common pinout helpers that are free to use ;)

                                  1 Reply Last reply Reply Quote 0
                                  • G
                                    gollumer
                                    last edited by

                                    Ok, I connected the fan back to the FAN connectors, and edited line 311 back to NESPiPlus 2 3 4 14. I tried it first with line 184 still un-commented. It wouldn't shut down, but would instead go into a reboot loop. (Shut down, immediately reboot, part-way through ES loading up, it would shut down again, then reboot...and keep doing that.) I then edited line 184 and commented it out again. It now shuts down, but the fan does not turn off. Only way to turn off the fan is to unplug the power supply.

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

                                      @gollumer You can update script

                                      1. cd /home/pi/RetroPie/scripts
                                      2. rm multi_shutdown.sh
                                      3. wget https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/multi_switch.sh && chmod +x multi_switch.sh

                                      I updated to 0.42

                                      G 1 Reply Last reply Reply Quote 0
                                      • G
                                        gollumer @cyperghost
                                        last edited by

                                        @cyperghost said in Multi Switch Shutdown Script!:

                                        @gollumer You can update script

                                        1. cd /home/pi/RetroPie/scripts
                                        2. rm multi_shutdown.sh
                                        3. wget https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/multi_switch.sh && chmod +x multi_switch.sh

                                        I updated to 0.42

                                        Ok, I updated the script. Unfortunately, it now gets stuck in the reboot loop when shutting down. It gets several seconds into the video splash screen, then reboots...keeps doing that over and over until I unplug.

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

                                          @gollumer That's weird becasue @cloudlink reports good results.
                                          Then please comment line 183, then the same version is restored.

                                          This is caused as you leave the LOOP caused by a button press. But don't know why ... can you recheck the ON/OFF position of the switch. Can you shot some photos from you setup?

                                          Then later you can use the raspi-gpio command raspi-gpio set 4 op dl manuell then you immedialty should loose power. And more weird becasue you said you typed the command raspi-gpio command later and nothing happens... But again: weird becasue cloudlink got good results. I can help you to shut off then fan with a workaround but let us eloborate this first.

                                          1 Reply Last reply Reply Quote 0
                                          • C
                                            cloudlink
                                            last edited by

                                            Mine is working perfectly.
                                            If I have an emulator running and I hit Reset, it only exits the emulator. If I have no emulator running and I hit Reset, it restarts Emulationstation.
                                            If it is off and I press the Power button, it powers on. If it is on and I press the Power button, it safely saves metadata and shuts down.

                                            I have noticed though that if I press and release the Reset button too quickly, it does not work. Is there a configured amount of time it must be held?

                                            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.