Jump to content

How terrible is my python script for my GPIO?

Helpful Tech Witch

I still have no idea what Im doing with python, this script was made in about 2 hours of me learning python and reading through RPi.GPIO documentation.

Its going to run on boot with rc.local, once i can set it up. Other than that it runs fine.

import RPi.GPIO as GPIO
import time
from gpiozero import CPUTemperature

cpuTEMP = CPUTemperature()
power = 12
tempHIGH = 26
loop = 0

GPIO.setmode(GPIO.BCM)
GPIO.setup(power, GPIO.OUT)
GPIO.setup(tempHIGH, GPIO.OUT)

while loop == 0:
    GPIO.output(power, GPIO.HIGH)
    time.sleep(.2)
    GPIO.output(power, GPIO.LOW)
    tempNOW = (cpuTEMP.temperature)
    if tempNOW >= 80:
        GPIO.output(tempHIGH, GPIO.HIGH)
    else:
        GPIO.output(tempHIGH, GPIO.LOW)
    time.sleep(.8)

 

Is there anything super stupid I did?

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

as long as it works it's good enough.

 

i would probably say to increase the sleep time a bit more, given you at least have somewhat of a heatsink the temperature will be a very slow changing process, so about 5 seconds wouldnt be too extreme IMO.

Link to comment
Share on other sites

Link to post
Share on other sites

You never change the loop variable. So your while statement can be "while True:" and you can remove the loop variable.

 

I would have to read the documentation to get a better understanding of the rest. At a glance it makes sense.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, manikyath said:

as long as it works it's good enough.

 

i would probably say to increase the sleep time a bit more, given you at least have somewhat of a heatsink the temperature will be a very slow changing process, so about 5 seconds wouldnt be too extreme IMO.

THe sleep time is short to facilitate the blinking of one LED, thus the sleep times being short

And my heatsink is small enought that when i have a heavy load, the temperature can drop ~10c in less than a second

7 minutes ago, Pandur said:

You never change the loop variable. So your while statement can be "while True:" and you can remove the loop variable.

 

thats a good point

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×