flav1972 / ArduinoINA219

An Arduino library for the INA219 I2C current monitor
17 stars 16 forks source link

Interpret bus voltage as uint16_t #13

Closed twischer closed 3 years ago

twischer commented 3 years ago

Without this patch values >2^15 will be interpreted as negative values. Therefore the right shift in INA219::busVoltage() will do a sign extension. This issue was seen on ESP8266 when measuring voltages above 16V.

In the Arduino Adafruit_INA219 library uint16_t is used for the bus voltage similar to this patch. See https://github.com/adafruit/Adafruit_INA219/blob/2.1.0/Adafruit_INA219.cpp#L78