INA2xx  v1.1.0
Arduino Library to read current, voltage and power data from one or more INA2xx device(s)
DisplayReadings.ino File Reference

Example program for the INA Library demonstrating reading an INA device and displaying results. More...

#include "WProgram.h"
#include <INA.h>

Functions

void setup ()
 
void loop ()
 

Variables

const uint32_t SERIAL_SPEED {115200}
 Use fast serial speed.
 
const uint32_t SHUNT_MICRO_OHM {100000}
 Shunt resistance in Micro-Ohm, e.g. 100000 is 0.1 Ohm.
 
const uint16_t MAXIMUM_AMPS {1}
 Max expected amps, clamped from 1A to a max of 1022A.
 
uint8_t devicesFound {0}
 Number of INAs found.
 
INA_Class INA
 INA class instantiation to use EEPROM.
 

Detailed Description

Example program for the INA Library demonstrating reading an INA device and displaying results.

Description

Program to demonstrate the INA library for the Arduino. When started, the library searches the I2C bus for all INA2xx devices. Then the example program goes into an infinite loop and displays the power measurements (bus voltage and current) for all devices.

Detailed documentation can be found on the GitHub Wiki pages at https://github.com/Zanduino/INA/wiki

This example is for a INA set up to measure a 5-Volt load with a 0.1 Ohm resistor in place, this is the same setup that can be found in the Adafruit INA219 breakout board. The complex calibration options are done at runtime using the 2 parameters specified in the "begin()" call and the library has gone to great lengths to avoid the use of floating point to conserve space and minimize runtime. This demo program uses floating point only to convert and display the data conveniently. The INA devices have 15 bits of precision, and even though the current and watt information is returned using 32-bit integers the precision remains the same.

The library supports multiple INA devices and multiple INA device types. The Atmel's EEPROM is used to store the 96 bytes of static information per device using https://www.arduino.cc/en/Reference/EEPROM function calls. Although up to 16 devices could theoretically be present on the I2C bus the actual limit is determined by the available EEPROM - ATmega328 UNO has 1024k so can support up to 10 devices but the ATmega168 only has 512 bytes which limits it to supporting at most 5 INAs. Support has been added for the ESP32 based Arduinos, these use the EEPROM calls differently and need specific code.

GNU General Public License v3.0

This program is free software : you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with this program(see https://github.com/Zanduino/INA/blob/master/LICENSE). If not, see http://www.gnu.org/licenses/.

Author

Written by Arnd Arnd@.nosp@m.Zand.nosp@m.uino..nosp@m.Com at https://www.github.com/SV-Zanshin

Changelog

Version Date Developer Comments
1.0.8 2020-12-01 SV-Zanshin Issue #72. Allow dynamic RAM allocation instead of EEPROM
1.0.7 2020-06-30 SV-Zanshin Issue #58. Changed formatting to use clang-format
1.0.6 2020-06-29 SV-Zanshin Issue #57. Changed case of functions "Alert..."
1.0.5 2020-05-03 SV-Zanshin Moved setting of maxAmps and shunt to constants
1.0.4 2019-02-16 SV-Zanshin Reformatted and refactored for legibility and clarity
1.0.3 2019-02-10 SV-Zanshin Issue #38. Made pretty-print columns line up
1.0.3 2019-02-09 SV-Zanshin Issue #38. Added device number to display
1.0.2 2018-12-29 SV-Zanshin Converted comments to doxygen format
1.0.1 2018-09-22 SV-Zanshin Comments corrected, add INA wait loop, removed F("") calls
1.0.0 2018-06-22 SV-Zanshin Initial release
1.0.0b 2018-06-17 SV-Zanshin INA219 and INA226 completed, including testing
1.0.0a 2018-06-10 SV-Zanshin Initial coding

Function Documentation

◆ loop()

void loop ( )

Arduino method for the main program loop

This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating. In order to format the output use is made of the "sprintf()" function, but in the Arduino implementation it has no support for floating point output, so the "dtostrf()" function is used to convert the floating point numbers into formatted strings.

Returns
void

◆ setup()

void setup ( )

Arduino method called once at startup to initialize the system

This is an Arduino IDE method which is called first upon boot or restart. It is only called one time and then control goes to the "loop()" method, from which control never returns. The serial port is initialized and the INA.begin() method called to find all INA devices on the I2C bus and then the devices are initialized to given conversion and averaging rates.

Returns
void