Main > Raspberry Pi & Dev Board

Pi shutdown with toggle switch

<< < (2/4) > >>

pbj:
Relays could do it, but I'd use a microrelay being switched by the power supply and not the AC power.  The issue is charging up the capacitor, and then you start back into the territory of that EDLC UPS circuit.

I've also contemplated using a backup battery, even AAs, but I'm not crazy about the idea of power being present at the Pi 24/7.  The beauty of the caps is that they're going to eventually wind down if that Pi manages to turn itself back on.

Keep at it, man, you're our only hope.




obcd:
You can make the linux root file system of the raspberry pi read only. If the SD card is no longer written 2, it will no longer corrupt if you pull the power. A problem that rises using that approach is obvious, what about the high scores? Maybe a small (cheap) usb stick can be used for that purpose. A normal setup on such a stick can still corrupt if the system is written during a powerdown. Some systems like the Nintendo Wii clearly give a message not to power down the system while the high scores are saved...Another approach is to use multiple save files with a crc check at the end of them. If a save file has a bad crc, simply revert to the one before it. You will only lose the stuff that was changed during the last save. You could even use the usb stick as medium with a number of writable sectors, and use no file system on it. This approach will again lessen the chanche of corruption. I found a tool for debian called fsprotect that does the job real nice. All writes are simply redirected to a ram based tmpfs file system. It uses aufs to combine the 2 filesystems (the root ext4 and the tmpfs) for it's purpose.
To get a kernel with aufs, you might need to recompile the kernel. Once you have that, the additional steps are simple.
first run : sudo update-initramfs -c -k `uname -r`
This will create an initrd file on the boot folder that is needed by fsprotect
Next, add the following line to the /boot/config.txt file:
initramfs initrd.img-x.yy.z
(x.yy.z depend upon your kernel version. uname -r will show that version)
Next, install the fsprotect package:
sudo apt-get install fsprotect
Next, add the following to the end of the /boot/cmdline.txt
fsprotect=128M
upon the next reboot, your root fs will be read only. You can run the command "sudo mount" to check this out.
Simply remove the fsprotect=128M and reboot if you need to make changes to the rootfs.
128M is the amount of ram memory used for the root fs overlay file.
I have instructions for the compilation of a new kernel, but it's a bit much to post this here.
There are other methods to make the rootfs read only, but fsprotect has the advantage that everything keeps working like there are no changes to the root fs.
You might just need to replace the logging system to prevent excessive writing to the rootfs.


DaOld Man:

--- Quote from: pbj on November 13, 2015, 09:41:25 am ---Relays could do it, but I'd use a microrelay being switched by the power supply and not the AC power.  The issue is charging up the capacitor, and then you start back into the territory of that EDLC UPS circuit.

I've also contemplated using a backup battery, even AAs, but I'm not crazy about the idea of power being present at the Pi 24/7.  The beauty of the caps is that they're going to eventually wind down if that Pi manages to turn itself back on.

Keep at it, man, you're our only hope.

--- End quote ---

The reason I was thinking of the relay on the power supply high side was to isolate the caps from the relay. The caps will keep the relay on otherwise, unless you use blocking diodes, but a diode introduces voltage drop, even the schottky ones, however the drop across them is small. Have to account for all the current going through the diode too.
A relay on the high side would be isolated by the power supply itself, but the power supply would have to be hefty enough to charge the completely drained cap.
A relay would be de-engerized automatically on power failure, and a simple on/off switch in the power high side before relay would work.

@obcd: Interesting stuff man.

Here is a crude drawing of my proposed circuit:

behrmr:
Have you considered an inexpensive UPS and NUT on the Pi? 

Jamesbeat:
Is it absolutely necessary to be able to pull the plug?

I set up my pi to shut down when exiting mame, and I have a dedicated (hidden) exit button mounted on the cabinet.
The same button is set to 'tab' when in a game, or 'esc' when in the main menu, so it serves double duty.

When I want to shut down the pi, I just quit to the main menu and hit the button. The pi shuts down in literally three seconds.

I'm not saying that it wouldn't be better to be able to just pull the plug, but this method is so fast that it practically shuts down in the time it takes to bend down and reach the plug to pull it out, and there's no extra hardware or batteries etc needed.

I did this by editing .profile to include 'sudo shutdown -h now' as the last instruction, so as soon as I quit mame, it executes the shutdown instruction.
Then all I had to do was map my button to the 'esc' or in mame.

Naturally, its best to get the machine set up properly before adding this line to .profile, otherwise the pi will shut down every time you quit mame. If you need to get back under the hood of the pi for any reason, you can always put the sd card in another machine and edit .profile to stop the pi shutting itself down.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version