Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fan does not start on RPi bootup #10

Open
ethanic17 opened this issue Aug 18, 2023 · 2 comments
Open

Fan does not start on RPi bootup #10

ethanic17 opened this issue Aug 18, 2023 · 2 comments

Comments

@ethanic17
Copy link

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?

@veerendra2
Copy link

veerendra2 commented Nov 29, 2023

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

@Tai-Mai
Copy link

Tai-Mai commented Jan 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants