BPI SoftPWM for a fan

5 2131
Hi everyone,
I have a BPI set up for media streaming etc. Now I want to cool the Pi with an external powered fan with softpwm. The PWM-Cable of the fan is attached to GPIO 0 (Phys. Pin11). Unfortunately, I have no expiriences with python or C/C++. Is there a script available for softpwm for a fan?
The fan is called Arctic Cooling AF
Max RPM 1500

Many thanks in advance for your help and sorry for my bad english :-)
Edited by tkaiser at Mon Jul 27, 2015 10:26

Based on the idea outlined in this post (defining a PWM pin and setting a value between 1 and 100) I wrote a script a few hours ago that uses a simple formula to derive the PWM value from the thermal value of the PMU (more realiable than the SoC's temperature):
  1. #!/bin/bash

  2. CheckTimeInSeconds=5
  3. MaxTemp=55000
  4. MinTemp=40000
  5. TempDiff=$(( ${MaxTemp} - ${MinTemp} ))

  6. while true ; do
  7.     read CurrentTemp </sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input
  8.     AdjustedTemp=$(( $(( ${CurrentTemp} - ${MinTemp} )) * 100 / ${TempDiff} ))
  9.     if [ ${AdjustedTemp} -lt 1 ]; then
  10.         AdjustedTemp=1
  11.     elif [ ${AdjustedTemp} -gt 100 ]; then
  12.         AdjustedTemp=100
  13.     fi
  14.     # AdjustedTemp=$(( 101 - ${AdjustedTemp} ))
  15.     echo ${AdjustedTemp} >/sys/class/pwm-sunxi/pwm0/duty_percent
  16.     sleep ${CheckTimeInSeconds}
  17. done
Copy the Code

The outcommented line "AdjustedTemp=$(( 101 - ${AdjustedTemp} ))" would invert the value. Now when temperature is below 40°C then duty_percent will be set to 1 and if temperature rises also this value will be increased. If you uncomment this line it would work the other way around: Setting duty_percent to 100 when 40°C or colder and decreasing it constantly when the temperature rises towards 55°C.

And maybe there's a mistake since values of 0 should also be possible to completely shut the fan off (easy to fix: just replace 1 with 0 two times and change 101 to 100)

tkaiser replied at Mon Jul 27, 2015 13:25
Based on the idea outlined in this post (d ...

Great job!

Many thanks for your script
Will test the script in this week or next, i have to do my school stuff etc.

Thanks, it worked perfectly as expected.

Use of latest featured designed tool is very helpful for professionals with their tasks are become easy in achievement. Online writing tasks are become easy with allassignmenthelp review reading and people get lots of benefits from them.

You have to log in before you can reply Login | Sign Up

Points Rules