You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you please include the max17040_battary module (config option CONFIG_BATTERY_MAX17040) to the default rpi-config (and as a result to the default kernel for raspbian). The chip is found at least on this UPS board (description is available only on Chinese).
Also it would be nice to have an associated device tree overlay. The chip utilizes i2c bus and has hard-wired address 0x36, the datasheet can be found here. I may assist with testing/writing it, but I haven't found the original *.dts repository for the raspbery pi *.dtbo's.
PS: don't make a typo in your configs... just spent half a day wondering why it doesn't work because wrote "i2c-sensors" for name of dt_overlay >_< (just wanted to share it).
is this feature implemented with dtoverlay=i2c-sensor,max17040?
if it is, I'm having issues using it, the Battery (pi-top / laptop) panel add-on for raspbian will always say Charging 0% irrespective of what is actually going on
The following python script does successfully return the voltage and charge percentage
#!/usr/bin/pythonimportstructimportsmbusimportsysimporttimedefreadVoltage(bus):
"This function returns as float the voltage from the Raspi UPS Hat via the provided SMBus object"address=0x36read=bus.read_word_data(address, 2)
swapped=struct.unpack("<H", struct.pack(">H", read))[0]
voltage=swapped*1.25/1000/16returnvoltagedefreadCapacity(bus):
"This function returns as a float the remaining capacity of the battery connected to the Raspi UPS Hat via the provided SMBus object"address=0x36read=bus.read_word_data(address, 4)
swapped=struct.unpack("<H", struct.pack(">H", read))[0]
capacity=swapped/256returncapacitybus=smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)print"++++++++++++++"print"Voltage:%5.2fV"%readVoltage(bus)
print"Battery:%5i%%"%readCapacity(bus)
ifreadCapacity(bus) ==100:
print"Battery: FULL"ifreadCapacity(bus) <20:
print"Battery: LOW"print"++++++++++++++"
@andrew-stclair, Hi, yes, the kernel interface should be enbaled by dtoverlay=i2c-sensor,max17040 in boot config. The chip supposed to correctly display only charge persentage, and a scaled value for voltage.
I can't say why the applet doesn't work for you. If the applet utilises upower it should correctly display at least charge percentage. The state should likely be 'discharging' or 'unknown' (as its reported by the kernel, but it seems upower doesn't actually support that state). The voltage is received directly from the chip, so it won't be quite correct as well (it should be scaled by 1.25/16*1000).
You should check what it actually displays under the hood with next commands:
for kernel interface: grep -r . /sys/class/power_supply/battery
@pelwell, sorry I haven't replied for a while. Everything works fine for me, so I'm closing the bug. If there are problems with modules, I don't think there is much more can be done on the raspberry's kernel side.
It would be nice to integrate some pre-scaler for voltage, but it's a task for the mainline kernel IMHO.
Activity
pelwell commentedon Mar 23, 2019
Look at
arch/arm/boot/dts/overlaysin this repo. We'll consider the module request.Fat-Zer commentedon Mar 24, 2019
Thanks, for the directions. The suggested patch, if you wondering (I grant it to the public domain or whatever if anybody wondering):
PS: don't make a typo in your configs... just spent half a day wondering why it doesn't work because wrote "i2c-sensors" for name of dt_overlay >_< (just wanted to share it).
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
pelwell commentedon Mar 25, 2019
Added to rpi-4.19.y. Please test, then close if happy.
Fat-Zer commentedon Mar 25, 2019
Thanks! The commits looks fine. I'll actually test it with next respbian kernel package update if you never mind.
kernel: config: disable memory and IO cgroups
kernel: config: disable memory and IO cgroups
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
20 remaining items
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
configs: Add CONFIG_BATTERY_MAX17040
overlays: Add max17040 support to i2c-sensor
JamesH65 commentedon Sep 19, 2019
@Fat-Zer Can this issue be closed?
andrew-stclair commentedon Dec 11, 2019
is this feature implemented with
dtoverlay=i2c-sensor,max17040?if it is, I'm having issues using it, the Battery (pi-top / laptop) panel add-on for raspbian will always say Charging 0% irrespective of what is actually going on
The following python script does successfully return the voltage and charge percentage
I'm using the
UPS 17650developed by @linshuqin329Fat-Zer commentedon Feb 21, 2020
@andrew-stclair, Hi, yes, the kernel interface should be enbaled by
dtoverlay=i2c-sensor,max17040in boot config. The chip supposed to correctly display only charge persentage, and a scaled value for voltage.I can't say why the applet doesn't work for you. If the applet utilises upower it should correctly display at least charge percentage. The state should likely be 'discharging' or 'unknown' (as its reported by the kernel, but it seems upower doesn't actually support that state). The voltage is received directly from the chip, so it won't be quite correct as well (it should be scaled by
1.25/16*1000).You should check what it actually displays under the hood with next commands:
for kernel interface:
grep -r . /sys/class/power_supply/batteryfor upower interface:
upower -eand then
upower -i /org/freedesktop/UPower/devices/battery_batteryFat-Zer commentedon Feb 21, 2020
@pelwell, sorry I haven't replied for a while. Everything works fine for me, so I'm closing the bug. If there are problems with modules, I don't think there is much more can be done on the raspberry's kernel side.
It would be nice to integrate some pre-scaler for voltage, but it's a task for the mainline kernel IMHO.