I've loaded my RPi4 with CentOS7 I also bought a case with fans that you can attach to the pins on the pi.
I'm not sure where to start looking for the software modifications I need to make in order to power the fans.
I've loaded my RPi4 with CentOS7 I also bought a case with fans that you can attach to the pins on the pi.
I'm not sure where to start looking for the software modifications I need to make in order to power the fans.
Some fans supplied with cases are designed to run full-time. If that's what you're doing, you don't need any software - just connect the fan wiring to the appropriate GPIO pins. If you're asking how to switch the fan ON & OFF based on the RPi CPU temperature, read on.
AFAIK CentOS7 - like all other Linux OS distributed by "The Foundation" - uses the same/standard device tree configuration that RPi OS does. That being the case, the only "software modification" you need to make is to add a single line to your /boot/config.txt
file that invokes the device tree overlay named gpio-fan
.
You can confirm this overlay is available on your system by checking that the file /boot/overlays/gpio-fan.dtbo
exists on your system. This one-liner will give you that information:
$ [[ -f /boot/overlays/gpio-fan.dtbo ]] && echo "fan-overlay available" || echo "No fan-overlay; write a script instead"
If you must (or prefer) to write a script, there are many examples here to do that.
To use the gpio-fan overlay
, you will find a brief explanation for many of the available overlays in your local file /boot/overlays/README
or on GitHub; the current version copied here:
Name: gpio-fan
Info: Configure a GPIO pin to control a cooling fan.
Load: dtoverlay=gpio-fan,<param>=<val>
Params: gpiopin GPIO used to control the fan (default 12)
temp Temperature at which the fan switches on, in
millicelcius (default 55000)
What this means:
Turning a fan ON & OFF requires an external switch (e.g. transistor) as the GPIO pin itself is not up to the task. Instead - use the GPIO to control the transistor. Connect your 2-wire, 3.3V or 5V fan as shown in the diagram below. See the GPIO pinout page for available GPIO pins.
simulate this circuit – Schematic created using CircuitLab
If you're wondering how to add this hardware to your system, there is a YouTube video that has some ideas - it was referenced in one of the many "fan answers" here.
Add the overlay to /boot/config.txt
as follows:
dtoverlay=gpio-fan,gpiopin=5,temp=60000
reboot
to load the overlay. Using the settings above, your fan will turn on when the temperature reaches 60deg C & turn off when it falls a few degrees below that.
/boot/overlays
for gpio-fan.dtbo
. If it isn't there, this can't work, if it is, it should.
– goldilocks
Mar 23 '22 at 14:35