ina219

package
v3.6.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Example
package main

import (
	"fmt"
	"log"

	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/experimental/devices/ina219"
	"periph.io/x/periph/host"
)

func main() {
	// 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)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

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

DefaultOpts is the recommended default options.

Functions

This section is empty.

Types

type Dev

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

Dev is a handle to the ina219 sensor.

func New

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

New opens a handle to an ina219 sensor.

func (*Dev) Sense

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

Sense reads the power values from the ina219 sensor.

type Opts

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

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

PowerMonitor represents measurements from ina219 sensor.

func (PowerMonitor) String

func (p PowerMonitor) String() string

String returns a PowerMonitor as string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL