dht

package module
v0.0.0-...-7d909bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2017 License: MIT Imports: 3 Imported by: 3

README

dht

CGo client library for the DHT11/22 sensors on a Raspberry Pi 1 via GPIO Edit

go get -d -u github.com/pakohan/dht
go generate github.com/pakohan/dht

The code is copied over from adafruit. I removed the Python part and moved the conversion from bytes from the C library to Go (mainly for learning about the library a little bit while changing it).

Since there is a mmap library it seems that this could be written entirely in Go, but I think the garbage collector prevents us from getting correct results here. What is not supported yet is the RPi2 and BeagleBone Black, both have drivers in the repo mentioned above. What I could not test as well was the DHT22 sensor, but I tried to copy over that conversion part as well.

I think the more of the library is moved to Go, the more similarities will be between the different platforms, which means less C code to maintain. Maybe opening the right device file can be moved to Go as well.

usage

go get will throw an error when it is retrieved without the -d flag since it tries to build the library after downloading. This is not possible, because before we need some C compilation to do. Everything is done via go generate and make, so when you just want to use the library, running go generate will do the trick.

development

make is a wonderful build tool that just builds what has been changed. Just change any file, run go generate or make (whatever you prefer) and only the files that will be changed will get recompiled. First it compiles the .c files to .o files, then it will combine these object files to one static library called dht.a which then can be catched by the cgo tool to build this library.

Documentation

Index

Constants

View Source
const (
	SensorDHT11 = iota
	SensorDHT22
)

Variables

This section is empty.

Functions

func GetSensorData

func GetSensorData(stype, pin int) (humidity, temperature float32, err error)

GetSensorData calls ReadSensor for the given pin and returns the converted humidty and temparature depending on the sensor model.

func ReadSensor

func ReadSensor(pin int) (data [5]byte, err error)

ReadSensor returns the raw bit sequence read from the GPIO pin attached to the data pin of the DHT sensors.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL