How do I detect if I am running off the battery ?

I am using and OSD3358 based PocketBeaglish Board.

I need to figure out if the board is running from external power or the LiPo battery,
Is there an easy means of doing so ?

Something in sysfs maybe ?

I do not know if it is also true for PocketBeagle, but there is a tool rc_battery_monitor which shows the voltage at the power supply jack. So you may just look into the sources of the tool.

I think you will need to do it by adding some hardware to detect if external power supply is present or not. If external supply is absent and you are executing some code then you are on battery. Simple comparator circuit should do it.

Kind Regards,
Aditya Ayachit

The PMIC has registers you can read to see what source you are using

Don’t know how one could do that…
Although the PMIC supports direct connection of a Li-ion battery (including charging), this functionality is not officially supported on any BeagleBone. Nevertheless, the terminals for this are available on an unplaced header (pins labled TP5-TP8) for experimentation.

Source: https://elinux.org/BeagleBone_Power_Management

Kind regards,
Aditya Ayachit

I use the built in battery and it works great I Can monitor it as well

Hi Evilwulfie,
Can you please explain. I am quite confused here. What internal battery are you talking about? Others also please do not hesitate to point out what I am missing here.
Thanks in advance.

Kind Regards,
Aditya

The 4 pins on the board that do not have anything soldered to them connect to the
PMIC and can supply voltage from a 3.7v li cell you also need a thermistor and a 75k resistor .

The PMIC can use the battery voltage and when on AC in can charge the battery

@evilwulfie Thanks. that’s valuable information.

Thank you all for the responses.

I am using an OSD3358
Battery power is supplied to P8 R8 T8 and N7.

I found the PMIC docs and I could get the information I want from it.
But it is I2C and owned by the kernel and I can not seem to communicate with the PMIC while the kernel driver is loaded, which does not surprise me.

I noted from other posts that there is a patch to the tps65217.c driver that generates KEY_POWER hits on various changes that the PMIC detects.

Unfortunately the current tps65217.c source (5.1-rc3) has significantly different interrupt handling, and patching it to incorporate the KEY_POWER functionality without breaking the other things that have been changed is on the edge of my abilities.

Is there someone that understand threaded and nested interrupt handling in Linux that can guide me in patching the current tps65217.c driver to include the Key generation without blowing it up ?

A person wrote a small program that can read all the registers from user space. so its possible
https://github.com/wphermans/Beaglebone-Web-PMIC-Register-Viewer