Skip to content

Commit

Permalink
Sensor INA219: Use optional i2c_bus_num (#328)
Browse files Browse the repository at this point in the history
* Sensor INA219: Use optional i2c_bus_num
- Optional i2c_bus_num if autodetects fails (often on Pi4)
- shunt_ohms defaults to 0.1 (equals to R100, which is used in almost all boards)
* Default Bus is 1
  • Loading branch information
mschlenstedt authored Aug 3, 2023
1 parent 7872a2f commit 2bb2f94
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mqtt_io/modules/sensor/ina219.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# - gain (40, 80, 160 or 320) -> maximum shunt voltage (milli volt)
# Optional:
# - low_power: send ina219 to sleep between readings
# - i2c_bus_num: if auto detection fails - like on Pi4

# Output:
# - power (in watt)
Expand All @@ -30,7 +31,8 @@
REQUIREMENTS = ("pi-ina219",)
CONFIG_SCHEMA: CerberusSchemaType = {
"chip_addr": dict(type="integer", required=True),
"shunt_ohms": dict(type="float", required=False, empty=False, default=100),
"i2c_bus_num": dict(type="integer", required=False, default=1),
"shunt_ohms": dict(type="float", required=False, empty=False, default=0.1),
"max_amps": dict(type="float", required=False, empty=False),
"voltage_range": dict(
type="integer", required=False, empty=False, allowed=[16, 32], default=32
Expand Down Expand Up @@ -71,6 +73,7 @@ def setup_module(self) -> None:
self.config["shunt_ohms"],
max_expected_amps=self.config.get("max_amps"),
address=self.config["chip_addr"],
busnum=self.config["i2c_bus_num"],
)

## Configure ina sensor with range and gain from config or default
Expand Down

0 comments on commit 2bb2f94

Please sign in to comment.