hybridgroup.gobot/examples/tinkerboard_mpl115a2.go

53 lines
987 B
Go
Raw Normal View History

// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/tinkerboard"
)
// Wiring
// PWR Tinkerboard: 1 (+3.3V, VCC), 2(+5V), 6, 9, 14, 20 (GND)
// I2C1 Tinkerboard: 3 (SDA-ws), 5 (SCL-gn)
// MPL115A2 plate: VDD (2.375..5.5V), GND, SDL, SDA
func main() {
board := tinkerboard.NewAdaptor()
mpl115a2 := i2c.NewMPL115A2Driver(board)
work := func() {
gobot.Every(2*time.Second, func() {
if press, err := mpl115a2.Pressure(); err != nil {
fmt.Println(err)
} else {
fmt.Println("Pressure [kPa]", press)
}
if temp, err := mpl115a2.Temperature(); err != nil {
fmt.Println(err)
} else {
fmt.Println("Temperature [°C]", temp)
}
fmt.Println("-------------")
})
}
robot := gobot.NewRobot("mpl115Bot",
[]gobot.Connection{board},
[]gobot.Device{mpl115a2},
work,
)
err := robot.Start()
if err != nil {
fmt.Println(err)
}
}