hybridgroup.gobot/examples/raspi_ina3221.go

54 lines
869 B
Go
Raw Normal View History

2017-05-04 06:08:56 +08:00
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/raspi"
"log"
)
func main() {
r := raspi.NewAdaptor()
ina := i2c.NewINA3221Driver(r)
work := func() {
gobot.Every(5*time.Second, func() {
bv, err := ina.GetBusVoltage(i2c.INA3221Channel1)
if err != nil {
}
log.Printf("Ch 1 Bus Voltage: %f", bv)
sv, err := ina.GetShuntVoltage(i2c.INA3221Channel1)
if err != nil {
}
2017-05-04 06:23:27 +08:00
log.Printf("Ch 1 Shunt Voltage: %f", sv)
2017-05-04 06:08:56 +08:00
ma, err := ina.GetCurrent(i2c.INA3221Channel1)
if err != nil {
}
2017-05-04 06:23:27 +08:00
log.Printf("Ch 1 Current: %f", ma)
2017-05-04 06:08:56 +08:00
lv, err := ina.GetLoadVoltage(i2c.INA3221Channel1)
if err != nil {
}
2017-05-04 06:23:27 +08:00
log.Printf("Ch 1 Load Voltage: %f", lv)
2017-05-04 06:08:56 +08:00
})
}
robot := gobot.NewRobot("ina3221Robot",
[]gobot.Connection{r},
[]gobot.Device{ina},
work,
)
robot.Start()
}