Start a new topic

battery widget development

There is a couple of interesting battery tools for the pi-top, but no proper widget yet. I have started porting the standard lxde power widget for use with the pi-top but other than setting up github I haven't made much progress seeing how I only just started today.  Anyone with some programming experience who would like to jump on board with this project please visit github and search bstone108/pt-battery-widget and request to join the project!

I've already got a good part of the legwork done on finding out how we can pull data without need for root access,  but someone else might have a better method.  Please join in and help us get a functional widget!

1 person likes this idea

If you look at the source of my gtk_battery program, which is on github at under user rricharz, you can see how one can get the information from the battery pack. But be aware that the whole subject is quite complicated, mainly because the i2c bus between the bq40z60 of the battery pack and the raspi does not work reliably. I have done a lot of research and experimenting on this subject and came to the conclusion that the root cause of the reliability problem is a hardware fault of the broadcom chip driving i2c on the raspi, the so called clock strething bug. Just let me know whether you have any more detailed questions.

I have no questions, I'm already learning how to talk to the battery via the official pi top battery script and for simplicity probably just going to make use of that script and just make it a package requirement for the battery applet.  please check the github project I mentioned above for the info I've collected and the source code in progress.

I think this is a interesting project, but I would advice against just using that script for two main reasons. First, it is unreliable and often gives errors or even wrong answers. Just run it a larger number of times while the raspi is busy and you will see the problem. Second, it forks often a large number of times new processes which then run i2cget. If you do this very often, you will use up considerable resources of the rpi. I feel that people do not want to wait more than, lets say 5 seconds, before they see that the battery is starting to charge after turning the main power on. So you need to poll every 5 seconds, and often more than 10 times to get reliable information. I also started with the original pt-battery script, but have in the mean time gone through a long learning curve until things work reliably.

I see,  advice taken.  I'll see what I can come up with.  it's going to be a bit of a learning curve for me too as I'm a very novice programmer.  I'm very very good at finding and fixing bugs,  but never been too great at writing something from scratch.  Guess now is as good of a time as any to learn!  Luckily calling ic2 isn't any harder than just asking the script for info.  I just need to see if I can do so in a way that bypasses root restrictions on older versions of raspbian and ubuntu.  can worry about that detail later,  for now I need to worry about just getting a working prototype.

Good idea, start calling i2cget the way pt-battery does. Then you can go from there and improve while you are learning. I'm sure it is a very interesting project. If you run into any problems with the data collection, I can certainly help, but I have no experience with widgets. In your repository you also mention brightness. This is a whole other subject. Talking to the pt-hub-controller requires spi. Be aware that some of the pi-top software does not work properly on the newest raspian. Good luck!

The existing pt-hub-controller actually works fine with latest raspian.  I have no issues with brightness or auto power off,  if you're having issues make sure you're pt-hub-controller app is up to date via apt repository.  I have no intention of replacing what already works, at least not initially.  That being said some battery widget settings to automatically manage brightness when power gets low,  and so on might be additions for the future,  but for now the pt-hub software works fine as is.  I’m starting initially by just getting a working power meter with auto shutdown capabilities added in in widget format.  The code currently in the GitHub project is an already working power meter but it works via acpi so I’m in process of gutting those functions and writing i2cget calls [scrapped script calls at your recommendation]  If you want to help with that, feel free to check out the script and submit your additions.  The widget itself is already a working widget so none of that part has to be written.

Login or Signup to post a comment