Go package for reading temperature and humidity from DHT11, DHT22 and AM2302 sensors on Raspberry Pi
This package contains only one function for measuring temperature and humidity from DHT11, DHT22 and AM2302 sensors. The package uses a Go-adapted version of the WiringPi GPIO Library - Go WiringPi
Usage example
- Download and install the WiringPi GPIO library on your Raspberry Pi
- Create a Go file with the following content:
package main
import (
"fmt"
"gitfox.ru/victor/go-dht"
)
var (
pin = 7 // Pin number (GPIO_7)
)
func main() {
temperature, humidity, err := dht.ReadDHT(pin)
if err != nil {
fmt.Println("Read error!")
} else {
fmt.Printf("Temperature: &.1f °C\nHumidity: %.1f %%\n", temperature, humidity)
}
}
- Create a module file, for example,
dht-reader
:
go mod init dht-reader
- Build the program:
go get
go build
- Run your application to get the temperature and humidity.
Links
Description
Пакет Go для чтения температуры и влажности с датчиков DHT11, DHT22 и AM2302 на Raspberry Pi
Readme
69 KiB
Languages
Go
98.7%
Makefile
1.3%