Dienstag, 25. Februar 2014

raspbmc TemperaturSensor DS18B20

anleitungsmix aus:
http://www.it-adviser.net/raspberry-pi-temperaturmessung-mit-ds18b20-1-wire-sensor/
und:
http://www.danielhansen.net/2013/03/raspberry-pi-temperature-logging-using.html



sudo vi /etc/modules 
#einfuegen von 
wire 
w1-gpio 
w1-therm

manuelles laden mit "insmod wire" bzw
lsmod | grep w1

cat /sys/bus/w1/devices/10-0008028ea37b/w1_slave
2b 00 4b 46 ff ff 04 10 20 : crc=20 YES
2b 00 4b 46 ff ff 04 10 20 t=21500
21.5 grad :-)

wohin geht die reise?
graph, aufzeichnungen, ...

python script zum auslesen:

#!/usr/bin/python

import os, glob, time, sys, datetime

#set up the location of the sensor in the system
#device_folder = glob.glob('/sys/bus/w1/devices/28*')
device_folder = glob.glob('/sys/bus/w1/devices/10*')

#print device_folder[1]
#device_file = [device_folder[0] + '/w1_slave', device_folder[1] + '/w1_slave']
device_file = [device_folder[0] + '/w1_slave' ]
#print device_file


def read_temp_raw(): #a function that grabs the raw temperature data from the sensor
    f_1 = open(device_file[0], 'r')
    lines_1 = f_1.readlines()
    f_1.close()
    return lines_1


print read_temp_raw()

def read_temp(): #a function that checks that the connection was good and strips out the tempera                                  ture
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    #equals_pos = lines[1].find('t='), lines[3].find('t=')
    pos = equals_pos+2
    temp = float (lines[1][pos:] ) / 1000
    return temp

temp = read_temp() #get the temp
print 'date: ' + str(datetime.datetime.now())
print 'temp: ' + str(temp)

ps: thanks richi! ;-)

Keine Kommentare: