Control speed of fan

my DevTerm is A06. I have set the max temp in that file to 50, fan does not run. Does it only work on CM3?

for a06
EDIT /usr/local/bin/temp_fan_daemon_a06.py

MAX_TEMP=50000

50000 is 50 deg

and don’t install rpi package on A06
try

sudo apt update && apt install -y devterm-fan-daemon-cpi-a06
1 Like

thank you for the reply.
That a06 package was already installed, I just edited the wrong settings file.
I have now set the parameter to 40000 and rebooted. I can see the fan start turning but it stops after a few seconds despite htop showing 53 degrees.
Is htop showing a different temp sensor than the fan is using?

P.S.: I can see the fan turning now and then. I would have thought it would keep turning with 12 to 13 degrees above MAX_TEMP…

Even setting it to 20000 doesn‘t change the behaviour.

Is there a way to just have the fan run constantly on the A04? I have an issue with the screen developing errors after a few minutes of use and I am beginning to suspect it is caused by overheating.

1 Like

By changing the script to a lower temperature it should be always on.

I don’t think this is true, at least for the A06. I looked at the Python script and when its overheating it makes calls to turn the fan on (which has a sleep of 30 seconds, so I’m guessing it stays on that long) and then it immediately makes a call to turn the fan off with a sleep of 5 seconds. So if I’m reading the code correctly (for A06 one, haven’t looked at A04 script) the behavior whenever it it overheating is currently turn the fan on, then turn it off after 30 seconds, wait 5 seconds with it off, and then turn it on again if it’s still overheating.

That seems like a bug, but I haven’t edited the file yet since I’m.not sure if it actually is a bug or if it’s intended behavior. Seems weird though.

1 Like

Here’s the relevant code (with some functions in between removed, and my own comments added):

ONCE_TIME=30  # how long to keep the fan on in seconds
def fan_on():
    init_fan_gpio()
    os.popen("gpio write 41 1")
    time.sleep(ONCE_TIME) # fan is on, and we're sleeping for 30 sec
def fan_off():
    init_fan_gpio()
    os.popen("gpio write 41 0")
def fan_loop():
    while True:
        temps = glob.glob('/sys/class/thermal/thermal_zone[0-9]/')
        temps.sort()
        for var in temps:
            _f = os.path.join(var,"temp")
            #print( open(_f).read().strip("\n") )
            _t = open(_f).read().strip("\n")
            if isDigit(_t):
                if int(_t) > MAX_TEMP: 
                    fan_on() # it's hot so turn the fan on (for 30 sec)
                    fan_off() # but for some reason now we turn it off ?!?

        time.sleep(5)  # wait for 5 seconds, but fan is still off, even if hot!

Any script for A04? Seems there are only python files for a06 and cm3.

Do you have devterm-fan-daemon-cpi-a04 installed from apt? That should give you a script in /usr/local/bin

I tried lowering the fan trigger temperature in my script and it does not seem to take effect until after a reboot. I dropped the threshold temperature to 30C and the time to run the fan to 300 seconds because I wanted to achieve close to an “always on” functionality. Running at full load with 2 cores enabled, this dropped my temps by about 10C and I don’t have the fan shroud on yet. I will print a fan shroud this evening and look into possibly replacing the fan with another one altogether. This is on A0402.

when i type edit i receive the error no write permission for file. forgive my ignorance but how do i give myself write permissions?

Hey Jeremiah, welcome. What exactly are you trying to accomplish? Change the trigger temperature that the fan turns on that guu was talking about? The package to control the fan should be pre-installed and functioning. You do NOT need to edit this file unless you want to change the temp the fan turns on. The fan is near silent, and you really can’t tell when it’s running.

Let’s first make sure you have the package installed. Then you need to elevate your privileges on Linux to edit files not owned by you – that’s done by prepending “sudo” in front of the command you want to run. ‘sudo’ mean “super user, do this”.

sudo apt update && sudo apt install -y devterm-fan-daemon-cpi-a06
sudo nano /usr/local/bin/temp_fan_daemon_a06.py

The first command refreshes the database of packages available and installs the fan daemon, if needed. The second command opens the actual script that controls the fan using the editor nano.

Use the cursor keys to find the line “MAX_TEMP=XXXXXX”, backspace to remove the number and type in the new number. Now hit control-x. Type y to save. Now reboot.

yes i 3d printed a fan shroud but the device is shutting off whenever it gets too hot and i dont see the fan coming on so i am attempting to get it to come on earlier (perhaps something else is making it shut off but i always start from what i know and work backward)

-edit . i should also note it turns off whenever i attempt to play a video on youtube as well, so i may have other issues

-edit 2 fan works

1 Like

The command to change file permission is chmod

For write permission is chmod +w filename for executable permissions chmod +x filename

The FAN_EN transistor is connected to GPIO3_A0/MAC_TXD2/SPI4_RXD_d.
It’s not a hardware PWM pin, so no hardware speed control.

Workarounds:

  1. Software PWM.
    Do it from the kernel, expose it as software pwm so a real fancontrol program can pick it up.
    Won’t be too heavy – we can lower the frequency to 50Hz or even 10Hz.
    Technically, the current fan control script is a 85.7% PWM at 0.028Hz

  2. Use the 40pin GPIO connector to loopback a real PWM pin to pull the leveler.

  3. Use the GPIO connector from the keyboard to loopback a real PWM pin. Stupidly amusing.

1 Like

I got it working.

Proof of pwm fan ramping up:

Patches uploaded here:

To test fan speed control:

#!/bin/bash
cd /sys/class/pwm/pwmchip0
echo 0 > export
cd pwm0
# 50_000_000ns, 50ms period
echo 50000000 > period
# enable it...
echo 1 > enable
# ramp it...
for i in {20000000,30000000,35000000,40000000,42000000,44000000,46000000,47000000,48000000,49000000,50000000}
do
  echo $i
  echo $i > duty_cycle
  read a
done

Yet pwmconfig doesn’t detect it :joy:
Once we figure it out we can have fancontrol taking over (maybe more advanced fan control? the last steps in the ramps are rather exponential).

PWM-enabled fan control daemon:

Weekend project done in the first night :sunglasses:
Strangely satisfying.

2 Likes

I saw that you did a lot of work adding depreciated pwm-gpio codes.
I would like to know why you didn’t use gpio_fan module?

Also as you have added fan node then why not add thermal trip in dts itself so no need for a python based daemon.

I will give some time to this approach and see if I can get fan to work on kernel level instead of user level.

Thanks for the patches I was looking for the gpio pin used for fan on off.

Some Update :

Because I want pwm_fan instead for speed control, so the first thing to do is to make the system believe there’s an extra pwm.

Nice job on gpio fan, maybe these two can be plugged together?

1 Like

Does the fan have more than 1 speed?

How it’s pwn fan different unless it have multiple speeds?

Yes it does. It’s pwm, so you can have any speed between 0rpm and 6000rpm.