AM2320 Temp/Humidity Sensor - Initial Add

pull/82/head
George Sexton 1 year ago
parent 867aad92a8
commit 840a355281

@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
//
// This package provides a driver for the AOSONG AM2320 Temperature/Humidity
// Sensor. This sensor is a basic, inexpensive sensor with reasonably good
// Sensor. This sensor is a basic, inexpensive i2c sensor with reasonably good
// accuracy for both temperature and humidity.
//
// The datasheet is located at:

@ -150,6 +150,7 @@ func TestSense(t *testing.T) {
func TestSenseContinuous(t *testing.T) {
readCount := 10
// make 10 copies of the single reading playback data.
pb := make([]i2ctest.IO, 0, len(pbSense)*10)
for range readCount {
pb = append(pb, pbSense...)

@ -0,0 +1,41 @@
// Copyright 2024 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package am2320
import (
"fmt"
"log"
"periph.io/x/conn/v3/i2c/i2creg"
"periph.io/x/conn/v3/physic"
"periph.io/x/host/v3"
)
func Example() {
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
log.Fatal(err)
}
// Open default I²C bus.
bus, err := i2creg.Open("")
if err != nil {
log.Fatalf("failed to open I²C: %v", err)
}
defer bus.Close()
// Create the Sensor
sensor, err := NewI2C(bus, SensorAddress)
if err != nil {
log.Fatal(err)
}
// Take a reading
env := physic.Env{}
err = sensor.Sense(&env)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Sensor Output: %s\n", env)
}
Loading…
Cancel
Save