Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/sensor_ina2xx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Simple example with one TI INA226 sensor attached and using I2C interface.

This example should also work with other INA22X and INA23X chips as well.
This example should also work with other INA2XX chips as well.
4 changes: 3 additions & 1 deletion examples/sensor_ina2xx/zigbee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sensors:
- type: ina2xx
# Must specify which model of sensor is being used.
# Note that currently only INA226 was tested,
# but other INA22X and INA23X should work as well.
# but other INA2XX should work as well.
model: ina226
# We also need to tell which I2C bus to use.
# It must be defined in board.i2c configuration,
Expand All @@ -29,6 +29,8 @@ sensors:
# It tells how many measurements sensor will
# use to average and return as result.
# Can be from 1 to 1024, as a power of 2 (so 1, 2, 4, 8, 16, ...).
#
# Does nothing if model is 'ina219'.
avg: 4
# Reuiqred configuration.
# Value in milliohms of shunt resistor used together
Expand Down
29 changes: 25 additions & 4 deletions sensor/ti/ina2xx.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (i *INA2XX) ApplyOverlay(overlay *dt.DeviceTree) error {

// 1 lsb step in microvolts.
LsbUvForModel := map[string]float32{
"ina219": 10, // 10 uV
"ina226": 2.5, // 2.5 uV
"ina228": 0.3125, // 312.5 nV, ADCRANGE = 0
"ina230": 2.5, // 2.5 uV
Expand Down Expand Up @@ -134,13 +135,18 @@ func (i *INA2XX) ApplyOverlay(overlay *dt.DeviceTree) error {
dt.NewProperty(dt.PropertyNameCompatible, dt.Quoted("ti,"+i.Model)),

dt.NewProperty("reg", dt.Angled(dt.String(i.I2C.Reg()))),
dt.NewProperty("avg-count", dt.FromValue(i.Avg)),
dt.NewProperty("rshunt-micro-ohms", dt.Angled(dt.String(shuntMicroOhmsStr))),
dt.NewProperty("current-lsb-microamps", dt.Angled(dt.String(currentMicroAmpsStr))),
},
}

i2c.AddNodes(inaNode)
var modelProps []dt.Property
// INA219 needs some other (older?) properties
if i.Model == "ina219" {
modelProps = i.dtProperties_ina219(shuntMicroOhmsStr, currentMicroAmpsStr)
} else {
modelProps = i.dtProperties_ina2xx(shuntMicroOhmsStr, currentMicroAmpsStr)
}

i2c.AddNodes(inaNode.AddProperties(modelProps...))

return nil
}
Expand All @@ -151,3 +157,18 @@ func (*INA2XX) Extenders() []generator.Extender {
extenders.ElectricalMeasurement{},
}
}

func (i *INA2XX) dtProperties_ina219(shuntUOhms, currentUAmps string) []dt.Property {
return []dt.Property{
dt.NewProperty("shunt-milliohm", dt.Angled(dt.String(shuntUOhms))),
dt.NewProperty("lsb-microamp", dt.Angled(dt.String(currentUAmps))),
}
}

func (i *INA2XX) dtProperties_ina2xx(shuntUOhms, currentUAmps string) []dt.Property {
return []dt.Property{
dt.NewProperty("avg-count", dt.FromValue(i.Avg)),
dt.NewProperty("rshunt-micro-ohms", dt.Angled(dt.String(shuntUOhms))),
dt.NewProperty("current-lsb-microamps", dt.Angled(dt.String(currentUAmps))),
}
}