Momentary On/Off Switch with soft shutdown

Raspberry Pi related support

Re: Momentary Contact Switch

Postby ingohz » 14 Apr 2016, 20:13

ingohz
 
Posts: 45
Joined: 22 Feb 2016, 12:11

Re: Momentary Contact Switch

Postby PeteB » 14 Apr 2016, 20:47

PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Momentary Contact Switch

Postby SimonDechain » 14 Apr 2016, 21:42

Hello,
You should be careful with the "RUN" header. It is a reset input, if you toggle it while the RPI is running, you will reset it and that is not healthy (it could corrupt the sd-card).

If you want to have a soft-power on button without the reset danger, you could use GPIO3 (Pin 5 on the header). When shorted against ground, the pi will start booting. it was previously used as a safe-boot input, but that part of the firmware was removed. Some infos about the pin can be found here: http://elinux.org/RPI_safe_mode#Wake_from_Halt.5B1.5D

The disadvantage is, that the pin can not be used for something else (for example as the I2C interface).


edit:
I also implemented the same functionality (shutdown through a spst toggle button) abeit a bit differently. In my case I created a device tree overlay (gpio-keys), which registered the button as an input and triggered the "Shutdown key" from Linux. Only thing is, that you are not able to call the rune shutdown script directly. I'm still working on that, currently by trying to register a shutdown service.

If you want, I can share the dts file tomorrow evening, it is already late here in Austria.
SimonDechain
 
Posts: 7
Joined: 12 Mar 2016, 19:19

Re: Momentary Contact Switch

Postby PeteB » 14 Apr 2016, 23:20

Hi Simon,

If you'd care to share then yes, please post your code. :)

Unfortunately my HiFiBerry DAC+ uses I2C, and so to some LCD's that other people here are using. So, yes, that would be ideal, but not everyone can make use of it.

I guess that the start circuit would have to be wired so it could NOT operate and cause a reset when the soft shutdown script is active. That should be possible because the pin used for shutdown is pulled high after start, and stays high until about three seconds after the button is pressed, and presumably released.

However, it may not be worth the effort to do that just for a soft start... :(
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Momentary Contact Switch

Postby SimonDechain » 15 Apr 2016, 22:49

Attachments
OR.png
OR.png (9.76 KiB) Viewed 3993 times
SimonDechain
 
Posts: 7
Joined: 12 Mar 2016, 19:19

Re: Momentary Contact Switch

Postby PeteB » 16 Apr 2016, 00:50

Simon:

Thanks for sharing, I will look at the code more closely this weekend. I really have no preference, but your method is interesting, and worth investigating.

As for soldering parts, as long as I can still see them without a microscope, I can probably solder them.

I started this thread to see if we could have a simple switch that activates a soft "off" function after reading about Rikardo's experience with the Audiophonics kit. There are lots of examples in the Raspberry forum and elsewhere, but they are all for Raspbian and Debian-based systems.

Soft start/reset:

If the reset pin is used only as a soft start after a shutdown, then a switch can be enabled through software, using a second pin. For example, only after the rune_shutdown call, and before systemctl shutdown.

This way, a single double-pole momentary switch can be used for both functions, and you enable one or the other in software. If that does not work, one can always pull the plug, which is what most people do now.

Thoughts?
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Momentary Contact Switch

Postby SimonDechain » 20 Apr 2016, 17:58

Ah, okay. If I've understood you correctly, you want to cut power to the pi after it powered down. At least, that's what the mousberry is doing. If not, can you make a sketch who you imagine it?

Unfortunately to cut the power with a push button, you'll need a bit more than a single switch (even if not much more :) ).

To reproduce it, one would basically, need a power-managment IC like the (This chip then can be controlled through the ). This chip would be the easiest, one only needs 3 capacitory a resistor, the pushbutton and 2 gpios from the pi. Controlling it can be done wholely through the device-tree. Downside is the price of the IC (here is austria about 5-8€ / piece).

Alternatively the of the IC could be used. The website describes the function pretty well and it uses a neat circuit, which only needs a single gpio output. Unfortunately one will need a custom script to control the circuit.

Greetings.
Simon
SimonDechain
 
Posts: 7
Joined: 12 Mar 2016, 19:19

Re: Momentary Contact Switch

Postby PeteB » 20 Apr 2016, 19:46

Hi Simon,

I was hoping for a discussion, about different ways to accomplish this. Maybe I should change the name of the thread, LOL. I'll post a pic tonight or tomorrow. You will likely see it tomorrow your time. It is pretty self-explanatory.

I do not want to duplicate a Mausberry. I had one for a while, and I can always buy another one, saving $15 would not be worth opening a thread, let alone the fun task of soldering small parts to a proto board (chuckle).

I can switch power with a small latching relay with dual coils (set/reset coils), IF I decide to do that.

Cutting power completely is not an absolute requirement (for me), because I already have a main power switch, and in any case the Pi with the DAC and dongles only uses 8 milliamps in shutdown (measured with a USB inline meter), and the AC supply draws ~0.25 watts at no load.

The LTC2951 is around $4 in single quantity, less than the cost of the caps and choke in my power supply filter, but more than the $2 for a small latching relay. I think I can solder SOT-23 (maybe, LOL). IRF 7319, around $1 (I will order a couple). Not sure this matters much, but the circuit does look interesting. The script, less so, because I am better at reading code than writing it.

I like the idea of using only one GPIO pin. I currently would need two (one for the button, one for the relay).

P.
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Momentary On/Off Switch with soft shutdown

Postby PeteB » 21 Apr 2016, 04:10

Here is how I imagine the hardware would look, with everything on a small board about half the size of a Pi.

Standard barrel connector for a 5V supply, momentary switch on the same board close to the connector, or on an extended pair of wires, if inside an enclosure. Room for a small number of other components, latching relay or the mosfet switch from the example posted above, power supplied to the Pi and a DAC through the GPIO connector. Resettable fuse (Polyfuse), maybe.

The switch in the pics is temporary, the one I intended to use turned out to be too poor quality to bother putting it on the board.

The ribbon cable is a convenience, I don't have the patience to connect/disconnect several single-pin jumpers several times, let alone make new ones.

Image

Image

As I think I said somewhere else, I think I am making my own Pi erector set... :mrgreen:
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Momentary On/Off Switch with soft shutdown

Postby Dohmar » 21 Apr 2016, 04:25

Would this system work with a 12v power source for a HAT? I have the x400 and it has a few gpio pins on top free that I could probably use...

-D
Dohmar
 
Posts: 79
Joined: 14 Mar 2016, 12:27

support RuneAudio Donate with PayPal

PreviousNext

Return to Raspberry Pi

Who is online

Users browsing this forum: Google [Bot] and 35 guests