x-c1 icon indicating copy to clipboard operation
x-c1 copied to clipboard

Fan does not start on RPi bootup

Open ethanic17 opened this issue 2 years ago • 2 comments

Hi, I am having trouble trying to get the PWM fan to spin on bootup. Whenever my Pi reboots I always have to run the fan-rpi.py file in order for the fan to start spinning again. I modified the file to my preferences but am not too experienced with Pi GPIO & the fan settings to debug what went wrong. The file works properly but I can't seem to get the file to run at startup. Here's what I have:

#!/usr/bin/python3

# DON'T use pigpiod library on Nov. 24 2022 by Harry Huang
#import pigpio
import RPi.GPIO as IO
import time
import subprocess

servo = 18

IO.setwarnings(False)
IO.setmode (IO.BCM)
IO.setup(servo,IO.OUT)
fan = IO.PWM(servo,2000)
fan.start(0)

def get_temp():
    output = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True)
    temp_str = output.stdout.decode()
    try:
        return float(temp_str.split('=')[1].split('\'')[0])
    except (IndexError, ValueError):
        raise RuntimeError('Could not get temperature')

while 1:
    temp = get_temp()                        # Get the current CPU temperature
    if temp > 60:                            # Check temperature threshhold, in degrees celcius
        fan.ChangeDutyCycle(100)             # Set fan duty based on temperature, 100 is max speed and 0 is min speed or off.
    elif temp > 50:
        fan.ChangeDutyCycle(90)
    elif temp > 40:
        fan.ChangeDutyCycle(60)
    elif temp > 30:
        fan.ChangeDutyCycle(30)
    else:
        fan.ChangeDutyCycle(20)
    time.sleep(5)                            # Sleep for 5 seconds

I also was wondering if it's possible to use this Noctua fan (https://www.amazon.com/gp/product/B00NEMGCIA/ref=ox_sc_act_title_1?smid=A1Z5H6ZGWCMTNX&psc=1), and it would run DC 5V correct? No PWM, so no fan control?

ethanic17 avatar Aug 18 '23 06:08 ethanic17

Hello, Here is my modified fan.py and running the python script in systemd daemon. I also created ansible tasks pigpio.yml which automates the installation of pigpio and fan.py installation

veerendra2 avatar Nov 29 '23 11:11 veerendra2

I mentioned a fix that worked for me in #7, have you tried that?

Tai-Mai avatar Jan 27 '24 19:01 Tai-Mai