Benutzer-Werkzeuge

Webseiten-Werkzeuge


temperatur_sensor

Temperatur Senor DS18B20

Prepare Pi

sudo apt-get install git-core

git clone git://git.drogon.net/wiringPi



cd wiringPi

git pull origin

./build

Test WiringPi

gpio -v

gpio readall

Init

load driver

sudo vi /boot/config.txt

#add line

dtoverlay=w1-gpio

After Login

sudo modprobe w1-gpio 

sudo modprobe w1_therm

Read sensor

ls -l /sys/bus/w1/devices/

Sensoren

DS18B20

Wasserdicht

Anschlüsse:

Schwarz = GND, Rot = VCC, Gelb = Data 

http://192.168.1.21/dokuwiki/lib/exe/fetch.php?media=ds18b20_wasserfest_beschreibung_und_anschluesse.pdf

Beschreibung siehe DS18B20 Wasserdicht und Beschreibung

Viele verschiedene Sensoren

SHT3x SHTC1

DHT22

DHT11

dht11_details.pdf http://www.geeetech.com/wiki/index.php/Electric_thermometer_by_using_DHT11_sensor_module

Kalibrierung

Sensor# Feutigkeit Temperatur Id
1 34 28
2 34 24
3 35 24
4 34 24
5 34 25
6 35 26
7 fehlerhaft ablöten
# /etc/modules
w1-gpio pullup=1
w1-therm
# /boot/config.txt
device_tree=
#dtoverlay=w1-gpio

python code for dht11 sensor

use Adafruit DHT

Install

wget http://goo.gl/oadpl -O Adafruit_DHT
sudo cp Adafruit_DHT /usr/bin/

Run

General call sudo Adafruit_DHT {11|12} {gpio}
sudo Adafruit_DHT 11 4

expected output like

Using pin #17Data (40): 0x28 0x0 0x18 0x0 0x40
Temp = 24 *C, Hum = 40 %

use own code

    import RPi.GPIO as GPIO
    import time

    def bin2dec(string_num):
        return str(int(string_num, 2))

    data = []

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(4,GPIO.OUT)
    GPIO.output(4,GPIO.HIGH)
    time.sleep(0.025)
    GPIO.output(4,GPIO.LOW)
    time.sleep(0.02)

    GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    for i in range(0,500):
        data.append(GPIO.input(4))

    bit_count = 0
    tmp = 0
    count = 0
    HumidityBit = ""
    TemperatureBit = ""
    crc = ""

    try:
       while data[count] == 1:
          tmp = 1
          count = count + 1

       for i in range(0, 32):
          bit_count = 0

          while data[count] == 0:
             tmp = 1
             count = count + 1

          while data[count] == 1:
             bit_count = bit_count + 1
             count = count + 1

          if bit_count > 3:
             if i>=0 and i<8:
                HumidityBit = HumidityBit + "1"
             if i>=16 and i<24:
                TemperatureBit = TemperatureBit + "1"
          else:
             if i>=0 and i<8:
                HumidityBit = HumidityBit + "0"
             if i>=16 and i<24:
                TemperatureBit = TemperatureBit + "0"

    except:
       print "ERR_RANGE"
       exit(0)

    try:
       for i in range(0, 8):
          bit_count = 0

          while data[count] == 0:
             tmp = 1
             count = count + 1

          while data[count] == 1:
             bit_count = bit_count + 1
             count = count + 1

          if bit_count > 3:
             crc = crc + "1"
          else:
             crc = crc + "0"
    except:
       print "ERR_RANGE"
       exit(0)

    Humidity = bin2dec(HumidityBit)
    Temperature = bin2dec(TemperatureBit)

    if int(Humidity) + int(Temperature) - int(bin2dec(crc)) == 0:
       print Humidity
       print Temperature
    else:
       print "ERR_CRC"
temperatur_sensor.txt · Zuletzt geändert: von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki