orange pi zero gpio fan set

简介

终于下定决心购买orangepizero其实自已经有raspberry2,3了所以购买不购买orangpi其实是比较纠结的因为毕竟orange社区不如raspberry
的,主要还是怕国产硬件不过关。不过买回来一段时间还好各项运行都还算不错也没出什么问题,还安装上gentoo设置了风扇,现在就写篇文章记录下。

设置orange_pi_zero原理

orange_pi_zero通过gpio控制三级管达到一定温度就开让风扇转动。低于某温度就停止。推荐使用3.3v风扇,因为orangpi电源要求2A本身wifi
也是要求3.3v,5v的风扇估计电压会不稳定。

orang_pi_zero gpio针脚安装以及针脚图

-安装WiringOP
WiringOP

gpiolink
1
2
3
4

-查看针脚定义

```gpio readall

-针脚图对应机器实际图形。
logo

-S8050三级管示意图原理

三级管平的那面面向自己如下图,

logo

发射级接地线,风扇红线接5V针脚,基极接GPIO7,集电极接风扇黑线。

Shell 脚本控制风扇

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
#Here i set my objective in deg celcius
obj=44

#date to log the fan state history
time=$(date +%d\/%m\/%y\ %H\:%M)

#putting my 2 cpu temperatures values in variables
temp1=$(cat /sys/devices/virtual/thermal/thermal_zone1/temp)
temp2=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)
#do and average of the two temperatures
temp=$((($temp1+$temp2)/2))
echo $temp
#set the pin 7 as an output
/usr/local/bin/gpio mode 7 out
#if greater or equal to the objective put the gpio state to 1
if [ $temp -ge $obj ]; then
/usr/local/bin/gpio mode 7 out
/usr/local/bin/gpio write 7 1
echo "$time $temp fan 1">>/root/fan

#if not greater or equal , then put the gpio7 state to 0
else
/usr/local/bin/gpio write 7 0
echo "$time $temp fan 0">>/root/fan
fi

crontab -e

* * * * * /root/fan-control.sh


raspberry python脚本控制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import RPi.GPIO as GPIO
import time
import commands

T_HIGH = 50
T_LOW = 45
fan_pin = 12
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(fan_pin, GPIO.OUT)

def get_gpu_temp():
gpu_temp = commands.getoutput( '/opt/vc/bin/vcgencmd measure_temp' ).replace( 'temp=', '' ).replace( '\'C', '' )
return float(gpu_temp)

while 1:
gpu_temp_loop = get_gpu_temp()
print 'GPU temp:', gpu_temp_loop,'C'
if gpu_temp_loop > T_HIGH:
GPIO.output(fan_pin, 1)
elif gpu_temp_loop < T_LOW:
GPIO.output(fan_pin, 0)
time.sleep(5)

参考

[shell脚本地址][http://www.d0wn.com/orange-pi-zero-the-battle-against-heat/]
[raspberry python脚本][http://www.eeboard.com/bbs/forum.php?mod=viewthread&tid=94763]