2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-06-10 19:18:29 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-06-10 19:18:29 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
|
2017-06-10 19:18:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
a := edison.NewAdaptor()
|
|
|
|
bme280 := i2c.NewBME280Driver(a, i2c.WithAddress(0x76))
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
t, e := bme280.Temperature()
|
|
|
|
fmt.Println("Temperature", t)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
p, e := bme280.Pressure()
|
|
|
|
fmt.Println("Pressure", p)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
a, e := bme280.Altitude()
|
|
|
|
fmt.Println("Altitude", a)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
h, e := bme280.Humidity()
|
|
|
|
fmt.Println("Humidity", h)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bme280bot",
|
|
|
|
[]gobot.Connection{a},
|
|
|
|
[]gobot.Device{bme280},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
err := robot.Start()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|