现在的位置: 首页 > 综合 > 正文

用 BerryClip – 6 LED Board 显示树莓派的温度

2019年01月12日 ⁄ 综合 ⁄ 共 2110字 ⁄ 字号 评论关闭

用 BerryClip - 6 LED Board 显示树莓派的温度

BerryClip - 6 LED Board 是一个学习GPIO的开发板,适合我这样不懂硬件的童鞋,用python 控制6个LED灯,一个蜂鸣器,和一个开关

BerryClip

文档在这里
https://bitbucket.org/MattHawkinsUK/rpispy-berryclip/downloads/BerryClip%20User%20Guide.pdf

示例代码在这里
https://bitbucket.org/MattHawkinsUK/rpispy-berryclip/get/master.tar.gz

current

aa

说实话,我的板子和这个颜色不一致。红色和绿色是反的。不过我觉得手头这个板子的颜色是对的

有几个很有趣的示例,如berryclip_12.py 是莫尔斯码
还有berryclip_cpu_01.sh 是用LED灯显示CPU占用

不过这个berryclip_cpu_01.sh是shell脚本,好像写错了一点,代码和注释不一致

# BerryClip LED reference :
# LED 1  - Pin 7  - GPIO4
# LED 2  - Pin 11 - GPIO17
# LED 3  - Pin 15 - GPIO22
# LED 4  - Pin 19 - GPIO10
# LED 5  - Pin 21 - GPIO9
# LED 6  - Pin 23 - GPIO11
#
#--------------------------------------

# Create array of GPIO references
led[1]="11"
led[2]="9"
led[3]="10"
led[4]="22"
led[5]="17"
led[6]="4"

但是LED灯是反的,应该是这样

led[1]="4"
led[2]="17"
led[3]="22"
led[4]="10"
led[5]="9"
led[6]="11"

说是话shell脚本还是不如python脚本,所以修改了下,用来显示板子温度

温度的来源是 /sys/class/thermal/thermal_zone0/temp

#!/usr/bin/python
# Import required libraries
import RPi.GPIO as GPIO
import time
import string



# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)

# List of LED GPIO numbers
LedSeq = [4,17,22,10,9,11]

# Set up the GPIO pins as outputs and set False
print "Setup LED pins as outputs"
for x in range(6):
    GPIO.setup(LedSeq[x], GPIO.OUT)
    GPIO.output(LedSeq[x], False)

# 44925 -> 44
def getTemp():
    f = open("/sys/class/thermal/thermal_zone0/temp")   
    line = f.readline()     
    f.close()
    rawTemp = string.atoi(line)    
    return rawTemp / 1000

def resetAll():
    for i in range(6):
        GPIO.output(LedSeq[i], False)


# Light   leds    no
def setLedNo(x):
    GPIO.output(LedSeq[x], True)  
    time.sleep(0.2)

while True:
    temp = getTemp()
    print temp
    resetAll()
    if(temp < 50):
        setLedNo(0)
    elif (temp < 55):
        setLedNo(1)
    elif (temp < 60):
        setLedNo(2)
    elif (temp < 65):
        setLedNo(3)
    elif (temp < 70):
        setLedNo(4)
    else :
        setLedNo(5)

    time.sleep(50)

# Reset GPIO settings
GPIO.cleanup()

50度以上每5度一个灯,从绿到黄到红

第一张图亮的是第2个LED灯,说明是在50-55度之间

samba安装 补充

samba 还是很方便的,可以直接在windows上用notepad++编辑树莓派上的python代码。不过安装方式和ubuntu略有不同
感谢这个
http://www.eeboard.com/bbs/forum.php?mod=viewthread&tid=5473

apt-get install samba samba-common-bin

注意啦,要安装samba-common-bin, 这点和ubuntu不同,否则sampassed无法使用

设置所有目录全部对root开放,编辑 /etc/samba/smb.conf

[global]
netbios name = raspberry
security = user
[root]
path=/
valid users=root
public= yes
browseable = yes
writeable = yes

添加 samba 的 root用户

smbpasswd -a root

抱歉!评论已关闭.