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

    Nespi+ case - turn off fan by using emulationstation software shutdown?

    Scheduled Pinned Locked Moved Help and Support
    nespi+ emulatioemulationstatiomultiswitch.shsafe shutdown
    15 Posts 3 Posters 2.2k 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.
    • T
      theretroprince
      last edited by

      Pi Model 3 B+
      RetroFlag Nespi+ Case
      Power Supply used: Northprada 5v 3amp
      Stretch running RetroPie 4.4
      Built From: retropie-4.4-rpi2_rpi3 distribution
      USB Devices connected: Rii Wireless keyboard, Seagate 2TB external USB drive
      Controller used: XBOX One Bluetooth Model 1708 (Firmware 3.1.1221.0)
      Joystick Driver: Xpadneo

      Hi all. I'm currently using a Nespi+ case for my 3B+. Inside the case, I have the toggle set to allow safe shutdown. I have enabled the multi_switch.sh method posted by the amazing cyperghost in topic 17639, and the buttons on the hood of my Nespi+ work great. Fan deactivation on safe shutdown and reset all work great with the case buttons. shutdown_fan script is also in the /lib/systemd/system-shutdown directory. (The fan power is attached to the fan board PCB in the Nespi+ case, not directly to the GPIO)

      The only difference in my configuration is that I've moved the multi_switch.sh file out of home/pi/RetroPie/scripts to the SD card due to permissions issues (path adjusted in autostart.sh) with retropie-mount on an external USB drive. Not a big deal, I don't think. Like I said, it works great!

      But I am curious if it is possible to have the emulationstation software shutdown path terminate the fan as well. When I execute a shutdown internally from EmulationStation (Quit- Shutdown System), the Pi shuts down, but the fan stays running. The buttons on the case work awesome, but I think it would be more awesome if you could fully terminate the Pi's fan through software as well. (Kind of like how you can fully turn off a current gen console from software/joystick) I thought maybe you could use "./multi_switch.sh --es-systemd" but that seems to only take me back to the CLI. But even if that worked, where exactly would that go?

      It is entirely possible that this is supposed to work, and I messed something up too! But I looked all over and just couldn't seem to find a solution. I just think it would be really neat to relax after a tough day at work, sit down to enjoy some Pi, and not having to worry about getting out of my chair to hit the power button on the Pi once I'm done just because the fan stays running. Bluetooth controllers make you really lazy! If it's not possible, it's not a huge deal. But I thought I'd ask nonetheless. Thanks for looking and have a great day!

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

        @theretroprince Nice you like the shutdown script.
        I've a few questions... Did you you have installed raspi-gpio with sudo apt install raspi-gpio at first?
        The systemd-parameter is useless as long as @meleu won't work on the general shutdown anymore :(

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

          @theretroprince Otherwise you can try this script instead. Place this to same location this to /lib/systemd/system-shutdown and make the script executable. The name does not matter ;)

          #!/bin/sh
          #
          # OnOff SHIM exposed by cyperghost for retropie.org.uk
          # This is mandatory for proper SHIM shutdown!
          
          	
          poweroff_pin="4"	
          led_pin="14"	
          	
          if [ "$1" = "poweroff" ]; then	
          	
              /bin/echo $led_pin > /sys/class/gpio/export	
              /bin/echo out > /sys/class/gpio/gpio$led_pin/direction	
          	
                  for iteration in 1 2 3; do	
                      /bin/echo 0 > /sys/class/gpio/gpio$led_pin/value	
                      /bin/sleep 0.2	
                      /bin/echo 1 > /sys/class/gpio/gpio$led_pin/value	
                      /bin/sleep 0.2	
                 done	
          	
              /bin/echo $poweroff_pin > /sys/class/gpio/export	
              /bin/echo out > /sys/class/gpio/gpio$poweroff_pin/direction	
              /bin/echo 0 > /sys/class/gpio/gpio$poweroff_pin/value
          fi
          
          cyperghostC 1 Reply Last reply Reply Quote 0
          • cyperghostC
            cyperghost @cyperghost
            last edited by

            Sorry for third posting....
            You've always to press the power button to make a complete shutdown afaik :(
            But you can modify the switch to make it work like the reset button. Just remove the small metal-sheet, this will convert the latching switch to a momentary one.

            T 1 Reply Last reply Reply Quote 0
            • T
              theretroprince @cyperghost
              last edited by

              @cyperghost Hi Cyperghost. Thank you for responding. I also want to personally thank you for the great work on your shutdown script. It works perfectly, as do the behaviors of my buttons on my case. When I press my power button, it shuts down nicely, and then terminates power to the fan. It does everything just like it should. Everyone with a Nespi+ case owes you lunch! I don't think my question relates to any of your code, necessarily. But, in response to your questions:

              Yes, I have installed raspi-gpio (version 0.2.0.171123) and placed your script in system-shutdown. (along with the script "shutdown_fan")

              My question was really "Is it possible to completely terminate power to both the Pi and the fan without pressing the button power, but rather only by using the Quit-Shutdown System option from within EmulationStation".

              When I execute shutdown from the EmulationStation menu, Power is turned off for the Pi, but the fan keeps running. The "shutdown_fan" script in systemd doesn't seem to do anything with this type of shutdown.

              As you said, @meleu is no longer working on the general shutdown anymore, so I may just be out of luck. I could probably figure out a way to do it if I could only create a way to shut the fan down with a command line script, but it's a little out of scope of my understanding at this point.

              I thought that your shutdown_fan script in "/lib/systemd/system-shutdown" would do the trick and turn the fan off with "[[ $1 == "poweroff" ]] && raspi-gpio set 4 op pn dl" but that doesn't seem to work, and executing this script from a command line produces the error: ./shutdown_fan: 12 ./shutdown_fan: [[: not found".

              And running "raspi-gpio set 4 op pn dl" from the command line seems to execute, but the fan still remains on.

              And I apologize in advance if this cannot be done, or I've made a mistake somewhere. I'm still an intermediate user learning new stuff everyday. Any ideas?

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

                @theretroprince said in Nespi+ case - turn off fan by using emulationstation software shutdown?:

                My question was really "Is it possible to completely terminate power to both the Pi and the fan without pressing the button power, but rather only by using the Quit-Shutdown System option from within EmulationStation".

                Yes it is possible but you have to modify the script and you have to modify the switch. If you press the power switch and keep it in on position, then a kind of "electric relais" (MOSFET) is activated, too (this is GPIO pin 4). So for proper shutdown you set power switch to off position and then in last shutdown sequence the shutdown_fan script is called and sets GPIO 4 to 0 . Thus deactivates the MOSFET and completly cuts of power and the fan shuts also down.

                Otherwise: you make a shutdown via menu only. This is the same procedure as writing sudo poweroff in terminal. This will also call GPIO 4 and set it to 0 but the power switch remains in ON position and this will fail to cut off power.

                So what to do? Use the same procedure as I made in line 504 for the PIMORONI ON OFF SHIM. I check in what state the switch is. it would get called power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT") If it's a momentary the power=0, if it's a latching then power=1. Then I make the loop until [[ $power == $switchtype ]] but you have to modify the switch for this, that it works like the reset switch.
                PS: Never tested this, so it's pure suggestion

                I thought that your shutdown_fan script in "/lib/systemd/system-shutdown" would do the trick and turn the fan off with "[[ $1 == "poweroff" ]] && raspi-gpio set 4 op pn dl" but that doesn't seem to work, and executing this script from a command line produces the error: ./shutdown_fan: 12 ./shutdown_fan: [[: not found".

                No this won't work. The systemd service parses arguments to any script. If you just call the script there is no $1 argument so the code [[ == "poweroff" ]] is an error. You should call the script with sudo /lib/systemd/system-shutdown/shutdown_fan poweroff` then it will work.

                Everyone with a Nespi+ case owes you lunch!

                I love good food ;)

                T 1 Reply Last reply Reply Quote 0
                • T
                  theretroprince @cyperghost
                  last edited by

                  @cyperghost Ohhhh, thanks for bearing with me. I'm just beginning to understand. Your first option is probably not what I'm looking for, but you're educating me!

                  For the second option (sudo /lib/systemd/system-shutdown/shutdown_fan poweroff), if I pass the "poweroff" variable to the script, shouldn't that still disable fan power even without the modifications to the power button?

                  I tried to run it: "sudo /lib/systemd/system-shutdown/shutdown_fan poweroff", but it still outputs an "error 12: [[: not found".

                  Or would the button modification still be required to complete the argument?

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

                    @theretroprince said in Nespi+ case - turn off fan by using emulationstation software shutdown?:

                    shouldn't that still disable fan power even without the modifications to the power button?

                    No. The commands should shut the whole current down. You can't select for fan only.

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      theretroprince @cyperghost
                      last edited by

                      @cyperghost That would be perfectly fine if it shut the whole system down. But I wonder why my script is not working? Any ideas?

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

                        Well you can try following

                        First you disable the multi_switch script with pkill -f multi_switch.sh
                        Then release power button - the system should not powerdown because you've disabled trigger script
                        Then run raspi-gpio set 4 op pn dl - this should cause a sudden power off

                        Please update your script! I used bashism for shell script
                        [ "$1" = "poweroff" ] && raspi-gpio set 4 op pn dl is correct

                        1 Reply Last reply Reply Quote 0
                        • meleuM
                          meleu
                          last edited by

                          hey, I saw some pings! 🏓

                          I came here for a quick visit and maybe I won't find the time to catch up...
                          is there something I can do to help?
                          help me to help you guys! 😅

                          • Useful topics
                          • joystick-selection tool
                          • rpie-art tool
                          • achievements I made
                          T 1 Reply Last reply Reply Quote 1
                          • T
                            theretroprince @meleu
                            last edited by

                            @meleu Hi Meleu! Thanks for replying.

                            I was just looking at possibilities for shutdown options with a Nespi+ case, and Cyperghost was educating me on his scripts and their interaction with this specific case.

                            What I was looking into was the ability to maintain the functionality of the power button on the Nespi+ with the scripts. (Safe shutdown, cut case power/ turn off fan), but also have the ability to perform the same functionality through the "Quit - Shutdown" option within EmulationStation.

                            Quit-Shutdown through ES shuts the system down, but does not disable the Nespi+ case power, specifically the fan. I was thinking that having both options would be nice, so you could still have the power button on the Case use a safe shutdown/cut power, but also be able to do the same through EmulationStation, similar to how you could turn off a current-gen console via the controller. (Without having to get my lazy behind off the couch! :-) I'm not sure we found a solution, but I got some learnin' nonetheless! And I really appreciate it!

                            meleuM 1 Reply Last reply Reply Quote 0
                            • meleuM
                              meleu @theretroprince
                              last edited by

                              @theretroprince oh, now I got what you want. And I'm afraid it's not possible :(
                              I can't think on something more "shutdownish" then sudo powerof (which is what happens when you shutdown system via emulationstation menu).

                              • Useful topics
                              • joystick-selection tool
                              • rpie-art tool
                              • achievements I made
                              cyperghostC 1 Reply Last reply Reply Quote 1
                              • cyperghostC
                                cyperghost @meleu
                                last edited by cyperghost

                                @meleu It is not possible because the power switch is always in "on" position. So the GPIO for cutting power is triggered correctly but the power switch has to be pressed always manually (as long it is a latching one ... you can modify this one to be a momentary switch)

                                @theretroprince can make a proof of concept I have written here. This should work ;)

                                1 Reply Last reply Reply Quote 0
                                • T
                                  theretroprince
                                  last edited by

                                  Thank you @meleu and @cyperghost

                                  I may end up ordering another Nespi+ case to attempt the button modification. If I do, I'll certainly come back and provide an update!

                                  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.