raspi INA3221 example

This commit is contained in:
John Pauley 2017-05-03 18:08:56 -04:00
parent 6b926ef037
commit 8e0637f3e3
1 changed files with 53 additions and 0 deletions

53
examples/raspi_ina3221.go Normal file
View File

@ -0,0 +1,53 @@
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 {
}
log.Printf("Ch 1 Shunt Voltage: %f", bv)
ma, err := ina.GetCurrent(i2c.INA3221Channel1)
if err != nil {
}
log.Printf("Ch 1 Current: %f", bv)
lv, err := ina.GetLoadVoltage(i2c.INA3221Channel1)
if err != nil {
}
log.Printf("Ch 1 Load Voltage: %f", bv)
})
}
robot := gobot.NewRobot("ina3221Robot",
[]gobot.Connection{r},
[]gobot.Device{ina},
work,
)
robot.Start()
}