Skip to content

Commit 943b717

Browse files
committed
Add INA260
1 parent e547559 commit 943b717

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-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 SPIFlash, Adafruit NeoPixel, 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, RTClib, StreamUtils, Adafruit SHT4x Library
10+
depends=SdFat - Adafruit Fork, Adafruit SPIFlash, Adafruit NeoPixel, 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, RTClib, StreamUtils, Adafruit SHT4x Library

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lib_deps =
3131
adafruit/Adafruit DPS310
3232
adafruit/Adafruit DS248x
3333
adafruit/Adafruit INA219
34+
adafruit/Adafruit INA260 Library
3435
adafruit/Adafruit HTS221
3536
adafruit/Adafruit HTU21DF Library
3637
adafruit/Adafruit HTU31D Library

src/components/i2c/controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
138138
const char *driver_name) -> drvBase * {
139139
return new drvIna219(i2c, addr, mux_channel, driver_name);
140140
}},
141+
{"ina260",
142+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
143+
const char *driver_name) -> drvBase * {
144+
return new drvIna260(i2c, addr, mux_channel, driver_name);
145+
}},
141146
{"lc709203f",
142147
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
143148
const char *driver_name) -> drvBase * {

src/components/i2c/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "drivers/drvHtu31d.h"
3535
#include "drivers/drvHtu21d.h"
3636
#include "drivers/drvIna219.h"
37+
#include "drivers/drvIna260.h"
3738
#include "drivers/drvLc709203f.h"
3839
#include "drivers/drvLps22hb.h"
3940
#include "drivers/drvLps25hb.h"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*!
2+
* @file drvIna260.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 DRV_INA260_H
16+
#define DRV_INA260_H
17+
18+
#include "drvBase.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 drvIna260 : public drvBase {
27+
public:
28+
/*******************************************************************************/
29+
/*!
30+
@brief Constructor for a INA260 sensor.
31+
@param i2c
32+
The I2C interface.
33+
@param sensorAddress
34+
7-bit device address.
35+
@param mux_channel
36+
The I2C multiplexer channel.
37+
@param driver_name
38+
The name of the driver.
39+
*/
40+
/*******************************************************************************/
41+
drvIna260(TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
42+
const char *driver_name)
43+
: drvBase(i2c, sensorAddress, mux_channel, driver_name) {
44+
// Initialization handled by drvBase constructor
45+
}
46+
47+
/*******************************************************************************/
48+
/*!
49+
@brief Destructor for an INA260 sensor.
50+
*/
51+
/*******************************************************************************/
52+
~drvIna260() { delete _ina260; }
53+
54+
/*******************************************************************************/
55+
/*!
56+
@brief Initializes the INA260 sensor and begins I2C.
57+
@returns True if initialized successfully, False otherwise.
58+
*/
59+
/*******************************************************************************/
60+
bool begin() {
61+
_ina260 = new Adafruit_INA260();
62+
if (!_ina260->begin(_address, _i2c)) {
63+
WS_DEBUG_PRINTLN("INA260 failed to initialise!");
64+
return false;
65+
}
66+
// TODO: use setCalibration()
67+
68+
return true;
69+
}
70+
71+
/*******************************************************************************/
72+
/*!
73+
@brief Reads a voltage sensor and converts the
74+
reading into the expected SI unit.
75+
@param voltageEvent
76+
voltage sensor reading, in volts.
77+
@returns True if the sensor event was obtained successfully, False
78+
otherwise.
79+
*/
80+
/*******************************************************************************/
81+
bool getEventVoltage(sensors_event_t *voltageEvent) {
82+
voltageEvent->voltage = _ina260->readBusVoltage();
83+
return true;
84+
}
85+
86+
/**
87+
* @brief Get the current sensor event.
88+
*
89+
* @param currentEvent Pointer to the current sensor event.
90+
*
91+
* @returns True if the sensor event was obtained successfully, False
92+
* otherwise.
93+
*/
94+
bool getEventCurrent(sensors_event_t *currentEvent) {
95+
currentEvent->current = _ina260->readCurrent();
96+
return true;
97+
}
98+
99+
protected:
100+
Adafruit_INA260 *_ina260; ///< Pointer to INA260 sensor object
101+
};
102+
103+
#endif // DRV_INA260_H

0 commit comments

Comments
 (0)