Jump to content

Battery management via AXP209 (Banana Pi/Pro)


Daniel J.

Recommended Posts

So I have a question... I'd like to manage Li-Ion battery operation on SBCs using the AXP209 power management chip (especially the Banana Pro, as that's what I have...)

 

I soldered a connector to the battery terminals on my BPro for portable operation, and it would be nice to have some kind of solution to raise an alert at low battery charge (like via the onboard LEDs), and automatically call system shutdown at a certain level.

 

Googling has shown that the AXP209 has an i2c interface for sensors, and there are a few scripts for reading battery status here:

http://hardware-libre.fr/2014/11/banana-pi-axp209-battery-power-monitoring/

 

My current plan is to probably use a shell script set as a regular cron job to monitor the battery and act accordingly, which should do the job but feels a bit too duct-tape-ey. Has anyone done something like this? Any observations or ideas? What battery voltage should I use as a cutoff?

Link to comment
Share on other sites

If you are using mainline kernel, you can use cron (for instance) to read every X minutes:

/sys/power/axp_pmu/ac/connected >>To find out if connected to AC power or not (then it's battery)

/sys/power/axp_pmu/battery/capacity >> To get a % of battery charge

 

To me is easier to say at 20 (%) than 3.75 mV or similar

 

I have a script that checks every 10 minutes, when ac is cut off it sends a warning mail. When battery is <20% it goes to self-shutdown

 

 

Legacy kernel has something similar, but I can't check right now (google for that if you need it)

Link to comment
Share on other sites

Hi

I am actually trying to do the same on my BananaPi with LEDE running kernel 4.4.79

I don't have /sys/power/axp_pmu,  checking the sunxi mainlining effort in 4.4.x there is support for axp209_usb (that I have in /sys) but "axp" drivers have been merged in 4.9.x.

Is this the kernel version I need (if I don't want to use i2c access)?

Link to comment
Share on other sites

:)

It is possible to swap kernel with some tricks, but Lede develops and use several network patches for their architecture. Anyhow I will look into that. 

About the apx: is it full functional in mainline, including battery monitor, or there are some armbian patches required? 

Link to comment
Share on other sites

1 minute ago, Menion said:

It is possible to swap kernel with some tricks, but Lede develops and use several network patches for their architecture. Anyhow I will look into that. 

About the apx: is it full functional in mainline, including battery monitor, or there are some armbian patches required? 


Surely it will be simpler to add patch to Lede. Armbian is not networking dedicated OS ... but if we had Lede kernel functionality it will not be damaging either.

 

I think that AXP related patch will be enough. It does not have all functions but you can monitor battery.

Link to comment
Share on other sites

Hi

I have managed to patch and compile the LEDE Snapshot (based on the 4.4.x kernel)

I would like to issue a pull request, if you don't mind (of course I will give credit to you)

But I need to understand one thing: as far as I see this patch is not included in mainline, right? Is it in the queue or not?

Also, just for your information, the axp20x-calibrate-battery needs a modification to compile against musl libc, because lack of error() function

Bye

Link to comment
Share on other sites

21 minutes ago, Menion said:

But I need to understand one thing: as far as I see this patch is not included in mainline, right? Is it in the queue or not?

No, and it wasn't intended to be included in the mainline. From its README

Quote

Main purpose of this patch is creating a sysfs interface to get information from AXP202/209 PMU until proper power driver is implemented in mainline kernel.

At the time it was created it was the simplest way to get data from the PMIC or change some settings without using userspace tools like i2cget/i2cset or a custom code based on i2c libraries.

Newer kernels have received proper drivers - starting with 4.12 there is even a battery driver and an ADC IIO driver, but this patch still can be useful i.e. to enable/disable RTC battery changing on some boards.

 

28 minutes ago, Menion said:

I would like to issue a pull request, if you don't mind (of course I will give credit to you)

I don't mind, but it has to be noted that it's more a hack than a proper solution (since it doesn't integrate in any existing system like hwmon, iio, power supply, etc.) and it has very limited usefulness without extra documentation.

Link to comment
Share on other sites

Hi @zador.blood.stained maybe you can help me on one thing.

I have connected a LiPo battery, it works, but when the AC is connected I get a battery voltage of about 4.11v which is full charged and the axp try to keep it around 95% with some charging On/Off

But If I disconnect the AC, the battery voltages drop to 3.9v so about 55% of capacity

Is it normal?

Link to comment
Share on other sites

How do you measure the voltage  - with multimeter on battery or what banana reports? If banana is powered from the battery then there is current flow in the wires from battery to banana. When there is current flow there is also voltage drop depending on how much current is used from battery and also how thick the wires are.  So for accurate results use volt-meter and measure directly from battery contacts. Also there is non-linear relationship between battery voltage and how much energy is left.  Depending on specific battery  you should look at manufacturers discharge chart for various loads to know if there is problem. I would not worry too much about if you still get the runtime that is in line with the capacity of the battery.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines