log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- R-Comp updates RISC OS Hexen port to v1.08 (News:)
- APDL make their PD catalogue available for free download (News:74)
- WROCC October 2024 meeting - Andy Marks and RISCOSbits (News:)
- WROCC October 2024 talk on wednesday - RISCOSbits (News:)
- September 2024 News Summary (News:2)
- London Show is 4 weeks away (News:)
- ROOL updates DDE to issue 31e (News:4)
- WROCC Newsletter Volume 41:12 reviewed (News:)
- WROCC September 2024 talk on wednesday - Amcog (News:2)
- Rougol September 2024 meeting on monday (News:)
Related articles
- PackMan in practice, part 2
- PackMan in practice
- Video conversion on RISC OS
- Building the Dream 4 - Random city basics
- Building the Dream 3 - Random map generators, redux
- Building the Dream 2 - The RISC OS Sound System
- Building the Dream 1 - Container data structures
- Bob and Trev: Resurrection: Just in time
- Monster AI
- Combat
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
The Icon Bar: News and features: Power Switching a RaspberryPi
 

Power Switching a RaspberryPi

Posted by Mark Stephens on 10:27, 28/4/2018 | ,
 
Chris Hall has been trying to make the most of power for a RISC OS based RaspberryPi for his GPS system. In his guest post , he lifts the lid on how he does this...
 
A Raspberry Pi can be powered by a mains adapter or by a powerbank. I found myself often pulling out the power plug to power cycle the Pi and came up with a software power switching method that would allow power to be removed under software control.
 

 
A 'power booster' board allows an internal 3.7V Lithium-Polymer battery to produce a 5.2V output and any external 5V power source will take over this rule and charge the internal battery until fully charged. Switching on and off is controlled by an 'ENABLE' input, pulled high by default. A blue LED lights if power is being supplied to the computer. With the booster board output disabled, only a minimal current is drawn from the internal battery. A red LED lights if the internal battery becomes discharged below 3V (and if a diode is fitted to the 'LBO' pad this can disable the output automatically). Fully discharging the internal battery is likely to damage it.
 
While the internal battery is being charged a yellow LED lights, turning green when it is fully charged. A small current drain to light the green LED to show a full charge seems enough to keep some power banks happy even whilst the unit is otherwise powered down and the internal battery fully charged.
 
This means the external source can be connected and disconnected without affecting the operation of the device except to extend battery life.
 

 
Power control
With no power control hardware it is difficult to ensure that the computer is not, inadvertently,turned off during a write operation to the SD card, which can corrupt the file or the whole card. My power control circuit allows power to be applied at any time by pressing the 'on' button. The 'off' button simply signals that a power off has been requested, which can be detected in software. A shutdown/restart cycle will then remove power as soon as the system has been shut down and the CMOS updated.
 
If software detects a 'power off' request then all it has to do (once it has completed any essential tasks) is to issue the command:
 
SYS "TaskManager_Shutdown",162
 
which will do a shutdown/restart cycle.
 
Doing a manual shutdown (CTRL-SHIFT-f12) and then pressing 'Restart' will also remove power (if a 'power off' request has been issued).
 

 
How Does It Work?
 
Software can detect the 'on' button being pressed or held down by reading the GPIO 19 line and can use this information for any purpose. The fact that the 'off' button has been pressed (and the 'on' button remains open circuit) can be detected by reading GPIO 26, meaning that 'power off' has been requested.
 
A little piece of software in !Boot.Choices.Boot.PreDesk sets GPIO 4 to output high (which ensures power stays on even after a 'power off' request).
 
During a restart cycle, before any writes are made to the SD card, the ROM modules are reset which takes GPIO 4 to high impedance: with a 'power off' request pending this will remove power.
 
Provided that the unit has been operating for at least six seconds (enough time for the RISC OS desktop to start), the 'off' button will pull GPIO 26 low but do nothing else. Software can detect this, complete any essential tasks and then either explicitly set GPIO 4 low (if a Witty Pi is present, this will remove power immediately) or (if not) perform a complete system shutdown using the command SYS "TaskManager_Shutdown",162 which will shutdown all applications tidily and restart RISC OS. The effect of this is to update the CMOS êlast time onë setting and restart the ROM. As the ROM reinitialises, GPIO 4 becomes high impedance thus removing power.
 

 
The 'on' button has some additional functions: whilst pressed, components (R6, R7 and LED) may also be fitted to present an LED load to any external power source that will only light if the external source is healthy (this works by sensing whether Vs from the power boost board is 3.7V or 5.2V). If a voltmeter is fitted as shown, the voltage of the internal LiPo battery is displayed whilst the button is depressed. A power meter can also be connected between the power boost board and the Raspberry Pi giving a voltage, current and power consumption readout.
 

 
Battery Life
With an internal 4400mAh LiPo battery, a Raspberry Pi Zero with an OLED display and GPS module (but with no HDMI connection) uses about 170mA (at 5V) and the battery should therefore last for about (4400 x 3.7)/(170 x 5.2)h which is just over 18 hours. A 5000mAh 5V powerbank should extend this by about 28 hours.
 

 
Chris Hall's website
 
  Power Switching a RaspberryPi
  svrsig (09:29 12/5/2018)
 
Chris Hall Message #124282, posted by svrsig at 09:29, 12/5/2018
Member
Posts: 42
Having done some testing, I was quite pleased to see that the current drain on the 3.7V Lithium Ion battery whilst the unit is turned off is less than 25uA (from my circuitry) plus 20uA for the unenabled power boost board itself. Also that the battery life with a 4400mAh battery is over 17 hours and the remaining life can be inferred from the battery voltage which drops from 4.17V to 3.29V steadily as it discharges (a digital voltmeter is enabled whilst the 'power on' button is held down). At around 3.2V the 'LBO' output automatically turns the unit off. At this point a red LED lights so although there is a current drain of 45uA, there will also be over 1mA to light the LED. It will thus be some time after 'low voltage' before the battery becomes fully discharged (which can damage it).

[Edited by svrsig at 09:36, 12/5/2018]
  ^[ Log in to reply ]
 

The Icon Bar: News and features: Power Switching a RaspberryPi