-
Notifications
You must be signed in to change notification settings - Fork 41
BackgroundRead.ino
Arduino sketch to demonstrate making current and voltage measurements with the INA226 chip in the background. The INA226 measures data and a pin change interrupt is used to signal the Arduino that data is ready to process.
The code contains no processor specific conditional code apart from the interrupt mechanism described below and therefore should work on all Atmel Arduino boards. It was designed and tested on both Arduino Micro and Arduino Mega boards. The example program uses the first INA226 found on the I2C bus, but by changing one line in the main program it can be made to use another device, an INA260 for example. The INA219, INA226 and INA260 were tested with this example program.
Each Atmel processor has specific pin allocations for interrupts. The program uses a pin change interrupt, of which each processor has only a limited number of vectors to handle. A description of which pins can be used on which processor can be found at Arduino PinChangeInterrupt(). The constant INA226_ALERT_PIN defines which pin is used in this program. As the pin is pulled low on alarm, the program uses the internal pullup to ensure that the pin is high when not triggered.
The INA2xx is initialized in the setup() method for a ±1 Amps maximum current and for a 0.1Ω resistor. The maximum conversion length and averaging is set, in this case each reading takes (8.244ms[bus] + 8.244ms[shunt]) x 64 averages = ~1000ms. The INA226 pulls the interrupt pin down to ground when a reading is ready and the Arduino's pin change interrupt triggers a call to the interrupt vector "PCINT0_vect" where the running sums and averages are collected. The main loop is freed to do any processing the developer wishes and each main loop iteration the counts are checked and if 10 or more readings (every 10.48 seconds) have been collected the averages are written to the serial port.
Overview
Installation
Class Instantiation
begin()
setI2CSpeed()
getBusMilliVolts()
getBusRaw()
getShuntMicroVolts()
getShuntRaw()
getBusMicroAmps()
getBusMicroWatts()
getDeviceAddress()
getDeviceName()
setMode()
setAveraging()
setBusConversion()
setShuntConversion()
reset()
waitForConversion()
conversionFinished()
alertOnConversion()
alertOnShuntOverVoltage()
alertOnShuntUnderVoltage()
alertOnBusOverVoltage()
alertOnBusUnderVoltage()
alertOnPowerOverLimit()