![]() |
Is the power source exposed to the OS? - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: PINE A64-LTS / SOPINE Compute Module (https://forum.pine64.org/forumdisplay.php?fid=66) +--- Forum: General Discussion on PINE A64-LTS / SOPINE (https://forum.pine64.org/forumdisplay.php?fid=67) +--- Thread: Is the power source exposed to the OS? (/showthread.php?tid=7720) |
Is the power source exposed to the OS? - seal - 07-19-2019 Meaning is there a way for the operating system to know if the device is being powered by dc input or lipo input? RE: Is the power source exposed to the OS? - stuartiannaylor - 07-20-2019 (07-19-2019, 05:43 PM)seal Wrote: Meaning is there a way for the operating system to know if the device is being powered by dc input or lipo input? Its not USB-C PD just Quote:Power input, positive tip; 12V/3A (minimum) recommended Needs prob more than just a little Pi Lipo and this is slight overkill but capable for extended run times. https://www.simplypowersupply.com/pdf/psc-60.pdf But if you search around there are lithium ones https://www.aliexpress.com/item/32827494097.html But its quite good being 12v 3amp as there are a lot of 'Alarm panels' that if you do some sourcing will have an discharge alarm. Lead acid though. https://www.alibaba.com/product-detail/ups-charger-power-12v-3a-SMPS_60536062686.html There are some quite cheap boards for the budding electronic genius out there where a current & voltage sense circuit could be added with a modicum of knowledge and have quite a kickass 12v UPS https://www.aliexpress.com/item/32953515494.html https://www.aliexpress.com/item/32828796768.htm https://www.aliexpress.com/item/32469098903.html Prob needs a decent big capacitor on output though RE: Is the power source exposed to the OS? - seal - 07-20-2019 But is there a way for the operating system to know what the current power source is? For the purpose of a script that would notify if DC power is lost and the system is now running on battery? Alternatively can the operating system know what the battery level is? RE: Is the power source exposed to the OS? - stuartiannaylor - 07-20-2019 (07-20-2019, 06:02 AM)seal Wrote: But is there a way for the operating system to know what the current power source is? For the purpose of a script that would notify if DC power is lost and the system is now running on battery? Alternatively can the operating system know what the battery level is? The last 2 where i2c volt/current sensors so they can measure an input so long as inline. The system itself if the UPS is any good will not be able to tell the difference between 12v non bat vs 12v bat. But if you put a cheap i2c sensor on your battery output then job done. Example software is via Sparkfun https://www.sparkfun.com/products/15176 https://www.rototron.info/raspberry-pi-ina219-tutorial/ https://pypi.org/project/pi-ina219/ dunno what happened to the aliexpress links? https://www.ebay.co.uk/itm/302997431044 Can not really tell you more as not done any gpio work on that platform To your original answer prob yes as has a port thought I was in the rockpro64 section hence 3a and all the rest doh! ![]() RE: Is the power source exposed to the OS? - pkfpeters - 07-20-2019 Hi Seal, Yes there is a very easy way. Just create a small script and use the following (sysfs) items: Current battery power level in percentage 0-100% full /sys/class/power_supply/battery/capacity Indicating if we are operation on battery or power supply (Kernel AC power looks a bit strange, but it does mean the DC input) 0 = Battery, 1 = DC input (main power) /sys/class/power_supply/ac/present Use `shutdown 0` in your script to shutdown. With the information above you should be able to create a small bash script checking the battery level in order to do a safety fast shutdown. Or use a countdown (for example. 120 seconds) and wait for power to come back so bufferring small power outages. Dont forget to put the jumper on battery and if your script works well you should be able to handle power restores (during shutdown delay , complete shutdowns and auto boot up when power restores. And if you want a lot more information just take a look at the sysfs items in: /sys/class/axppower/ You can get all sorts of information, like battery temperature, charge current, etc. |