Did a quick check and the problem is that the script reads/act on GPIO status, which breaks peppy_meter. Donāt have a quick solution in place. (Placed some test code below in this topic)
Get a silent FAN, so the noise is very low and you donāt need to bother on the coding part.
Or get an extension cable, so the hat can be place sideways and you donāt need a FAN.
bash script: call_fancontrol.sh
#!/bin/bash
while [ : ]
do
python3 /home/volumio/script/fancontrol.py
sleep 15
done
Python script: fancontrol.py
#!/usr/bin/env python3
import subprocess
import time
from gpiozero import OutputDevice
ON_THRESHOLD = 65 # (degrees Celsius) Fan kicks on at this temperature.
OFF_THRESHOLD = 55 # (degress Celsius) Fan shuts off at this temperature.
GPIO_PIN = 22 # Which GPIO pin you're using to control the fan.
def get_temp():
"""Get the core temperature.
Run a shell script to get the core temp and parse the output.
Raises:
RuntimeError: if response cannot be parsed.
Returns:
float: The core temperature in degrees Celsius.
"""
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 parse temperature output.')
# Validate the on and off thresholds
if OFF_THRESHOLD >= ON_THRESHOLD:
raise RuntimeError('OFF_THRESHOLD must be less than ON_THRESHOLD')
fan = OutputDevice(GPIO_PIN)
#while True:
temp = get_temp()
# Start the fan if the temperature has reached the limit and the fan
# isn't already running.
# NOTE: `fan.value` returns 1 for "on" and 0 for "off"
if temp > ON_THRESHOLD and not fan.value:
fan.on()
# Stop the fan if the fan is running and the temperature has dropped
# to 10 degrees below the limit.
elif fan.value and temp < OFF_THRESHOLD:
fan.off()
Respected Wheaten.Write the order of actions. I donāt understand anything about it.
In order:
1.
git clone GitHub - Howchoo/pi-fan-controller: Raspberry Pi fan controller.
2.
sudo apt-get install git
3.
sudo apt install python3-pip
4.
sudo pip3 install -r pi-fan-controller/requirements.txt
5.
./pi-fan-controller/script/install
6.
nano fancontrol.py
7.
#!/usr/bin/env python3
import subprocess
import time
from gpiozero import OutputDevice
ON_THRESHOLD = 60 # (degrees Celsius) Fan kicks on at this temperature.
OFF_THRESHOLD = 37 # (degress Celsius) Fan shuts off at this temperature.
GPIO_PIN = 16 # Which GPIO pin youāre using to control the fan.
def get_temp():
āāāGet the core temperature.
Run a shell script to get the core temp and parse the output.
Raises:
RuntimeError: if response cannot be parsed.
Returns:
float: The core temperature in degrees Celsius.
āāā
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 parse temperature output.ā)
# Validate the on and off thresholds
if OFF_THRESHOLD >= ON_THRESHOLD:
raise RuntimeError(āOFF_THRESHOLD must be less than ON_THRESHOLDā)
fan = OutputDevice(GPIO_PIN)
#while True:
temp = get_temp()
# Start the fan if the temperature has reached the limit and the fan
# isn't already running.
# NOTE: `fan.value` returns 1 for "on" and 0 for "off"
if temp > ON_THRESHOLD and not fan.value:
fan.on()
# Stop the fan if the fan is running and the temperature has dropped
# to 10 degrees below the limit.