periph: periph.io/x/periph/experimental/devices/ina219 Index | Examples | Files

package ina219

import "periph.io/x/periph/experimental/devices/ina219"

Package ina219 controls a Texas Instruments ina219 high side current, voltage and power monitor IC over an i2c bus.

Calibration

Calibration is recommended for accurate current and power measurements. Voltage measurements do not require sensor calibration. To calibrate, measure the actual value of the shunt resistor.

Datasheet

http://www.ti.com/lit/ds/symlink/ina219.pdf

Code:

// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
    log.Fatal(err)
}

// Open default I²C bus.
bus, err := i2creg.Open("")
if err != nil {
    log.Fatalf("failed to open I²C: %v", err)
}
defer bus.Close()

// Create a new power sensor.
sensor, err := ina219.New(bus, &ina219.DefaultOpts)
if err != nil {
    log.Fatalln(err)
}

// Read values from sensor.
measurement, err := sensor.Sense()

if err != nil {
    log.Fatalln(err)
}

fmt.Println(measurement)

Index

Examples

Package Files

doc.go ina219.go

Variables

var DefaultOpts = Opts{
    Address:       0x40,
    SenseResistor: 100 * physic.MilliOhm,
    MaxCurrent:    3200 * physic.MilliAmpere,
}

DefaultOpts is the recommended default options.

type Dev Uses

type Dev struct {
    // contains filtered or unexported fields
}

Dev is a handle to the ina219 sensor.

func New Uses

func New(bus i2c.Bus, opts *Opts) (*Dev, error)

New opens a handle to an ina219 sensor.

func (*Dev) Sense Uses

func (d *Dev) Sense() (PowerMonitor, error)

Sense reads the power values from the ina219 sensor.

type Opts Uses

type Opts struct {
    Address       int
    SenseResistor physic.ElectricResistance
    MaxCurrent    physic.ElectricCurrent
}

Opts holds the configuration options.

Slave Address

Depending which pins the A1, A0 pins are connected to will change the slave address. Default configuration is address 0x40 (both pins to GND). For a full address table see datasheet.

type PowerMonitor Uses

type PowerMonitor struct {
    Shunt   physic.ElectricPotential
    Voltage physic.ElectricPotential
    Current physic.ElectricCurrent
    Power   physic.Power
}

PowerMonitor represents measurements from ina219 sensor.

func (PowerMonitor) String Uses

func (p PowerMonitor) String() string

String returns a PowerMonitor as string

Package ina219 imports 7 packages (graph) and is imported by 1 packages. Updated 2019-01-03. Refresh now. Tools for package owners.