User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: RaspberryPi On/Off Switch Idea

Thu Jul 26, 2012 10:52 am

Wolfram23 wrote:I'm planning to put my RPi in a car, so it's already on a 12V DC circuit. Trying to figure out the most efficient 12V to 5V adapter, as well as how to auto sleep/wake the RPi.
The 12V DC in a car is apparently very "noisy", so the circuit that the RPi uses to "sense" the ignition switch (via one of it's GPIOs) should use an opto-isolator for protection.
Anyway I'm sure the hardwire side of it is just a little more reading away, but as for software interfacing with the GPIO pins, I really have no idea. Would be great if you guys can expand on that.
Wiki to the rescue! ;) http://elinux.org/Rpi_Low-level_peripherals have a look at the code examples.

User avatar
Mortimer
Posts: 919
Joined: Sun Jun 10, 2012 3:57 pm

Re: RaspberryPi On/Off Switch Idea

Thu Jul 26, 2012 11:29 am

AndrewS wrote:The 12V DC in a car is apparently very "noisy", so the circuit that the RPi uses to "sense" the ignition switch (via one of it's GPIOs) should use an opto-isolator for protection.
Why? I would have though a simple filter would deal with most of that, and if you are really worried a zener diode to dump excess voltages. An opto isolator makes sense when you are interfacing low voltage circuits with mains voltages, but that is not what we have here. If the input to the opto isolator is noisy, the output is likely to be noisy too.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: RaspberryPi On/Off Switch Idea

Thu Jul 26, 2012 3:04 pm

Sorry, I was just repeating what I'd read elsewhere :oops: Don't have a car so never done any interfacing to automotive electronics. :|

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4249
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: RaspberryPi On/Off Switch Idea

Thu Jul 26, 2012 4:24 pm

I have heard from someone who should know, that if the battery terminal is loose, the alternator can produce spikes of up to 300V. That doesn't mean that you can't filter it and cap it with a zener, but you have to do so fairly robustly.

Bakul Shah
Posts: 305
Joined: Sun Sep 25, 2011 1:25 am

Re: RaspberryPi On/Off Switch Idea

Sat Jul 28, 2012 10:43 pm

rurwin wrote: The advantages of relays are they are simple, easy to understand, they have zero leakage current and almost zero on resistance, and they very effectively isolate the controlling circuit from the controlled circuit. Also you can see and hear them operate and they very rarely half-operate.
A friend of mine dug up this Linear part, http://www.linear.com/product/LTC2954 which seems about perfect!
  • When power is off, a short press on the push button to turn it on.
  • When power is on, a short press to interrupt the µprocessor. It can then save its state and shut itself down.
  • If the µP doesn't do what you want, a much longer press (6.4 sec per µF) to force shut down -- just like on a PC!
A bit pricey in small quantities (only because the Raspi has spoiled us on pricing!). Variations on this part (such as LTC2953, with voltage monitoring, power fail and low voltage signal) may also be useful.

medosamer
Posts: 3
Joined: Thu Aug 09, 2012 2:25 pm

Re: RaspberryPi On/Off Switch Idea

Thu Aug 09, 2012 2:55 pm

Maybe i'm missing the point here, but here's my idea of on/off switch. Instead of constantly plugging and unplugging the cable why not use something like this IR switch in a link below. It's low quality, low cost but it works. Connect your power adapter to it and you can turn your power on/off with IR remote or by pushing litlle black switch on it.

http://www.dealextreme.com/p/ir-remote- ... 220v-12902

User avatar
Mortimer
Posts: 919
Joined: Sun Jun 10, 2012 3:57 pm

Re: RaspberryPi On/Off Switch Idea

Thu Aug 09, 2012 4:58 pm

Eek! If you tried to use one of those in my home, I'd kick you out... fast! Sorry, the idea is cool, but that particular example looks nasty and dangerous!
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
jbeale
Posts: 3375
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: RaspberryPi On/Off Switch Idea

Thu Aug 09, 2012 5:29 pm

rurwin wrote:The SD card is smart and handles wear-leveling itself. Therefore it can be writing data to the flash memory and moving pointers to data around a short time after data is written to the SD. If power is removed during this process, it is possible to corrupt the SD so thoroughly that no computer can recover it.
To this point, looking closely at the green LED indicating SD card activity while I have nothing but the usual background tasks running, I notice a tiny faint blink once every second. Then every so often (at least every 10 sec or so) the green light stays on quite a bit longer. My assumption is that the system is updating some time-of-day value into the same location in a file on the SD card once every second, which frequently triggers a wear-levelling process so the next write has a long timeout which makes the process visible on the LED.

If that assumption is correct... is there some way to avoid this once-every-second file write, which may be fine for a hard-disk system but seems questionable with a flash-based filesystem?

medosamer
Posts: 3
Joined: Thu Aug 09, 2012 2:25 pm

Re: RaspberryPi On/Off Switch Idea

Thu Aug 09, 2012 5:45 pm

:-) I know it looks bad, but i actually use one at home. Good thing I don't live under your roof :-) I really don't think it can be that dangerous for low power devices. But then again I really don't know for sure.

User avatar
Mortimer
Posts: 919
Joined: Sun Jun 10, 2012 3:57 pm

Re: RaspberryPi On/Off Switch Idea

Thu Aug 09, 2012 7:19 pm

It's not the low power or not that is the problem, it is the fact that it allows an earth device to be plugged into it, but doesn't have an earth pin itself to maintain continuity from device to ground. In many countries such devices are actually banned.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

medosamer
Posts: 3
Joined: Thu Aug 09, 2012 2:25 pm

Re: RaspberryPi On/Off Switch Idea

Fri Aug 10, 2012 4:20 pm

Didn't know that. But my raspberry power supply (htc phone charger) also doesn't have groud pin so I think it doesn't make a difference.

User avatar
Mortimer
Posts: 919
Joined: Sun Jun 10, 2012 3:57 pm

Re: RaspberryPi On/Off Switch Idea

Fri Aug 10, 2012 4:28 pm

For most things that have a dummy plastic earth pin, I agree it would probably be safe. The problem is that someone who doesn't know better could come along and plug something in that requires an earth to be safe, and in the worst case get hurt. I wouldn't want that on my conscience.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
reiuyi
Posts: 165
Joined: Sun Oct 09, 2011 4:59 pm
Contact: Website

Re: RaspberryPi On/Off Switch Idea

Sat Aug 11, 2012 11:36 am

The UK has wall sockets with switches, right?

Image

And for those that don't, I've seen this in general goods stores for like a euro each:

Image

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: RaspberryPi On/Off Switch Idea

Tue Oct 23, 2012 1:06 pm

Bakul Shah wrote: A friend of mine dug up this Linear part, http://www.linear.com/product/LTC2954 which seems about perfect!
  • When power is off, a short press on the push button to turn it on.
  • When power is on, a short press to interrupt the µprocessor. It can then save its state and shut itself down.
  • If the µP doesn't do what you want, a much longer press (6.4 sec per µF) to force shut down -- just like on a PC!
A bit pricey in small quantities (only because the Raspi has spoiled us on pricing!). Variations on this part (such as LTC2953, with voltage monitoring, power fail and low voltage signal) may also be useful.
Hi,

I would be interested to know if you had any success with this part?

Thanks
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

Bakul Shah
Posts: 305
Joined: Sun Sep 25, 2011 1:25 am

Re: RaspberryPi On/Off Switch Idea

Wed Oct 24, 2012 5:52 pm

shawaj wrote:
Bakul Shah wrote: A friend of mine dug up this Linear part, http://www.linear.com/product/LTC2954 which seems about perfect!
  • When power is off, a short press on the push button to turn it on.
  • When power is on, a short press to interrupt the µprocessor. It can then save its state and shut itself down.
  • If the µP doesn't do what you want, a much longer press (6.4 sec per µF) to force shut down -- just like on a PC!
A bit pricey in small quantities (only because the Raspi has spoiled us on pricing!). Variations on this part (such as LTC2953, with voltage monitoring, power fail and low voltage signal) may also be useful.
Hi,

I would be interested to know if you had any success with this part?

Thanks
I am afraid it will remain a paper design until I actually need it. It will be nice to have but none of the stuff I am working on now needs it.

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: RaspberryPi On/Off Switch Idea

Thu Oct 25, 2012 6:46 am

Hi,

Thanks for the reply.

Do you have a circuit diagram you have put together already then?

Thanks
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

Bakul Shah
Posts: 305
Joined: Sun Sep 25, 2011 1:25 am

Re: RaspberryPi On/Off Switch Idea

Fri Oct 26, 2012 5:23 pm

Sorry, no circuit diagram.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: RaspberryPi On/Off Switch Idea

Fri Oct 26, 2012 5:50 pm

I also designed a power supply switch for the PI so it kills the power when it's in shutdown mode and start back up with a tap of a push button switch.

If you want a circuit to work on have a look at:

Image

The only problem you'll find is it's designed to run from 6v you can modify it for 5v by removing D1 however C6 on the PI could store enough charge to sometimes prevent the relay closing properly.
If you have a DPDT relay then you could use the other half of the switch to discharge the capacitor faster unfortunately I only have an SPDT relay at the moment.

Richard S.

Bakul Shah
Posts: 305
Joined: Sun Sep 25, 2011 1:25 am

Re: RaspberryPi On/Off Switch Idea

Fri Oct 26, 2012 6:38 pm

Bakul Shah wrote:Sorry, no circuit diagram.
Forgot to mention. http://cds.linear.com/docs/Datasheet/2954fb.pdf shows some sample applications that may help.

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: RaspberryPi On/Off Switch Idea

Wed Oct 31, 2012 10:42 am

redhawk wrote:I also designed a power supply switch for the PI so it kills the power when it's in shutdown mode and start back up with a tap of a push button switch.

If you want a circuit to work on have a look at:

Image

The only problem you'll find is it's designed to run from 6v you can modify it for 5v by removing D1 however C6 on the PI could store enough charge to sometimes prevent the relay closing properly.
If you have a DPDT relay then you could use the other half of the switch to discharge the capacitor faster unfortunately I only have an SPDT relay at the moment.

Richard S.
Thanks very much for that. So does that circuit have two buttons - one to power on and one to power off? And I am guesing it doesnt pull the power until it senses that the pi is properly shut down? Also with this circuit is it possible to get the power off switch to initiate a shutdown on the pi before removing the power?

Also, is D1 the diode just before the 22k resistor?

Lastly, would the only change for 5v be that D1 and the DPDT relay? Would something like this suffice for the relay: http://uk.rs-online.com/web/p/non-latch ... s/0351803/

cheers!
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: RaspberryPi On/Off Switch Idea

Thu Nov 01, 2012 10:35 am

I recently changed the design of my circuit and photo so any previous comments are not valid anymore, sorry for the confusion.
There is no D1 the diode at the 22k resistor is to prevent 5v flowing back into the GPIO UART TX pin.
The other diode across the relay coil is to protect the transistors from damage when the power is lost.
This is because a collapse of the magnetic field in the relay coil would generate a high voltage spike in the reverse direction.

The circuit now has 2 switches one to turn on the power supply and the other to turn off the power supply.
It will happily work using 5v and doesn't require a DPDT relay because I have reduced the sensitivity of the transistor switch.
For more information on how the circuit works please read my other post: http://www.raspberrypi.org/phpBB3/viewt ... 64#p205664

Richard S.

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: RaspberryPi On/Off Switch Idea

Thu Nov 01, 2012 11:57 am

hi again,

thanks for the update.

so just a 5v spdt will be sufficient there for a 5v input? and i am assuming they are just non latching switches?

and I am guessing that this setup will not cut the power until the pi is completely and properly shutdown? lastly, it doesnt need any coding on the raspberry pi to perform all these actions?

thanks a lot
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: RaspberryPi On/Off Switch Idea

Thu Nov 01, 2012 12:16 pm

Wolfram23 wrote:Interesting discussion here. As someone who knows relatively little about electronics, I can confirm that most of what you're talking about is going over my head (although I understand the gist of it).

I'm planning to put my RPi in a car, so it's already on a 12V DC circuit. Trying to figure out the most efficient 12V to 5V adapter, as well as how to auto sleep/wake the RPi.

The idea I have is to use the 12V to 5V on the main 12V Battery line (constant power), with a second adapter 12V to 5V (or does it need to be 3.3V?) on the ignition line. Then when ignition goes live, the RPi wakes up, and when it goes dead, the RPi goes to sleep. I'd also consider a physical switch in case I won't be driving my car for more than several days, just to minimize battery drain.

Anyway I'm sure the hardwire side of it is just a little more reading away, but as for software interfacing with the GPIO pins, I really have no idea. Would be great if you guys can expand on that.
You can use a relay as a switch (energized by the ignition line) for the RPi. If you can boot the OS with SD card in read-only mode (it is possible with Linux), you can just power RPi down abruptly without OS corruption (no need to signal RPi about power down).

The relay coil must be 12 V energize-able. The are some cheap DC-DC switch mode converters on EBay (LM2577 based DC-DC converters). You need to turn the potentiometer to set the output as 5 V.
Thus, the ignition line controls the relay which turns on the DC-DC converter. You may need a surge suppressor on the input of the DC-DC converter to protect it.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: RaspberryPi On/Off Switch Idea

Thu Nov 01, 2012 1:07 pm

The relay needs to be SPDT (single pole double throw) so all 3 pins are used the circuit it won't work with only 2 pins.
As for the switches they're nothing special just tactile push buttons e.g. http://www.ebay.co.uk/itm/Quality-Minia ... 0932555176
There is no coding required on the PI the circuit would kill the power when the PI is in shutdown mode this is determined by the voltage output at the GPIO UART TX pin (GPIO 14) - http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29

Richard S.

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: RaspberryPi On/Off Switch Idea

Thu Nov 01, 2012 1:22 pm

I would like to adapt this to allow a microcontroller to switch on and off the raspberry pi.

Process as follows for shutdown:
  1. Switch or microcontroller triggers shutdown process via 1st GPIO pin
    Raspberry Pi indicates that shutdown is complete via 2nd GPIO pin
    Microcontroller or circuit cuts all power
Process as follows for power up:
  1. Switch or microcontroller triggers power through circuit
    Raspberry Pi indicates that raspberry pi is active via 2nd GPIO pin
By using something like the TI launchpad, it could monitor the input voltages via it's ADCs and provide automatic power up and down dependent on available battery power for instance (see the Solar Pi article in the MagPi 7 for my thinking here), or provide timed activations or wireless triggering.

Anyway, just ideas but will look at the circuit in detail and perhaps have a play with it. Thoughts?
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

Return to “General discussion”