From 8e0637f3e349ddcb5bec2edc9768857956eca484 Mon Sep 17 00:00:00 2001 From: John Pauley Date: Wed, 3 May 2017 18:08:56 -0400 Subject: [PATCH] raspi INA3221 example --- examples/raspi_ina3221.go | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 examples/raspi_ina3221.go diff --git a/examples/raspi_ina3221.go b/examples/raspi_ina3221.go new file mode 100644 index 00000000..f3c630db --- /dev/null +++ b/examples/raspi_ina3221.go @@ -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() +}