Dht22

Iš Žinynas.
Jump to navigation Jump to search

61P84dhJ1sL. SL1000 .jpg

DHT22 sensorius gali matuoti temperatūrą ir oro drėmę patalpose, jį galima įsigyti čia.

RaspberryPI ir OrangePI sujungimas

PIN1 = +
PIN6 = - (GND)
PIN7 = DATA

Gpio portai aprašyti čia RaspberryPI.

Programavimo interfeisai

Golang

package main

import (
	"github.com/d2r2/go-dht"
        "fmt"
        "log"
        "flag"
)

var (
pin int
)

func main() {
        flag.IntVar(&pin, "pin", 6, "Specify pin for dht22 sensor")
        flag.Parse()
	// Read DHT11 sensor data from pin 4, retrying 10 times in case of failure.
	// You may enable "boost GPIO performance" parameter, if your device is old
	// as Raspberry PI 1 (this will require root privileges). You can switch off
	// "boost GPIO performance" parameter for old devices, but it may increase
	// retry attempts. Play with this parameter.
	// Note: "boost GPIO performance" parameter is not work anymore from some
	// specific Go release. Never put true value here.
        fmt.Printf("Testing pin: %d\n",pin)
	temperature, humidity, retried, err :=
		dht.ReadDHTxxWithRetry(dht.DHT22, pin, false, 10)
	if err != nil {
		log.Fatal(err)
	}
	// Print temperature and humidity
	fmt.Printf("Temperature = %v*C, Humidity = %v%% (retried %d times)\n",
		temperature, humidity, retried)
}

Su šia programa taip pat galime pratestuoti visus portus ir rasti sensorių, jeigu atmintinai nežinome GPIO numeravimo:

for ((i=1;i<=200;i++)); do ./read_dht -pin $i; done