-2

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.

XChikuX
  • 97
  • 2
  • Is the fan simply meant to run continuously; in which case it only needs to connect to power and ground? What does the product listing say? Have you searched for raspberry pi temp controlled fan? – Steve Robillard Mar 23 '22 at 02:32

1 Answers1

3

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:

Step 1:

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.

schematic

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.

Step 2:

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.

Seamus
  • 18,728
  • 2
  • 27
  • 57
  • 1
    *"If CentOS7 uses the standard device tree configuration that RPi OS does"* -> Might be worth noting, so that someone does not waste too much time pursuing that as a cause of problems, that since the RPi requires a special kernel and it is the kernel + firmware that apply the device tree stuff, it almost certainly is supported anywhere and everywhere. That said, CentOS following RHEL is very conservative update wise and you should check `/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