Skip to content

Commit e50a164

Browse files
committed
Add INA260
1 parent 8e5bf4f commit e50a164

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library
10+
depends=SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lib_deps =
3838
adafruit/Adafruit DPS310
3939
adafruit/Adafruit DS248x
4040
adafruit/Adafruit INA219
41+
adafruit/Adafruit INA260 Library
4142
adafruit/Adafruit HDC302x
4243
adafruit/Adafruit HTS221
4344
adafruit/Adafruit HTU21DF Library

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
391391
_ina219->configureDriver(msgDeviceInitReq);
392392
drivers.push_back(_ina219);
393393
WS_DEBUG_PRINTLN("INA219 Initialized Successfully!");
394+
} else if (strcmp("ina260", msgDeviceInitReq->i2c_device_name) == 0) {
395+
_ina260 = new WipperSnapper_I2C_Driver_INA260(this->_i2c, i2cAddress);
396+
if (!_ina260->begin()) {
397+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize INA260");
398+
_busStatusResponse =
399+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
400+
return false;
401+
}
402+
_ina260->configureDriver(msgDeviceInitReq);
403+
drivers.push_back(_ina260);
404+
WS_DEBUG_PRINTLN("INA260 Initialized Successfully!");
394405
} else if (strcmp("ltr390", msgDeviceInitReq->i2c_device_name) == 0) {
395406
_ltr390 = new WipperSnapper_I2C_Driver_LTR390(this->_i2c, i2cAddress);
396407
if (!_ltr390->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "drivers/WipperSnapper_I2C_Driver_HTU21D.h"
3636
#include "drivers/WipperSnapper_I2C_Driver_HTU31D.h"
3737
#include "drivers/WipperSnapper_I2C_Driver_INA219.h"
38+
#include "drivers/WipperSnapper_I2C_Driver_INA260.h"
3839
#include "drivers/WipperSnapper_I2C_Driver_LC709203F.h"
3940
#include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h"
4041
#include "drivers/WipperSnapper_I2C_Driver_LPS25HB.h"
@@ -150,6 +151,7 @@ class WipperSnapper_Component_I2C {
150151
WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
151152
WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
152153
WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
154+
WipperSnapper_I2C_Driver_INA260 *_ina260 = nullptr;
153155
WipperSnapper_I2C_Driver_LTR329_LTR303 *_ltr329 = nullptr;
154156
WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
155157
WipperSnapper_I2C_Driver_MCP3421 *_mcp3421 = nullptr;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_INA260.h
3+
*
4+
* Device driver for the INA260 DC Current and Voltage Monitor
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2025 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WipperSnapper_I2C_Driver_INA260_H
16+
#define WipperSnapper_I2C_Driver_INA260_H
17+
18+
#include "WipperSnapper_I2C_Driver.h"
19+
#include <Adafruit_INA260.h>
20+
21+
/**************************************************************************/
22+
/*!
23+
@brief Class that provides a driver interface for a INA260 sensor.
24+
*/
25+
/**************************************************************************/
26+
class WipperSnapper_I2C_Driver_INA260 : public WipperSnapper_I2C_Driver {
27+
public:
28+
/*******************************************************************************/
29+
/*!
30+
@brief Constructor for a INA260 sensor.
31+
@param i2c
32+
The I2C interface.
33+
@param sensorAddress
34+
The 7-bit I2C address of the sensor.
35+
*/
36+
/*******************************************************************************/
37+
WipperSnapper_I2C_Driver_INA260(TwoWire *i2c, uint16_t sensorAddress)
38+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
39+
_i2c = i2c;
40+
_sensorAddress = sensorAddress;
41+
}
42+
43+
/*******************************************************************************/
44+
/*!
45+
@brief Destructor for an INA260 sensor.
46+
*/
47+
/*******************************************************************************/
48+
~WipperSnapper_I2C_Driver_INA260() { delete _ina260; }
49+
50+
/*******************************************************************************/
51+
/*!
52+
@brief Initializes the INA260 sensor and begins I2C.
53+
@returns True if initialized successfully, False otherwise.
54+
*/
55+
/*******************************************************************************/
56+
bool begin() {
57+
_ina260 = new Adafruit_INA260();
58+
if (!_ina260->begin(_sensorAddress, _i2c)) {
59+
WS_DEBUG_PRINTLN("INA260 failed to initialise!");
60+
return false;
61+
}
62+
// TODO: use setCalibration()
63+
64+
return true;
65+
}
66+
67+
/*******************************************************************************/
68+
/*!
69+
@brief Reads a voltage sensor and converts the
70+
reading into the expected SI unit.
71+
@param voltageEvent
72+
voltage sensor reading, in volts.
73+
@returns True if the sensor event was obtained successfully, False
74+
otherwise.
75+
*/
76+
/*******************************************************************************/
77+
bool getEventVoltage(sensors_event_t *voltageEvent) {
78+
voltageEvent->voltage = _ina260->readBusVoltage();
79+
return true;
80+
}
81+
82+
/**
83+
* @brief Get the current sensor event.
84+
*
85+
* @param currentEvent Pointer to the current sensor event.
86+
*
87+
* @returns True if the sensor event was obtained successfully, False
88+
* otherwise.
89+
*/
90+
bool getEventCurrent(sensors_event_t *currentEvent) {
91+
currentEvent->current = _ina260->readCurrent();
92+
return true;
93+
}
94+
95+
protected:
96+
Adafruit_INA260 *_ina260; ///< Pointer to INA260 sensor object
97+
};
98+
99+
#endif // WipperSnapper_I2C_Driver_INA260

0 commit comments

Comments
 (0)