Dht22: Skirtumas tarp puslapio versijų
Jump to navigation
Jump to search
(nerodoma viena tarpinė versija, sukurta to paties naudotojo) | |||
4 eilutė: | 4 eilutė: | ||
== RaspberryPI ir OrangePI sujungimas == | == RaspberryPI ir OrangePI sujungimas == | ||
+ | Vietoje VCC naudosime GPIO pin'a į kurį paduosime VCC kai mums reikia arba recovery metu, norint perkrauti sensorių išjungiant ir įjungiant jam maitinimą (pagelbėja kai naudojami kiniški sensoriai). | ||
− | + | PIN19 = + | |
− | + | PIN39 = - (GND) | |
− | + | PIN26 = DATA | |
Gpio portai aprašyti čia [[RaspberryPI]]. | Gpio portai aprašyti čia [[RaspberryPI]]. | ||
16 eilutė: | 17 eilutė: | ||
<syntaxhighlight lang="go"> | <syntaxhighlight lang="go"> | ||
+ | /* | ||
+ | 2020 (c) \dev\null | ||
+ | */ | ||
+ | |||
package main | package main | ||
import ( | import ( | ||
+ | . "github.com/cyoung/rpi" | ||
"github.com/d2r2/go-dht" | "github.com/d2r2/go-dht" | ||
"fmt" | "fmt" | ||
"log" | "log" | ||
"flag" | "flag" | ||
+ | "time" | ||
) | ) | ||
var ( | var ( | ||
pin int | pin int | ||
+ | vcc int | ||
) | ) | ||
+ | |||
+ | func RecoveryPin(pin int) { | ||
+ | log.Printf("Powering off pin %d\n",pin) | ||
+ | PinMode(BoardToPin(pin), OUTPUT) | ||
+ | DigitalWrite(BoardToPin(pin), LOW) | ||
+ | log.Printf("Waiting 10 secondds...\n") | ||
+ | time.Sleep(time.Second*10) | ||
+ | PinMode(pin, OUTPUT) | ||
+ | DigitalWrite(BoardToPin(pin), HIGH) | ||
+ | log.Printf("Powering on pin %d\n",pin) | ||
+ | time.Sleep(time.Second*10) | ||
+ | return | ||
+ | } | ||
func main() { | func main() { | ||
− | flag.IntVar(&pin, "pin", | + | flag.IntVar(&pin, "pin", 7, "Specify pin for dht22 sensor") // GPIO porto tipas (Raspberry GPIO7, OrangePI PA21 todėl RaspberryPI rašome 7 o Orange rašome 21) |
+ | flag.IntVar(&vcc, "vcc", 19, "VCC pin for dht22 sensor recovery") // fizinis raspberrypi portas | ||
+ | check := flag.Bool("recovery", false,"Do a sensor recovery on startup") // ar daryti recovery startavimo metu, atjungiant maitinima | ||
flag.Parse() | flag.Parse() | ||
+ | log.Printf("Initializing wiring-pi interface...\n") | ||
+ | WiringPiSetup() | ||
// Read DHT11 sensor data from pin 4, retrying 10 times in case of failure. | // 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 | // You may enable "boost GPIO performance" parameter, if your device is old | ||
39 eilutė: | 64 eilutė: | ||
// Note: "boost GPIO performance" parameter is not work anymore from some | // Note: "boost GPIO performance" parameter is not work anymore from some | ||
// specific Go release. Never put true value here. | // specific Go release. Never put true value here. | ||
+ | if *check { | ||
+ | RecoveryPin(vcc) | ||
+ | } | ||
+ | |||
fmt.Printf("Testing pin: %d\n",pin) | fmt.Printf("Testing pin: %d\n",pin) | ||
temperature, humidity, retried, err := | temperature, humidity, retried, err := | ||
44 eilutė: | 73 eilutė: | ||
if err != nil { | if err != nil { | ||
log.Fatal(err) | log.Fatal(err) | ||
+ | RecoveryPin(vcc) | ||
} | } | ||
// Print temperature and humidity | // Print temperature and humidity |
Dabartinė 13:23, 17 sausio 2021 versija
DHT22 sensorius gali matuoti temperatūrą ir oro drėmę patalpose, jį galima įsigyti čia.
RaspberryPI ir OrangePI sujungimas[keisti]
Vietoje VCC naudosime GPIO pin'a į kurį paduosime VCC kai mums reikia arba recovery metu, norint perkrauti sensorių išjungiant ir įjungiant jam maitinimą (pagelbėja kai naudojami kiniški sensoriai).
PIN19 = + PIN39 = - (GND) PIN26 = DATA
Gpio portai aprašyti čia RaspberryPI.
Programavimo interfeisai[keisti]
Golang[keisti]
/*
2020 (c) \dev\null
*/
package main
import (
. "github.com/cyoung/rpi"
"github.com/d2r2/go-dht"
"fmt"
"log"
"flag"
"time"
)
var (
pin int
vcc int
)
func RecoveryPin(pin int) {
log.Printf("Powering off pin %d\n",pin)
PinMode(BoardToPin(pin), OUTPUT)
DigitalWrite(BoardToPin(pin), LOW)
log.Printf("Waiting 10 secondds...\n")
time.Sleep(time.Second*10)
PinMode(pin, OUTPUT)
DigitalWrite(BoardToPin(pin), HIGH)
log.Printf("Powering on pin %d\n",pin)
time.Sleep(time.Second*10)
return
}
func main() {
flag.IntVar(&pin, "pin", 7, "Specify pin for dht22 sensor") // GPIO porto tipas (Raspberry GPIO7, OrangePI PA21 todėl RaspberryPI rašome 7 o Orange rašome 21)
flag.IntVar(&vcc, "vcc", 19, "VCC pin for dht22 sensor recovery") // fizinis raspberrypi portas
check := flag.Bool("recovery", false,"Do a sensor recovery on startup") // ar daryti recovery startavimo metu, atjungiant maitinima
flag.Parse()
log.Printf("Initializing wiring-pi interface...\n")
WiringPiSetup()
// 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.
if *check {
RecoveryPin(vcc)
}
fmt.Printf("Testing pin: %d\n",pin)
temperature, humidity, retried, err :=
dht.ReadDHTxxWithRetry(dht.DHT22, pin, false, 10)
if err != nil {
log.Fatal(err)
RecoveryPin(vcc)
}
// 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