raspi INA3221 example
This commit is contained in:
parent
6b926ef037
commit
8e0637f3e3
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue