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

    [Tutorial] OnOff SHIM exposed - neat Powerswitch from Pimoroni

    Scheduled Pinned Locked Moved Ideas and Development
    cyperghostpimoronishimpowerswitchonoff
    26 Posts 7 Posters 24.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.
    • caver01C
      caver01 @cyperghost
      last edited by

      @cyperghost Interesting. Well, I finally picked up a Nespi case, so I am going to start doing mods to it over the next few days to get my mausberry connected. It looks like I have some choices to make.

      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

        @caver01 Well the Mausberry Switch is also a good choice imho ... the SHIM is just extremly cheap in priece. Good luck with your build and make some photos ;)

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

          The SHIM is available again ;)
          https://shop.pimoroni.de/products/onoff-shim

          But it's now 7 GBP!

          1 Reply Last reply Reply Quote 0
          • NecsusN
            Necsus
            last edited by

            @cyperghost First of all thks for the Tutorial.

            But it doesn't work fine for me ...

            • The gpio-shutoffscript doesn't run when the Pi turns off ... (I make the script executable with sudo chmod +x /lib/systemd/system-shutdown/gpio-shutoff command line but it's still not working)

            • The switch.sh script is not running at the start ... However, I add line sudo /home/pi/RetroPie/scripts/switch.sh & to /opt/retropie/configs/all/autostart.sh and to /opt/retropie/configs/autostart.sh scripts and it's not runnig. But if I use sudo /home/pi/RetroPie/scripts/switch.sh in the terminal and test the switch, it's working ...

            Thanks for helping.

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

              @necsus I tried this on two builds. On a Raspberry 2 and a Raspberry 3 RPi0, both with Jessie image. The call to gpio-shutoff is hidden and you won't see a message. Can you check your wiring? The LED should blink 3 times but only if you wired it to PIN 1 (3,3V)

              So what happens if the Pie is shutdown? Can you repower it by pressing the switch button?

              It's definitly /opt/retropie/configs/all/autostart.sh - thank you

              It looks like

              sudo /home/pi/RetroPie/scripts/switch.sh &
              mpg123 -Z /media/usb0/BGM/*.mp3 >/dev/null 2>&1 &
              emulationstation #auto
              

              So the switch-script must be executed BEFORE emulationstation call!
              I wasn't exact in this point - sorry!

              I've no clue why this does not work in your case ;) Give more information about your system - I think you are on a wrong system as the shutoff script is a rip of the original script from pimoroni.

              1 Reply Last reply Reply Quote 0
              • NecsusN
                Necsus
                last edited by Necsus

                @cyperghost Thks for your quick response !

                I have a Raspberry Pi 3 with the Pre-made image RetroPie v4.3.

                The modification of the autostart.sh script works fine !

                But when the Pie is shutdown I can't repower it by pressing the button ... The Red Power LED from the Pie and my switch LED (wired on the PIN 1) remain ON ...

                I have check my wiring, and it's ok !
                But I've find a new problem, in the folder /lib/systemd/system-shutdown/ I have 2 scripts : gpio-shutoff.saveand gpio-shutoff.sh. I've test to delete with rm or modify the script but I get the following message error : "Permission denied"

                Did I do something wrong ?

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

                  @necsus use sudo rm /lib/systemd/system-shutdown/gpio-shutoff.save

                  and remove the .sh file, too

                  then create the file exactly as I wrote in the tutorial .... WITHOUT .sh just gpio-shutoff and make it executable ;) ... that should do the trick. Seems your script wasn't made executable because of the extension.

                  1 Reply Last reply Reply Quote 0
                  • NecsusN
                    Necsus
                    last edited by

                    @cyperghost Thks for the help, I succeeded to delete the two files, create the gpio-shutoff script (I make it executable with sudo chmod +x ;) ).

                    But it's still not working, I think the PCB has a problem. I will test if the script run by putting a LED on the GPIO 17 when the Pie shutoff.

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

                      @necsus Well... that's weird!

                      Try to install the official from Pimoroni

                      type curl https://get.pimoroni.com/onoffshim | bash

                      But I really don't know why this is not working for you... see here
                      But seems you are not alone ... from runeaudio.com - I think I will dig deeper in this!
                      Hell! There is something going wrong here .... See the official Pimoroni-board - the guy is reporting the same as you! I will make a test on the new Stretch image - keep you updated. That's really strange now!

                      1 Reply Last reply Reply Quote 0
                      • NecsusN
                        Necsus
                        last edited by Necsus

                        @cyperghost It's very strange, because I install Raspbian Stretch Lite Kernel version: 4.9 on my pi zero w, and use curl https://get.pimoroni.com/onoffshim | bashcommand and it works ...
                        I buy 5 OnOff Shim board at the same time on Pimoroni.
                        Do you think the OnOff Shim board use on my Rpi 3 has a problem ?

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

                          SOLVED! Proceed with Tutorial as descriped!

                          1 Reply Last reply Reply Quote 0
                          • NecsusN
                            Necsus
                            last edited by

                            @cyperghost Ok that's very strange ! And thanks for the explaination.
                            I will do a test on the Pi3 with Raspbian OS on a new SD card, if it's working.

                            Which OS can I test to help us understanding the problem ?

                            mituM 1 Reply Last reply Reply Quote 0
                            • mituM
                              mitu Global Moderator @Necsus
                              last edited by mitu

                              @necsus The RetroPie image is built on top of Raspbian, so you could keep using Raspbian to test things.

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

                                @mitu Yes that's right! Raspbian would be the first choice.
                                The reason why I ripped this out of the PIMORONI SHIM service is, that the installer will likely not work on systems like RECALBOX, LibreELEC or OSMC.

                                But the two bash files and the explaination to setup them would likely work. I think I can test just on weekend so I would be glad if someone else could take over.

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

                                  @mitu @Necsus

                                  Updated scripts... It will now work! Thanks for your support!
                                  This will now work on RPi0/1, RPi2/3

                                  Tested also with Raspbian light Stretch on 4.9 Kernel! Works fine, too :D

                                  1 Reply Last reply Reply Quote 0
                                  • K
                                    Kzar
                                    last edited by

                                    For whomever stumbles upon this topic trying to customize the On-Off Shim, please note that not all GPIO PINs are usable for this circuit.

                                    This is an undocumented bug, which is quite important to know if you try to change the default pins on which the board is connected.

                                    In fact, for the "poweroff pin", which is by default on GPIO 4, only GPIO pins from 0 to 8 can be used. If you use pins over 9, the raspberry will never turn on.

                                    This is because the OnOff Shim relies (undocumented) on the "poweroff_pin" being "ON" all the time, since startup.

                                    As documented on https://elinux.org/RPi_BCM2835_GPIOs the pins 0-8 are by default "pulled HIGH", while all the other pins are "pulled LOW".

                                    There is no problem for the other pin "trigger" (or "status" as it is labeled on the circuit), which can be moved to any other GPIO pin.

                                    Personally, I moved them to pins GPIO 6 (physical 31) and GPIO 16 (physical 36) so they do not interfere with any other attached circuit.

                                    It took me a couple of hours to figure this out, I hope this could be of help to someone else.

                                    M 1 Reply Last reply Reply Quote 0
                                    • M
                                      muze @Kzar
                                      last edited by

                                      @kzar said in [Tutorial] OnOff SHIM exposed - neat Powerswitch from Pimoroni:

                                      For whomever stumbles upon this topic trying to customize the On-Off Shim, please note that not all GPIO PINs are usable for this circuit.

                                      This is an undocumented bug, which is quite important to know if you try to change the default pins on which the board is connected.

                                      In fact, for the "poweroff pin", which is by default on GPIO 4, only GPIO pins from 0 to 8 can be used. If you use pins over 9, the raspberry will never turn on.

                                      This is because the OnOff Shim relies (undocumented) on the "poweroff_pin" being "ON" all the time, since startup.

                                      As documented on https://elinux.org/RPi_BCM2835_GPIOs the pins 0-8 are by default "pulled HIGH", while all the other pins are "pulled LOW".

                                      There is no problem for the other pin "trigger" (or "status" as it is labeled on the circuit), which can be moved to any other GPIO pin.

                                      Personally, I moved them to pins GPIO 6 (physical 31) and GPIO 16 (physical 36) so they do not interfere with any other attached circuit.

                                      It took me a couple of hours to figure this out, I hope this could be of help to someone else.

                                      Kzar, would you know or quickly be able to see if the very oldest pi (the A, not A+) would be able to work with the on-off shim? The pinout for the 26 Pi looks very similar for pin 1-12, including GPIO4 but I am not an expert and Pimoroni only mentions they are compatible with 40 pin Pis? But from the pinout I do not understand why. Just checking as I have a pi-hole running great on this old Pi, but an on-off button would be amazing.

                                      Many thanks for any thoughts on this.

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

                                        @muze I have the shim running on a 1st generation Pi B 256Mb. Runs flawless even with 26 pin header.

                                        And yes Pihole rules 😋😍

                                        cnotoC 1 Reply Last reply Reply Quote 1
                                        • cnotoC
                                          cnoto @cyperghost
                                          last edited by

                                          @cyperghost Do I need to modify your script if I am using a non momentary button? Right now, I followed your script and instructions press the button in the off position the pi shuts off immediately.

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

                                            @cnoto The script in this posting does not need to be modified it supports both kind of switches
                                            Momentary buttons and latching ones

                                            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.