Skip to content

Commit 2abba37

Browse files
authored
Merge pull request #53 from SkUrRiEr/address_calc_define
Add a macro to calculate the I2C address based on the A0 and A1 pads
2 parents c179972 + 41ce68a commit 2abba37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Adafruit_INA219.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
#include <Adafruit_I2CDevice.h>
2323
#include <Wire.h>
2424

25+
/** calculated I2C address: 0 = GND, 1 = V+ **/
26+
/* The address is controlled by the A0 and A1 inputs on the INA219:
27+
*
28+
* Calculated address: b100ABCD
29+
* A0 controls C and D: GND = 00, V+ = 01, SDA = 10, SCL = 11
30+
* A1 controls A and B: GND = 00, V+ = 01, SDA = 10, SCL = 11
31+
*
32+
* E.g. if A0 is tied to ground and A1 is tied to V+,
33+
* the resulting address is b1000100 = 0x44
34+
*
35+
* SDA and SCL options aren't implemented.
36+
*/
37+
#define INA219_CALC_ADDRESS(INA_ADDR0, INA_ADDR1) \
38+
(0x40 | (INA_ADDR0 != 0 ? 0x01 : 0x00) | (INA_ADDR1 != 0 ? 0x04 : 0x00))
39+
2540
/** default I2C address **/
2641
#define INA219_ADDRESS (0x40) // 1000000 (A0+A1=GND)
2742

0 commit comments

Comments
 (0)