Documentation
¶
Index ¶
- Constants
- Variables
- func ModeTriggered(m Mode) bool
- type BusADC
- type BusVoltageRange
- type Calibration
- type Config
- type Device
- func (d *Device) BusVoltage() (voltage int16, err error)
- func (d *Device) Configure() (err error)
- func (d *Device) Current() (current float32, err error)
- func (d *Device) Measurements() (busVoltage int16, shuntVoltage int16, current float32, power float32, ...)
- func (d *Device) Power() (power float32, err error)
- func (d *Device) ReadConfig() (config Config, err error)
- func (d *Device) ReadRegister(reg uint8) (val int16, err error)
- func (d *Device) SetConfig(config Config)
- func (d *Device) ShuntVoltage() (voltage int16, err error)
- func (d *Device) Trigger() (err error)
- func (d *Device) WriteRegister(reg uint8, val uint16) error
- type ErrConfigMismatch
- type ErrNotReady
- type ErrOverflow
- type Mode
- type PGA
- type ShuntADC
Constants ¶
const ( RegConfig uint8 = 0x0 RegShuntVoltage uint8 = 0x1 RegBusVoltage uint8 = 0x2 RegPower uint8 = 0x3 RegCurrent uint8 = 0x4 RegCalibration uint8 = 0x5 )
const Address = 0x40
The default I2C address for this device.
Variables ¶
var ( // Config32V2A is a configuration for a 32V 2A range. Config32V2A = Config{ BusVoltageRange: Range32V, PGA: PGA8, BusADC: ADC12, ShuntADC: SADC12, Mode: ModeContShuntBus, Calibration: Calibration16V400mA, CurrentDivider: 10.0, PowerMultiplier: 2.0, } // Config32V1A is a configuration for a 32V 1A range. Config32V1A = Config{ BusVoltageRange: Range32V, PGA: PGA8, BusADC: ADC12, ShuntADC: SADC12, Mode: ModeContShuntBus, Calibration: Calibration32V1A, CurrentDivider: 25.0, PowerMultiplier: 0.8, } // Config16V400mA is a configuration for a 16V 400mA range. Config16V400mA = Config{ BusVoltageRange: Range16V, PGA: PGA1, BusADC: ADC12, ShuntADC: SADC12, Mode: ModeContShuntBus, Calibration: Calibration16V400mA, CurrentDivider: 20.0, PowerMultiplier: 1.0, } )
Configurations from https://github.com/adafruit/Adafruit_INA219/blob/master/Adafruit_INA219.cpp
Functions ¶
func ModeTriggered ¶
ModeTriggered returns true if the mode is a triggered mode.
Types ¶
type BusVoltageRange ¶
type BusVoltageRange int8
BusVoltageRange is the bus voltage range.
const ( Range16V BusVoltageRange = 0 // 0-16V Range32V BusVoltageRange = 1 // 0-32V )
func (BusVoltageRange) RegisterValue ¶
func (r BusVoltageRange) RegisterValue() uint16
type Calibration ¶
type Calibration uint16
Calibration is the calibration register for the INA219. Values from: https://github.com/adafruit/Adafruit_INA219/blob/master/Adafruit_INA219.cpp
const ( Calibration32V2A Calibration = 4096 Calibration32V1A Calibration = 10240 Calibration16V400mA Calibration = 8192 )
func (Calibration) RegisterValue ¶
func (c Calibration) RegisterValue() uint16
type Config ¶
type Config struct {
// BusVoltageRange sets the bus voltage range.
BusVoltageRange BusVoltageRange
// PGA sets the programmable gain amplifier.
PGA PGA
// BusADC sets the bus ADC resolution.
BusADC BusADC
// ShuntADC sets the shunt ADC resolution.
ShuntADC ShuntADC
// Mode sets the operating mode.
Mode Mode
// Calibration sets the calibration value for the expected
// voltage and current values.
Calibration Calibration
// 1000 / uA per bit
CurrentDivider float32
// 1mW per bit
PowerMultiplier float32
}
func (*Config) RegisterValue ¶
RegisterValue returns the register value of the configuration.
type Device ¶
type Device struct {
Address uint16
// contains filtered or unexported fields
}
An INA219 device.
func New ¶
Create a new INA219 device with the default configuration and the given I2C bus at the default address.
Set Address after New to change the address.
Call Configure after New to write the configuration to the device. If you don't call Configure, the device may have a different configuration and the power divider and current multiplier are probably wrong.
func (*Device) BusVoltage ¶
BusVoltage reads the "bus" voltage in millivolts.
It returns an error if the value is invalid due to overflow or if the conversion is not ready yet. In a continuous mode there should always be a measurement available after the device is ready. See above notes on Trigger.
func (*Device) Measurements ¶
func (d *Device) Measurements() ( busVoltage int16, shuntVoltage int16, current float32, power float32, err error, )
Measurements reads the bus voltage, shunt voltage, current, and power from the device.
func (*Device) ReadConfig ¶
Read the configuration from the device.
func (*Device) ReadRegister ¶
Read a register from the device.
func (*Device) SetConfig ¶
Set the configuration for the device. This only changes the configuration in memory, not on the device. Call Configure to write the configuration to the device.
func (*Device) ShuntVoltage ¶
ShuntVoltage reads the "shunt" voltage in 100ths of a millivolt.
func (*Device) Trigger ¶
Trigger a conversion. This is only necessary if the device is in trigger mode. In continuous mode (the default), the device will automatically trigger conversions and this has no effect. See config.go.
Triggering a conversion or reading the "power" register resets the conversion ready bit.
type ErrConfigMismatch ¶
type ErrConfigMismatch struct{}
func (ErrConfigMismatch) Error ¶
func (e ErrConfigMismatch) Error() string
type ErrNotReady ¶
type ErrNotReady struct{}
func (ErrNotReady) Error ¶
func (e ErrNotReady) Error() string
type ErrOverflow ¶
type ErrOverflow struct{}
func (ErrOverflow) Error ¶
func (e ErrOverflow) Error() string
type Mode ¶
type Mode int8
Mode is the operating mode.
const ( ModePowerDown Mode = 0 // power-down ModeTrigShunt Mode = 1 // triggered shunt voltage ModeTrigBus Mode = 2 // triggered bus voltage ModeTrigShuntBus Mode = 3 // triggered shunt and bus voltage ModeADCOff Mode = 4 // ADC off ModeContShunt Mode = 5 // continuous shunt voltage ModeContBus Mode = 6 // continuous bus voltage ModeContShuntBus Mode = 7 // continuous shunt and bus voltage )
const ModeTriggeredMask Mode = 0x4
ModeTriggered is a mask for triggered modes.