The Pi5 Fan Control library wraps functions to read and control the fan curve of a Raspberry Pi 5 from a Python script.
Used Github copilot for minimal autocomplete, Claude for researching methods of interacting with the fan and firmware.
The Pi5 Fan Control library wraps functions to read and control the fan curve of a Raspberry Pi 5 from a Python script.
Used Github copilot for minimal autocomplete, Claude for researching methods of interacting with the fan and firmware.
I finally pushed my package to PyPi (🥳) and I got version 1.0.0 out, followed quickly by v1.1.0 to fix some issues and also add some new code.
For version 1.0.0, I updated the pyproject.toml metadata with info like the author, license, and GitHub page. Then, I built using uv build and published with uv publish.
For the 1.1.0 update, I took advantage of the Pi’s native pinctrl utility to control the PWM pins of the fan myself. Although I only get binary access, that still let this version turn off the fan completely (useful for a quiet mode) or max the fan speed out (good for high temps or cleaning the fan). This also meant I had to add another function that told pinctrl to let go of the GPIO registers and give control back to the native Linux governors. I made a quick example file for this and pushed 1.1.0 to PyPi as well.
Log in to leave a comment
In this update, I was finally able to finish the core logic of the library and get complete coverage in my tests and examples!
I noticed that whenever I updated the config, it was appending more and more config values to the bottom of the config.txt. To fix this, I reworked the logic that I used for reading/writing to do an atomic overwrite if a config already existed. I also added a function to easily clear the fan curve config, as if my library had never touched it!
I added these new functions to my unit tests, and I also cleaned up the old ones so that they worked properly and had more thorough checks. I also went back to my examples folder and fixed all of the example scripts, adding helpful comments and print statements so that every line is clear.
Log in to leave a comment
Looking through the Linux/Raspberry Pi OS system classes, I was able to identify thermalzone0 and hwmonX (with X changing every time on boot) as the two folders where the data I needed to read/write would be located. I added functions to get the fan speed, profile, and CPU temps, as well as pytest unit tests to check these functions. In addition, I started making the functions that would actually affect the fan curves, although I need to do some more tinkering around with thermalzone0 and sudo permissions in particular to finish that bit up.
Log in to leave a comment