Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

BackgroundRead.ino

Arnd edited this page Jun 22, 2018 · 3 revisions

‼️ This library is now deprecated and has been replaced by the INA library. All existing INA226 functionality and functions have been implemented ‼️

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.

Compatibility

General

The code contains no processor specific conditional code apart from the interrupt mechanism described below and therefore should work on all Atmel Arduinos. It was designed and tested on both Arduino Micro and Arduino Mega boards.

Pin Change Interrupt Pins

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.

Function

The INA226 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, which means that each reading takes 8.244ms x 64 readings = 527.616ms. 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 5.28 seconds) have been collected the averages are written to the serial port.