adafruit / Adafruit_INA219

INA219 Current Sensor
Other
204 stars 145 forks source link

Add a macro to calculate the I2C address based on the A0 and A1 pads #53

Closed SkUrRiEr closed 2 years ago

SkUrRiEr commented 2 years ago

This module and derivatives of it have pads broken out to set the A0 and A1 pins to either ground or V+, and while the way this adjusts the I2C address is explained in the documentation, the library doesn't document this or provide any way to calculate the address.

This adds a separate macro to perform the address calculations, and adds a brief explanation of how the address is calculated.

I've not modified the existing address #define as it's useful to have the exact number visible for IDEs who show that.

This has been tested by verifying that it produces the correct addresses according to the documentation, but not on actual hardware as my only INA219 board is in-use with a solder bridge on the A0 pads.

ladyada commented 2 years ago

hiya, its non-standard but seems harmless, please dont use A0 / A1 - those are special names for arduino IDE, can use INA_ADDR0 and INA_ADDR1 :)

SkUrRiEr commented 2 years ago

:facepalm: Good point. I even checked that it did the right thing with the standard LOW and HIGH constants and didn't even think of this.