How to Customize Raspberry Pi 5 fan speeds from within Ubuntu?

Ubuntu Version:

Ubuntu 24.04.02 LTS

Desktop Environment (if applicable):

Gnome

Problem Description:

I’d like instructions on how to create a custom fan curve for a Raspberry Pi 5 from within Ubuntu.

My understanding is that the fan doesn’t spin up until the hardware reaches 50 degrees, but I want to create a custom fan curve to keep it spinning at lower temperatures.

I tried editing the bcm2712-rpi-5-b.dtb file in Nano, but I wasn’t sure what I was looking at.

Relevant System Information:
Raspberry Pi 5

You are correct that the device-tree is where this is configured, but the dtb file is the compiled device-tree which isn’t (directly) editable. However, in this case we don’t even need to edit the device-tree itself because the values you want to tweak are parameterized and can be customized simply by adding some lines to /boot/firmware/config.txt.

Firstly, the reference file you want to have a look at is /boot/firmware/overlays/README. This text file documents all the available device-tree overlays, and their parameters. It also documents the parameters for the base device tree, which is what we’re interested in here.

Search for fan_temp0 in that README file and you should find yourself at the start of the various fan-related parameters in the base device-tree. I’ll quote them here, but you should double-check in that file in case they’ve changed across kernel versions:

        fan_temp0               Temperature threshold (in millicelcius) for
                                1st cooling level (default 50000). Pi5 only.
        fan_temp0_hyst          Temperature hysteresis (in millicelcius) for
                                1st cooling level (default 5000). Pi5 only.
        fan_temp0_speed         Fan PWM setting for 1st cooling level (0-255,
                                default 75). Pi5 only.
        fan_temp1               Temperature threshold (in millicelcius) for
                                2nd cooling level (default 60000). Pi5 only.
        fan_temp1_hyst          Temperature hysteresis (in millicelcius) for
                                2nd cooling level (default 5000). Pi5 only.
        fan_temp1_speed         Fan PWM setting for 2nd cooling level (0-255,
                                default 125). Pi5 only.
        fan_temp2               Temperature threshold (in millicelcius) for
                                3rd cooling level (default 67500). Pi5 only.
        fan_temp2_hyst          Temperature hysteresis (in millicelcius) for
                                3rd cooling level (default 5000). Pi5 only.
        fan_temp2_speed         Fan PWM setting for 3rd cooling level (0-255,
                                default 175). Pi5 only.
        fan_temp3               Temperature threshold (in millicelcius) for
                                4th cooling level (default 75000). Pi5 only.
        fan_temp3_hyst          Temperature hysteresis (in millicelcius) for
                                4th cooling level (default 5000). Pi5 only.
        fan_temp3_speed         Fan PWM setting for 4th cooling level (0-255,
                                default 250). Pi5 only.

The syntax for customizing these is a little strange, but not too difficult. In /boot/firmware/config.txt you need to add lines with the format dtparam=PARAM=VALUE. For example, if you want to change the base temperature at which the fan turns on from 50°C to 55°C you might append the following (bearing in mind the value is in millicelcius):

dtparam=fan_temp0=55000

You can list multiple parameters in a single dtparam= line like so:

dtparam=fan_temp0=55000,fan_temp0_speed=90

Alternatively, you can use multiple dtparam= lines, if you prefer:

dtparam=fan_temp0=55000
dtparam=fan_temp0_speed=90

If your boot media is used only on a Pi 5, adding this under an [all] section is absolutely fine. However, if your boot media is going to move between different models of Pi, you may wish to place these customizations within a section limiting their effect to the Pi 5. For example:

[pi5]
dtparam=fan_temp0=55000
dtparam=fan_temp0_speed=90

[all]
# The rest of the configuration...

There’s a lot more one can do with the conditional filters, which is documented on the Raspberry Pi site.

1 Like

Thank you very much!

I was able to lower the temperature settings so the fan starts at 20c, and theoretically spins faster every 10 degrees.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.