SparkFun INA2XX Arduino Library  v1.0.0-3-gc9007d6
Arduino Library for the SparkFun Qwiic Power Monitor (INA228 / INA237)
Loading...
Searching...
No Matches
SparkFun_INA2XX.h
Go to the documentation of this file.
1
45#pragma once
46
47// clang-format off
48#include <SparkFun_Toolkit.h>
49#include "sfTk/sfDevINA228.h"
50#include "sfTk/sfDevINA237.h"
51#include <Arduino.h>
52// clang-format on
53
69{
70 public:
72 {
73 }
74
90 bool begin(uint8_t address = kI2CAddress, TwoWire &wirePort = Wire)
91 {
92 if (_theI2CBus.init(wirePort, address) != ksfTkErrOk)
93 return false;
94
95 if (sfDevINA2XX::begin(&_theI2CBus) != ksfTkErrOk)
96 return false;
97
98 return isConnected();
99 }
100
111 bool isConnected(void)
112 {
113 if (_theI2CBus.ping() != ksfTkErrOk)
114 return false;
115
116 uint16_t devID = 0;
117 if (getDeviceID(devID) != ksfTkErrOk)
118 return false;
119
120 return ((devID & kDeviceIDMask) == kINA228DeviceIDValue);
121 }
122
123 private:
124 sfTkArdI2C _theI2CBus;
125};
126
140{
141 public:
143 {
144 }
145
161 bool begin(uint8_t address = kI2CAddress, TwoWire &wirePort = Wire)
162 {
163 if (_theI2CBus.init(wirePort, address) != ksfTkErrOk)
164 return false;
165
166 if (sfDevINA2XX::begin(&_theI2CBus) != ksfTkErrOk)
167 return false;
168
169 return isConnected();
170 }
171
182 bool isConnected(void)
183 {
184 if (_theI2CBus.ping() != ksfTkErrOk)
185 return false;
186
187 // Accept both INA237 (0x237x) and INA238 (0x238x) — they are register-compatible.
188 uint16_t devID = 0;
189 if (getDeviceID(devID) != ksfTkErrOk)
190 return false;
191
192 uint16_t maskedID = devID & kDeviceIDMask;
193 return (maskedID == kINA237DeviceIDValue || maskedID == kINA238DeviceIDValue);
194 }
195
196 private:
197 sfTkArdI2C _theI2CBus;
198};
Arduino I2C implementation for the INA228 high-precision power monitor.
Definition: SparkFun_INA2XX.h:69
SfeINA228ArdI2C()
Definition: SparkFun_INA2XX.h:71
bool begin(uint8_t address=kI2CAddress, TwoWire &wirePort=Wire)
Initializes the INA228 with I2C communication.
Definition: SparkFun_INA2XX.h:90
bool isConnected(void)
Checks if the INA228 is connected and responding.
Definition: SparkFun_INA2XX.h:111
Arduino I2C implementation for the INA237 power monitor.
Definition: SparkFun_INA2XX.h:140
bool begin(uint8_t address=kI2CAddress, TwoWire &wirePort=Wire)
Initializes the INA237 with I2C communication.
Definition: SparkFun_INA2XX.h:161
bool isConnected(void)
Checks if the INA237 is connected and responding.
Definition: SparkFun_INA2XX.h:182
SfeINA237ArdI2C()
Definition: SparkFun_INA2XX.h:142
INA228 high-precision power/energy/charge monitor driver.
Definition: sfDevINA228.h:37
INA237 power monitor driver (also covers the register-compatible INA238).
Definition: sfDevINA237.h:37
static const uint16_t kINA238DeviceIDValue
INA238 device ID (register-compatible with INA237)
Definition: sfDevINA2XX.h:674
static const uint16_t kDeviceIDMask
Mask for device ID (ignore revision)
Definition: sfDevINA2XX.h:675
static const uint8_t kI2CAddress
Default 7-bit I2C address for the SparkFun Qwiic Power Monitor board.
Definition: sfDevINA2XX.h:642
sfTkError_t getDeviceID(uint16_t &id)
Read the Device ID register (0x3F).
Definition: sfDevINA2XX.cpp:57
static const uint16_t kINA228DeviceIDValue
INA228 device ID (upper 12 bits)
Definition: sfDevINA2XX.h:672
static const uint16_t kINA237DeviceIDValue
INA237 device ID (upper 12 bits)
Definition: sfDevINA2XX.h:673
sfTkError_t begin(sfTkIBus *theBus=nullptr)
Initialize the device driver with the given bus.
Definition: sfDevINA2XX.cpp:28
Header file for the SparkFun INA228 high-precision power monitor driver.
Header file for the SparkFun INA237 power monitor driver.