Initial working commit, phoenix edition, now with less printf
This commit is contained in:
parent
9483949eb7
commit
55d1e5e6cc
11 changed files with 659 additions and 1 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
html/
|
||||
Doxyfile
|
||||
26
.travis.yml
Normal file
26
.travis.yml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
language: c
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- ~/arduino_ide
|
||||
- ~/.arduino15/packages/
|
||||
git:
|
||||
depth: false
|
||||
quiet: true
|
||||
env:
|
||||
global:
|
||||
- PRETTYNAME="Adafruit INA260 Arduino Library"
|
||||
|
||||
before_install:
|
||||
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
|
||||
|
||||
install:
|
||||
- arduino --install-library "Adafruit BusIO","Adafruit NeoPixel"
|
||||
|
||||
script:
|
||||
- build_main_platforms
|
||||
|
||||
# Generate and deploy documentation
|
||||
after_success:
|
||||
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
|
||||
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
|
||||
185
Adafruit_INA260.cpp
Normal file
185
Adafruit_INA260.cpp
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*!
|
||||
* @file Adafruit_INA260.cpp
|
||||
*
|
||||
* @mainpage Adafruit INA260 I2C Current and Power sensor
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* I2C Driver for the INA260 I2C Current and Power sensor
|
||||
*
|
||||
* This is a library for the Adafruit INA260 breakout:
|
||||
* http://www.adafruit.com/products
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
* @section dependencies Dependencies
|
||||
*
|
||||
* This library depends on the Adafruit BusIO library
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Bryan Siepert for Adafruit Industries
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD (see license.txt)
|
||||
*
|
||||
* @section HISTORY
|
||||
*
|
||||
* v1.0 - First release
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_INA260.h"
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new INA260 class
|
||||
*/
|
||||
Adafruit_INA260::Adafruit_INA260(void) {}
|
||||
|
||||
/*!
|
||||
* @brief Sets up the HW
|
||||
* @param theWire
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
boolean Adafruit_INA260::begin(TwoWire *theWire) {
|
||||
i2c_dev = new Adafruit_I2CDevice(INA260_I2CADDR_DEFAULT);
|
||||
|
||||
if (!i2c_dev->begin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Current = new Adafruit_I2CRegister(i2c_dev, INA260_REG_CURRENT, 2, MSBFIRST);
|
||||
BusVoltage = new Adafruit_I2CRegister(i2c_dev, INA260_REG_BUSVOLTAGE, 2, MSBFIRST);
|
||||
Power = new Adafruit_I2CRegister(i2c_dev, INA260_REG_POWER, 2, MSBFIRST);
|
||||
Config = new Adafruit_I2CRegister(i2c_dev, INA260_REG_CONFIG, 2, MSBFIRST);
|
||||
MaskEnable = new Adafruit_I2CRegister(i2c_dev, INA260_REG_MASK_ENABLE, 2, MSBFIRST);
|
||||
AlertLimit = new Adafruit_I2CRegister(i2c_dev, INA260_REG_ALERT_LIMIT, 2, MSBFIRST);
|
||||
|
||||
|
||||
AveragingCount = new Adafruit_I2CRegisterBits(Config, 3, 9);
|
||||
ConversionReady = new Adafruit_I2CRegisterBits(MaskEnable, 1, 3);
|
||||
CurrentConversionTime = new Adafruit_I2CRegisterBits(Config, 3, 3);
|
||||
VoltageConversionTime = new Adafruit_I2CRegisterBits(Config, 3, 6);
|
||||
Mode = new Adafruit_I2CRegisterBits(Config, 3, 0);
|
||||
Reset = new Adafruit_I2CRegisterBits(Config, 1, 15);
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Resets the harware. By setting the MSB of the config register,
|
||||
all registers are set to default values, the same as a power-on reset.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_INA260::reset(void){
|
||||
Reset->write(1);
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads and scales the current value of the Current register.
|
||||
@return The current current measurement in mA
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float Adafruit_INA260::readCurrent(void) {
|
||||
return (int16_t)Current->read() * 1.25;
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads and scales the current value of the Bus Voltage register.
|
||||
@return The current bus voltage measurement in mV
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float Adafruit_INA260::readBusVoltage(void) {
|
||||
return BusVoltage->read() * 1.25;
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads and scales the current value of the Power register.
|
||||
@return The current Power calculation in mW
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float Adafruit_INA260::readPower(void) {
|
||||
return Power->read() * 10;
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns the current mode
|
||||
@return The current Power calculation in mW
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t Adafruit_INA260::getMode(void) {
|
||||
return Mode->read();
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns the current mode
|
||||
@param mode
|
||||
The new mode to be set
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_INA260::setMode(uint8_t mode) {
|
||||
Mode->write(mode);
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set the number of averaging samples
|
||||
@param count
|
||||
The number of samples to be averaged
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_INA260::setAveragingCount(uint8_t count){
|
||||
AveragingCount->write(count);
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Read the current current conversion time register
|
||||
@return The current current conversion time
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t Adafruit_INA260::getCurrentConversionTime(void){
|
||||
return CurrentConversionTime->read();
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set the current conversion time
|
||||
@param time
|
||||
The new current conversion time
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_INA260::setCurrentConversionTime(uint8_t time){
|
||||
CurrentConversionTime->write(time);
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Read the current bus voltage conversion time register
|
||||
@return The current bus voltage conversion time
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t Adafruit_INA260::getVoltageConversionTime(void){
|
||||
return VoltageConversionTime->read();
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set the bus voltage conversion time
|
||||
@param time
|
||||
The new bus voltage conversion time
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_INA260::setVoltageConversionTime(uint8_t time){
|
||||
VoltageConversionTime->write(time);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief check if the most recent one shot measurement has completed
|
||||
@return true if the conversion has completed
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_INA260::conversionReady(void){
|
||||
return ConversionReady->read();
|
||||
}
|
||||
111
Adafruit_INA260.h
Normal file
111
Adafruit_INA260.h
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*!
|
||||
* @file Adafruit_INA260.h
|
||||
*
|
||||
* I2C Driver for INA260 Current and Power sensor
|
||||
*
|
||||
* This is a library for the Adafruit INA260 breakout:
|
||||
* http://www.adafruit.com/products
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
*
|
||||
* BSD license (see license.txt)
|
||||
*/
|
||||
|
||||
#ifndef _ADAFRUIT_INA260_H
|
||||
#define _ADAFRUIT_INA260_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_I2CRegister.h>
|
||||
|
||||
#define INA260_I2CADDR_DEFAULT 0x40 ///< INA260 default i2c address
|
||||
#define INA260_REG_CONFIG 0x00 ///< Configuration register
|
||||
#define INA260_REG_CURRENT 0x01 ///< Current measurement register (signed) in mA
|
||||
#define INA260_REG_BUSVOLTAGE 0x02 ///< Bus voltage measurement register in mV
|
||||
#define INA260_REG_POWER 0x03 ///< Power calculation register in mW
|
||||
#define INA260_REG_MASK_ENABLE 0x06 ///< Interrupt/Alert setting and checking register
|
||||
#define INA260_REG_ALERT_LIMIT 0x07 ///< Alert limit value register
|
||||
#define INA260_REG_MFG_UID 0xFE ///< Manufacturer ID Register
|
||||
#define INA260_REG_DIE_UID 0xFF ///< Die ID and Revision Register
|
||||
/* mode options */
|
||||
|
||||
|
||||
#define INA260_MODE_SHUTDOWN 0x00 ///< SHUTDOWN: Minimize quiescient current and turn
|
||||
/* off current into the device inputs. Set another mode to exit shutown mode */
|
||||
|
||||
|
||||
#define INA260_MODE_TRIGGERED 0x03 ///< TRIGGERED: Trigger a one-shot measurement of current and bus voltage
|
||||
/* Set the TRIGGERED mode again to take a new measurement */
|
||||
|
||||
|
||||
#define INA260_MODE_CONTINUOUS 0x07 ///< CONTINUOUS: (Default) Continuously update the current,
|
||||
/* bus voltage and power registers with new measurements*/
|
||||
|
||||
/* options for size of averaging window */
|
||||
#define INA260_COUNT_1 0x01 ///< Window size: 1 sample (Default)
|
||||
#define INA260_COUNT_4 0x02 ///< Window size: 4 samples
|
||||
#define INA260_COUNT_16 0x03 ///< Window size: 16 samples
|
||||
#define INA260_COUNT_64 0x04 ///< Window size: 64 samples
|
||||
#define INA260_COUNT_128 0x05 ///< Window size: 128 samples
|
||||
#define INA260_COUNT_256 0x06 ///< Window size: 256 samples
|
||||
#define INA260_COUNT_512 0x07 ///< Window size: 512 samples
|
||||
#define INA260_COUNT_1024 0x08 ///< Window size: 1024 samples
|
||||
|
||||
/* options for shunt resistor Voltage
|
||||
and bus voltage measurement time */
|
||||
#define INA260_TIME_140_us 0x00 ///< Measurement time: 140us
|
||||
#define INA260_TIME_204_us 0x01 ///< Measurement time: 204us
|
||||
#define INA260_TIME_332_us 0x02 ///< Measurement time: 332us
|
||||
#define INA260_TIME_558_us 0x03 ///< Measurement time: 558us
|
||||
#define INA260_TIME_1_1_ms 0x04 ///< Measurement time: 1.1ms (Default)
|
||||
#define INA260_TIME_2_116_ms 0x05 ///< Measurement time: 2.116ms
|
||||
#define INA260_TIME_4_156_ms 0x06 ///< Measurement time: 4.156ms
|
||||
#define INA260_TIME_8_244_ms 0x07 ///< Measurement time: 8.224ms
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Class that stores state and functions for interacting with
|
||||
* INA260 Current and Power Sensor
|
||||
*/
|
||||
class Adafruit_INA260 {
|
||||
public:
|
||||
Adafruit_INA260();
|
||||
boolean begin(TwoWire *theWire = &Wire);
|
||||
void reset(void);
|
||||
float readCurrent(void);
|
||||
float readBusVoltage(void);
|
||||
float readPower(void);
|
||||
void setMode(uint8_t mode);
|
||||
uint8_t getMode(void);
|
||||
|
||||
bool conversionReady(void);
|
||||
|
||||
uint8_t getCurrentConversionTime(void);
|
||||
void setCurrentConversionTime(uint8_t time);
|
||||
uint8_t getVoltageConversionTime(void);
|
||||
void setVoltageConversionTime(uint8_t time);
|
||||
void setAveragingCount(uint8_t count);
|
||||
|
||||
Adafruit_I2CRegister *Current, ///< BusIO Register for Current
|
||||
*BusVoltage, ///< BusIO Register for BusVoltage
|
||||
*Power, ///< BusIO Register for Power
|
||||
*Config, ///< BusIO Register for Config
|
||||
*MaskEnable, ///< BusIO Register for MaskEnable
|
||||
*AlertLimit; ///< BusIO Register for AlertLimit
|
||||
|
||||
Adafruit_I2CRegisterBits *AveragingCount, ///< BusIO RegisterBits object for averaging count
|
||||
*ConversionReady, ///< BusIO RegisterBits object for conversion readyness check
|
||||
*CurrentConversionTime, ///< BusIO RegisterBits object for current conversion time
|
||||
*VoltageConversionTime, ///< BusIO RegisterBits object for voltage conversion time
|
||||
*Mode, ///< BusIO RegisterBits object for mode
|
||||
*Reset; ///< BusIO RegisterBits object for reset
|
||||
private:
|
||||
Adafruit_I2CDevice *i2c_dev;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
19
README.md
19
README.md
|
|
@ -1 +1,18 @@
|
|||
# Adafruit_INA260
|
||||
Adafruit_INA260 [](https://travis-ci.com/adafruit/Adafruit_INA260)
|
||||
================
|
||||
|
||||
This is the Adafruit INA260 Current and Power sensor library
|
||||
|
||||
Tested and works great with the [Adafruit INA260 Breakout Board](http://www.adafruit.com/)
|
||||
|
||||
This chip uses I2C to communicate, 2 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Bryan Siepert for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above must be included in any redistribution
|
||||
|
||||
To install, use the Arduino Library Manager and search for "Adafruit INA260" and install the library.
|
||||
|
|
|
|||
127
code-of-conduct.md
Normal file
127
code-of-conduct.md
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
# Adafruit Community Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project leaders are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Helpers by tagging @community helpers. You may also send an
|
||||
open message from any channel, or a direct message to @kattni#1507,
|
||||
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
|
||||
@Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
96
examples/ina260_neopixel_modes/ina260_neopixel_modes.ino
Normal file
96
examples/ina260_neopixel_modes/ina260_neopixel_modes.ino
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
#include <Adafruit_INA260.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
#define PIN 5
|
||||
#define NUMPIXELS 8
|
||||
int delayval = 100; // delay for half a second
|
||||
|
||||
// setup the neopixel strip with it's power running through the IN+ and IN- pins of the INA260
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_INA260 ina260 = Adafruit_INA260();
|
||||
|
||||
|
||||
void setup() {
|
||||
while (!Serial) { delay(10); }
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit INA260 Test");
|
||||
|
||||
pixels.begin();
|
||||
pixels.setBrightness(50);
|
||||
pixels.show(); // Initialize all pixels to 'off'
|
||||
|
||||
ina260.begin();
|
||||
|
||||
ina260.setAveragingCount(INA260_COUNT_4);
|
||||
ina260.setVoltageConversionTime(INA260_TIME_140_us);
|
||||
ina260.setCurrentConversionTime(INA260_TIME_140_us);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// first the default continuous mode
|
||||
ina260.setMode(INA260_MODE_CONTINUOUS);
|
||||
rampPixelColors();
|
||||
delay(500);
|
||||
|
||||
// second trigger a reading in triggered mode
|
||||
ina260.setMode(INA260_MODE_TRIGGERED);
|
||||
// the measurements in rampPixelColors will remain the same because we haven't triggered a new reading
|
||||
rampPixelColors();
|
||||
delay(500);
|
||||
|
||||
// trigger a new reading, with the values staying the same again
|
||||
ina260.setMode(INA260_MODE_TRIGGERED);
|
||||
rampPixelColors();
|
||||
delay(500);
|
||||
|
||||
// finally shutdown the INA260. The measurements will stay from the last triggered measurement.
|
||||
ina260.setMode(INA260_MODE_SHUTDOWN);
|
||||
rampPixelColors();
|
||||
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void rampPixelColors(void){
|
||||
pixels.setBrightness(25);
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, pixels.Color(255,0, 0)); // Moderately bright green color.
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
Serial.print(ina260.readCurrent());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readBusVoltage());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readPower());
|
||||
Serial.println();
|
||||
}
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
|
||||
pixels.setBrightness(50);
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, pixels.Color(255,255, 0)); // Moderately bright green color.
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
Serial.print(ina260.readCurrent());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readBusVoltage());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readPower());
|
||||
Serial.println();
|
||||
}
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
|
||||
pixels.setBrightness(100);
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, pixels.Color(255,255, 255)); // Moderately bright green color.
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
Serial.print(ina260.readCurrent());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readBusVoltage());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readPower());
|
||||
Serial.println();
|
||||
}
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
}
|
||||
24
examples/ina260_test/ina260_test.ino
Normal file
24
examples/ina260_test/ina260_test.ino
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <Adafruit_INA260.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
Adafruit_INA260 ina260 = Adafruit_INA260();
|
||||
|
||||
void setup() {
|
||||
while (!Serial) { delay(10); }
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit INA260 Test");
|
||||
ina260.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Current: ");
|
||||
Serial.println(ina260.readCurrent());
|
||||
Serial.print("Bus Voltage: ");
|
||||
Serial.println(ina260.readBusVoltage());
|
||||
Serial.print("Power: ");
|
||||
Serial.println(ina260.readCurrent());
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
35
examples/ina260_tuning/ina260_tuning.ino
Normal file
35
examples/ina260_tuning/ina260_tuning.ino
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <Adafruit_INA260.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
|
||||
int delayval = 100; // delay for half a second
|
||||
|
||||
Adafruit_INA260 ina260 = Adafruit_INA260();
|
||||
|
||||
void setup() {
|
||||
while (!Serial) { delay(10); }
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit INA260 tuning test");
|
||||
|
||||
ina260.begin();
|
||||
|
||||
// set the number of samples to average
|
||||
ina260.setAveragingCount(INA260_COUNT_16);
|
||||
// set the time over which to measure the current and bus voltage
|
||||
ina260.setVoltageConversionTime(INA260_TIME_140_us);
|
||||
ina260.setCurrentConversionTime(INA260_TIME_140_us);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// measure and print current, voltage, and power to display on the serial plotter
|
||||
Serial.print(ina260.readCurrent());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readBusVoltage());
|
||||
Serial.print(" ");
|
||||
Serial.print(ina260.readPower());
|
||||
Serial.println();
|
||||
|
||||
delay(125); // Delay for a period of time (in milliseconds).
|
||||
}
|
||||
9
library.properties
Normal file
9
library.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
name=Adafruit INA260 Library
|
||||
version=1.0.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for the INA260 sensors in the Adafruit shop
|
||||
paragraph=Arduino library for the INA260 sensors in the Adafruit shop
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_INA260
|
||||
architectures=*
|
||||
26
license.txt
Normal file
26
license.txt
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2012, Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Loading…
Reference in a new issue