Skip to content

Fan does not start on RPi bootup  #10

Open
@ethanic17

Description

@ethanic17

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions