Daniel J. Posted February 8, 2017 Share Posted February 8, 2017 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 More sharing options...
sooperior Posted February 8, 2017 Share Posted February 8, 2017 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 More sharing options...
sooperior Posted February 8, 2017 Share Posted February 8, 2017 By the way, I didn't check your link. Yes, you can also use those scripts but the guys at armbian made it a "built-in" feature. I think that my approach on the message above is way more simple. Link to comment Share on other sites More sharing options...
Daniel J. Posted February 8, 2017 Author Share Posted February 8, 2017 Thanks, great info... Link to comment Share on other sites More sharing options...
Menion Posted August 19, 2017 Share Posted August 19, 2017 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 More sharing options...
Igor Posted August 19, 2017 Share Posted August 19, 2017 Tell Lede to start using our kernel or at lest patches and you will have those functions Link to comment Share on other sites More sharing options...
Menion Posted August 19, 2017 Share Posted August 19, 2017 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 More sharing options...
zador.blood.stained Posted August 19, 2017 Share Posted August 19, 2017 2 minutes ago, Menion said: About the apx: is it full functional in mainline, including battery monitor, or there are some armbian patches required? /sys/power/axp_pmu comes from this patch: https://github.com/zador-blood-stained/axp209-sysfs-interface You could probably apply it to the LEDE 4.4.x kernel. Link to comment Share on other sites More sharing options...
Igor Posted August 19, 2017 Share Posted August 19, 2017 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 More sharing options...
Menion Posted August 19, 2017 Share Posted August 19, 2017 2 hours ago, zador.blood.stained said: /sys/power/axp_pmu comes from this patch: https://github.com/zador-blood-stained/axp209-sysfs-interface You could probably apply it to the LEDE 4.4.x kernel. Yeah, this is definitely something I can work on, thank you! Link to comment Share on other sites More sharing options...
Menion Posted August 21, 2017 Share Posted August 21, 2017 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 More sharing options...
zador.blood.stained Posted August 21, 2017 Share Posted August 21, 2017 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 More sharing options...
Mahyuddin Husairi Posted August 22, 2017 Share Posted August 22, 2017 How to change the sampling frequency reading from AXP209? In the code you gave several options from 25hz to 200hz. Link to comment Share on other sites More sharing options...
Menion Posted August 24, 2017 Share Posted August 24, 2017 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 More sharing options...
zador.blood.stained Posted August 24, 2017 Share Posted August 24, 2017 7 minutes ago, Menion said: Is it normal? Is it an old battery? What devices do you have connected to your board (i.e. SATA HDD)? For something like a 18650 cell recycled from a laptop battery it would be normal. Link to comment Share on other sites More sharing options...
Menion Posted August 24, 2017 Share Posted August 24, 2017 No. It is a brand new LiPo battery of a decent brand also. I have anly the BananaPi and a WiFi USB dongle connected Link to comment Share on other sites More sharing options...
carrierlost Posted September 18, 2017 Share Posted September 18, 2017 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 More sharing options...
Menion Posted September 19, 2017 Share Posted September 19, 2017 I did the math. The current is aprox 200mA, it would mean that the voltage drop is caused by roughly 1Ohm of wires resistance which is really a lot Link to comment Share on other sites More sharing options...
mido Posted April 1, 2018 Share Posted April 1, 2018 @Menion Hi, how do you use a battery with the BananaPi, is it supported? Link to comment Share on other sites More sharing options...
Recommended Posts