Dht22: Skirtumas tarp puslapio versijų
Jump to navigation
Jump to search
(Naujas puslapis: 400px '''DHT22''' sensorius gali matuoti temperatūrą ir oro drėmę patalpose, jį galima [https://www.amazon.com/gp/product/B073F472JL/re...) |
|||
8 eilutė: | 8 eilutė: | ||
PIN6 = - (GND) | PIN6 = - (GND) | ||
PIN7 = DATA | PIN7 = DATA | ||
+ | |||
+ | = Programavimo interfeisai = | ||
+ | |||
+ | == Golang == | ||
+ | |||
+ | <syntaxhighlight lang="go"> | ||
+ | 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) | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | 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 | ||
+ | |||
[[Category:Hardware]] | [[Category:Hardware]] | ||
[[Category:RaspberryPI]] | [[Category:RaspberryPI]] | ||
[[Category:OrangePI]] | [[Category:OrangePI]] |
19:11, 29 vasario 2020 versija
DHT22 sensorius gali matuoti temperatūrą ir oro drėmę patalpose, jį galima įsigyti čia.
RaspberryPI ir OrangePI sujungimas
PIN1 = + PIN6 = - (GND) PIN7 = DATA
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