• sales

    +86-0755-88291180

Raspberry Pi Variable-Frequency-Fan User Guide

Introduction

Raspberry Pi Variable-Frequency-Fan, for Raspberry Pi 4B/3B+/3B/3A+/2B

Features

  • Fan speed can be controlled by programming PWM mode
  • Four RGB LEDs can be programmed to achieve status indication and other special effects
  • Provides open source program control code, and the heat dissipation solution makes Raspberry Pi run more stable, perform better
  • Real-time monitoring of the Raspberry Pi's CPU temperature
  • Start the fan when the CPU temperature reaches the set value
  • Multiple temperature threshold settings, corresponding to different fan operating speeds
  • Multiple sets of temperature threshold settings, matching different RGB LED colors, allowing you to easily understand the real-time temperature and heat dissipation effect
  • Real-time monitoring of the working frequency of the Raspberry Pi
  • When the working frequency of the Raspberry Pi reaches the maximum frequency limit, regardless of whether the heat dissipation temperature threshold is reached or not, the fan runs at full speed, which is more intelligent in response to heat
  • The program is based on Python, which is convenient for DIY



Install fan

When the Raspberry Pi is not powered on, connect the fan to pins 1 to 12 of the Raspberry Pi, as shown in the figure.

If the pins are installed incorrectly, the hardware may be damaged. So be sure to confirm the location and power on the Raspberry Pi again.

If you use it with a casing, please confirm whether the casing is compatible with the fan and Raspberry Pi. For example, the following case is compatible with Raspberry Pi 4B and fans. After assembly, the effect is as follows.


Enable SPI of Raspberry Pi

Run the following command in the terminal to enter the configuration interface.

sudo raspi-config

Select Interface Options-SPI to enable SPI. Restart the Raspberry Pi after completion.


Install Python library

The fan driver we provide includes intelligent fan speed control and RGB LED status display. RGB LED relies on apa102-pi library to drive. Therefore, in order to use the complete fan function, this library needs to be installed in advance. Of course, if you don't need the LED status display function, you don't need to install it, and just remove the code related to LED control from the driver code we provide.

Run the following command in the terminal.

sudo apt install -y python3-pip python3-rpi.gpio
sudo pip3 install apa102-pi


Fan driver

The fan driver is open source and can be run after downloading to the Raspberry Pi. Enter the following commands in the terminal.

sudo apt install -y git
cd ~
git clone https://github.com/nxez/rpi-fan
cd rpi-fan

We have prepared two source codes, rpi-fan.py is a fully functional version. rpi-fan-lite.py is a simplified version, without the RGB LED driver.

Enter the following command in the terminal to run

sudo python3 rpi-fan.py

or

sudo python3 rpi-fan-lite.py

To run in the background, add & after the command, for example:

sudo python3 rpi-fan.py &

Set up to run

Edit the rc.local file.

sudo nano /etc/rc.local

Add a line before exit 0 (the path of the script should be modified according to the actual situation):

sudo python3 /home/pi/rpi-fan/rpi-fan.py &

Appendix: Source code description

Taking the full version as an example, the following describes the configurable variables in the source code. If you encounter fan stalls, you can increase the value of speed_base appropriately according to the situation.

# The calculation formula of fan running speed, speed = base speed + (current temperature-temperature threshold) * speed unit increment.
speed = speed_base + (current_temp - threshold_temp) * speed_step

# Fan base speed, range 0 ~ 100。
speed_base = 70
# Rate unit increment.
speed_step = 1.5
# The temperature threshold for starting the fan, the default is 40 degrees.
threshold_temp = 40

# The color value displayed by the RGB LED. Different CPU temperatures correspond to different colors. The default sequence is blue, green, yellow, magenta, and red.
# The value uses RGB color value, from 0x000000 to 0xFFFFFF, the brightness of the color can also be reflected by changing the color value.
c_temp = [0x000008, 0x000800, 0x080800, 0x080008, 0x080000]

# The following settings are used to match the temperature and the LED color. Modify the upper c_temp and the lower temp adjustment to match, and you can set more temperature levels and LED colors by yourself.
c_temp_i = 4
if temp < 60:
    c_temp_i = 3
if temp < 55:
    c_temp_i = 2
if temp < 50:
    c_temp_i = 1
if temp < 40:
    c_temp_i = 0
TAG: Core3566002032 3.5 inch LCD Computer CPU GPU RAM Monitor PC USB Secondary Display Screen 2.13Inch E-Ink Raspberry Pi 5 PCM5122 I2S Audio Card DAC Also For PI4 /PI3 /Zero Series 3.4inch Round LCD HDMI Capacitive Touchscreen Display 800x800 For Raspberry Pi/Jetson Nano/mini PC Raspberry Pi 5 PCIe USB HUB 3.2 Gen1 HAT+ High Speed Pi5 7.5 inch Passive NFC e-Paper V2 BW Display 7.5inch E-ink Screen No Need Battery Wireless Powered Data Transfer For Mobile APP SpotPear Magnetic Encoder Servo Motor 120KG.CM 24V 360° RS485 High Precision And Large Torque RP2040 USB To CAN Pi 5 PCIe to M.2 ESP32-P4 ESP32-C6 Development Board RISC-V WiFi6 MIPI CSI Camera 7/10.1 inch DSI Display /RJ45 Ethernet /Mic /Audio Size Compatible with Raspberry Pi LuckFox MP2.5G Raspberry Pi 5 PCIe to 2.5G Ethernet HAT Pi5 RTL8125 ESP32 C3 Raspberry Pi 13.3 inch DSI MIPI Display 13.3inch LCD Capacitive TouchScreen 1920x1080 English Character Display Principle Development Board RS485 Bus