Dht22: Skirtumas tarp puslapio versijų

Iš Žinynas.
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...)
 
 
(nerodoma 3 tarpinės versijos, sukurtos 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]].
 +
 +
= Programavimo interfeisai =
 +
 +
== Golang ==
 +
 +
<syntaxhighlight lang="go">
 +
/*
 +
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)
 +
}
 +
</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
  
PIN1 = +
 
PIN6 = - (GND)
 
PIN7 = DATA
 
  
 
[[Category:Hardware]]
 
[[Category:Hardware]]
 
[[Category:RaspberryPI]]
 
[[Category:RaspberryPI]]
 
[[Category:OrangePI]]
 
[[Category:OrangePI]]

Dabartinė 13:23, 17 sausio 2021 versija

61P84dhJ1sL. SL1000 .jpg

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