Python3 GPIO issues

Hi there…

So, I’ve just installed DietPi on my Raspberry Pi 4, having run Raspian previously. I have a python script for controlling the fan, but it doesn’t work in DietPi it seems. I have installed the RPi.GPIO module for python. Can anyone suggest what I’ll need to change. Script is below (feel free to steal if useful!)

import RPi.GPIO as GPIO
import time
import subprocess

ON_THRESHOLD = 65 # (degrees Celsius) Fan kicks on at this temperature.
OFF_THRESHOLD = 50 # (degress Celsius) Fan shuts off at this temperature.
ledPin = 13 # define ledPin

def setup():
GPIO.setmode(GPIO.BOARD) # use PHYSICAL GPIO Numbering
GPIO.setup(ledPin, GPIO.OUT) # set the ledPin to OUTPUT mode
GPIO.output(ledPin, GPIO.LOW) # make ledPin output LOW level

def get_temp():
output =[‘vcgencmd’, ‘measure_temp’], capture_output=True)
temp_str = output.stdout.decode()
return float(temp_str.split(’=’)[1].split(’’’)[0])
except (IndexError, ValueError):
raise RuntimeError(‘Could not parse temperature output.’)

def loop():
while True:
temp = get_temp()
strtemp = str(temp)
xtime = time.strftime("%c")
if temp > ON_THRESHOLD:
GPIO.output(ledPin, GPIO.HIGH)
f = open("/home/dietpi/fancontrol/fanlog.txt", “a”)
f.write(" “)
elif temp < OFF_THRESHOLD:
GPIO.output(ledPin, GPIO.LOW)
time.sleep(60) # Wait for x seconds

def destroy():
GPIO.cleanup() # Release all GPIO

if name == ‘main’: # Program entrance
print (‘Program is starting … \n’)
except KeyboardInterrupt: # Press ctrl-c to end the program.


many thanks for your request. Did you activated serial console on dietpi-config?

Not sure if it helps but there was a user who tried to control a specific fan. He found a setup script on vendor page that install some stuff as well as set specific settings. Maybe you can have a look to the script. At the beginning your will find the relevant parts for setup and config.