X-FAN40 PWM fan HAT
  Getting Started - software
   
 
  Home       Be Our Distributor      Custom Products      OEM/ODM      What We Do      Contact  
     
sudo re
      Software Tutorials   hardware   software  
     
 

This tutorial assumes you've already set up a Raspberry Pi 5 with Debian 13 (trixie) . For help installing the Debian-based OS on your Pi, check out the docs on Raspberrypi.org.

 

 

 
     
 
  1.0 Configuring EEPROM and testing the script
1.1 From the command line or Terminal window start by running the following command :
pi@raspberrypi ~ $  sudo rpi-eeprom-config -e
 

To configure the fan to power off after system shutdown, Add "POWER_OFF_ON_HALT=1" at the end of the file that reads like this:

 
1.2 Reboot your Raspberry Pi 5 to make the change take effect.
  pi@raspberrypi ~ $  sudo reboot
   
1.3 Update your system and install the required Python libraries:
  pi@raspberrypi ~ $  sudo apt-get update
  pi@raspberrypi ~ $  sudo apt-get upgrade -y
  pi@raspberrypi ~ $  sudo apt install python3-gpiozero
   
1.4 Download the script and enter the directories:
pi@raspberrypi ~ $  sudo git clone https://github.com/suptronics/x-fan40.git /opt/x-fan40
  pi@raspberrypi~ $  cd /opt/x-fan40
   
1.5 Run the script to start CPU temperature-based fan speed control
  pi@raspberrypi:/opt/x-fan40~ $  sudo python3 fan_controller.py
   
1.6 Run the script to monitor fan RPM
  pi@raspberrypi:/opt/x-fan40~ $ sudo python3 rpm_reading.py
   
2.0 Execute the fan auto-control script at Raspberry Pi boot
2.1 Create the service configuration file:
  pi@raspberrypi ~ $  sudo nano /etc/systemd/system/fan-controller.service
  Copy and paste the following configuration:
[Unit]
Description=Fan Controller
After=multi-user.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/python3 /opt/x-fan40/fan_controller.py
WorkingDirectory=/opt/x-fan40
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
   
  Save and exit (Ctrl+X, then Y, then Enter).
   
2.2 Reload systemd and Enable Service
  pi@raspberrypi~ $  sudo systemctl daemon-reload
  pi@raspberrypi~ $  sudo systemctl enable fan-controller.service
  pi@raspberrypi~ $  sudo systemctl start fan-controller.service
   
2.3 Check if the service is running properly:
  # Check service status
  pi@raspberrypi~ $  sudo systemctl status fan-controller.service
   
2.4 Reboot your Raspberry Pi to verify auto-start:
  pi@raspberrypi~ $  sudo reboot
   
  # After reboot, check if the service is running:
  pi@raspberrypi~ $ sudo systemctl status fan-controller.service
   
 
 
 
   
   
© 2025 SupTronics Technologies Limited, All Rights Reserved.