[arm-allstar] Troubleshooting Fan Control Script

ve3rwj at winsystem.org ve3rwj at winsystem.org
Tue Nov 7 12:45:43 EST 2023


Hi.

 

I'm trying to troubleshoot a fan control script running on a Pi 4. The fan
runs continuously no matter what I do.

 

The fan has two connectors, a larger one plugged into pins 4 and 6, (power
and ground). The second connector, which checks temperature, is connected to
pin 8 (GPIO 14?)

 

The Pi is no longer on my desk here, but I added a line to the script to
print the temperature each time it loops. Presumably, if I get things right,
I should be able to turn the fan off and watch the temperature go up. turn
it back on and watch the temperature lower again. Currently, the fan is
running all the time and temp is about 46C.

What should I change in my script or try at the command prompt next?

 

Script follows:

 

#! /bin/bash

#

#       CPU temp monitor/fan control script.  VE3RWJ 2023-11-04

#

 

hi=60

lo=50

fanstate=unknown

FAN_BIT=14

 

function fan_on

{

gpio write $FAN_BIT 1

}

 

function fan_off

{

gpio write $FAN_BIT 0

}

 

while true ; do

 

temp=$(/opt/vc/bin/vcgencmd measure_temp | awk -F= '{j=$2 - 0; print j}' |
cut -b -2)

echo $temp

[ $temp -ge $hi ] && fanneeded=on

[ $temp -le $lo ] && fanneeded=off

if [ "$fanstate" != "$fanneeded" ] ; then

[ "$fanneeded" = "on" ] && fan_on

[ "$fanneeded" = "off" ] && fan_off

fanstate=$fanneeded

fi

sleep 5

done

 

 

 



More information about the ARM-allstar mailing list