Warning: goina219 is not ready for primetime!
Goina219 is a simple golang package for configuring and reading the INA219 Bidirectional Current/Power Monitor over I2C.
It is currently only available for *nix systems as it leverages the github.com/NeuralSpaz/i2c package for I2C.
- Go (tested on 1.12.1, may work on older)
- NeuralSpaz I2C: https://github.com/NeuralSpaz/i2c
With the dependancies installed, simply use:
go get github.com/jeffalyanak/goina219
Usage is very simple and an example is included in the example/ directory.
A config should be generated:
config := ina219.Config(
ina219.Range32V,
ina219.Gain320MV,
ina219.Adc12Bit,
ina219.Adc12Bit,
ina219.ModeContinuous,
)And an INA219 struct initialized:
myINA219, err := ina219.New(
0x40, // ina219 address
0x00, // i2c bus
0.01, // Shunt resistance in ohms
config,
)
if err != nil {
panic(fmt.Sprintf("%v", err))
}The read function can be called:
err := ina219.Read(myINA219)
if err!= nil {
// error
}Power and current can now be accessed from the struct:
fmt.Printf(
"Power: %fw, Current: %fa, Voltage: %fv, Shunt: %fv",
myINA219.Power,
myINA219.Current,
myINA219.Bus,
myINA219.Shunt,
)| Range | Parameter |
|---|---|
| 16V | goina219.Range16V |
| 32V | goina219.Range32V |
| Gain | Parameter |
|---|---|
| 40mV | goina219.Gain40MV |
| 80mV | goina219.Gain80MV |
| 160mV | goina219.Gain160MV |
| 320mV | goina219.Gain320MV |
| Samples | Bit-depth | Sample Time | Parameter |
|---|---|---|---|
| 1 | 9-bit | 84μs | goina219.Adc9Bit |
| 1 | 10-bit | 148μs | goina219.Adc10Bit |
| 1 | 11-bit | 276μs | goina219.Adc11Bit |
| 1 | 12-bit | 532μs | goina219.Adc12Bit |
| 2 | 12-bit | 1060μs | goina219.Adc2Samp |
| 4 | 12-bit | 2130μs | goina219.Adc4Samp |
| 8 | 12-bit | 4260μs | goina219.Adc8Samp |
| 16 | 12-bit | 8510μs | goina219.Adc16Samp |
| 32 | 12-bit | 17020μs | goina219.Adc32Samp |
| 64 | 12-bit | 34050μs | goina219.Adc64Samp |
| 128 | 12-bit | 68100μs | goina219.Adc128Samp |
Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.