Adafruit INA219 Current Sensor Breakout Created by lady ada Last updated on 2018-08-22 03:30:10 PM UTC
Guide Contents Guide Contents Overview 2 3 Why the High Side? How does it work? 3 3 Assembly 5 Addressing the Boards 5 Wiring 7 Connect to the microprocessor Connect to the circuit Arduino Code 11 Install the Library Load the Example Run it! Customize it 11 11 12 12 Library Reference Construction and Initialization Functions: Sensor Reading Functions: Python & CircuitPython CircuitPython Microcontroller Wiring Python Computer Wiring CircuitPython Installation of INA219 Library Python Installa
Overview The INA219B breakout board will solve all your power-monitoring problems. Instead of struggling with two multimeters, you can use this breakout to measure both the high side voltage and DC current draw over I2C with 1% precision. Why the High Side? Most current-measuring devices such as our current panel meter are only good for low side measuring. That means that unless you want to get a battery involved, you have to stick the measurement resistor between the target ground and true ground.
inductive spikes. © Adafruit Industries https://learn.adafruit.
Assembly The board comes with all surface-mount components pre-soldered. Additional parts are included to help integrate the INA219 breakout board into your project. Wires can be soldered directly to the holes on the edge of the board. But for breadboard use, you will want to solder on the included 6-pin header. The load can be connected via the header, or using the included 2-pin screw-terminal.
To program the address offset, use a drop of solder to bridge the corresponding address jumper for each binary '1' in the address. Up to 4 boards may be connected. Addressing is as follows: Board 0: Address = 0x40 Offset = binary 00000 (no jumpers required) Board 1: Address = 0x41 Offset = binary 00001 (bridge A0 as in the photo above) Board 2: Address = 0x44 Offset = binary 00100 (bridge A1) Board 3: Address = 0x45 Offset = binary 00101 (bridge A0 & A1) © Adafruit Industries https://learn.adafruit.
Wiring The INA219 breakout board can be powered by the 5v pin on your Arduino and communicates via I2C. Connect to the microprocessor Connect GND to GND Connect VCC to 5v Then connect SDA to SDA (Analog pin 4 on pre-R3 Arduinos) And connect SCL to SCL (Analog pin 5 on pre-R3 Arduinos) On R3 and later Arduinos, you can connect to the new dedicated SDA & SCL pins next to the AREF pin. On pre-R3 Megas, SDA & SCL are on pins 20 & 21. © Adafruit Industries https://learn.adafruit.
Next we must insert the INA219 current sensor into the circuit we want to measure: Be careful inserting noisy loads that can cause a sharp current draw, such as DC motors, since they can cause problems on the power lines and may cause the INA219 to reset, etc. When using a DC motor or a similar device, be sure to include a large capacitor to decouple the motor from the power supply and use a snubber diode to protect against inductive spikes.
Connect V- to the positive terminal or lead of the load. This puts the sense resistor in-line with the circuit. Finally, connect a wire from the negative terminal of the power supply to GND. This allows the sensor to measure the load voltage as well as the load current. The photo below shows an INA219 breakout board configured to measure the motor supply current on an Adafruit Motor Shield. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Arduino Code Programming the Adafruit INA219 breakout board is simple using our library: Install the Library Download (https://adafru.it/aRj)the library (https://adafru.it/aRj) from the Downloads button below https://adafru.it/rMD https://adafru.it/rMD Expand the .zip file to the Libraries folder in your Arduino Sketchbook folder (If you don't know where this is, open File->Preferences in the IDE and it will tell you the location of your sketchbook folder).
Run it! Click on the upload button in the IDE. When it is "done uploading" Open your Serial Monitor and set the speed to 115200 baud. The output should appear similar to the sample below: Customize it You can adapt, expand or modify the example code to suit your project requirements. For a detailed description of the available library functions, see the Library Reference on the next page: © Adafruit Industries https://learn.adafruit.
Library Reference Construction and Initialization Functions: Adafruit_INA219(uint8_t addr = INA219_ADDRESS); Constructs an instance of the Adafruit_INA219. If no address is specified, the default address (0x40) is used. If more than one INA219 module is connected, it should be addressed as shown on the Assembly page and the configured address passed to the constuctor. void begin(void); Initializes I2C communication with the Adafruit_INA219 device using the default configuration values.
float float float float shuntvoltage = 0; busvoltage = 0; current_mA = 0; loadvoltage = 0; shuntvoltage = ina219.getShuntVoltage_mV(); busvoltage = ina219.getBusVoltage_V(); current_mA = ina219.getCurrent_mA(); loadvoltage = busvoltage + (shuntvoltage / 1000); Serial.print("Bus Voltage: Serial.print("Shunt Voltage: Serial.print("Load Voltage: Serial.print("Current: Serial.println(""); © Adafruit Industries "); "); "); "); Serial.print(busvoltage); Serial.println(" V"); Serial.
Python & CircuitPython It's easy to use the INA219 sensor with Python and CircuitPython, and the Adafruit CircuitPython INA219 (https://adafru.it/BHQ) module. This module allows you to easily write Python code that reads the current and more from the sensor. You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library (https://adafru.it/BSN).
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle (https://adafru.it/zdx). For example the Circuit Playground Express guide has a great page on how to install the library bundle (https://adafru.it/ABU) for both express and non-express boards.
That's all there is to using the INA219 with CircuitPython! Here's a full example to print the voltage and current every second. Save this as code.py on your board's filesystem and check the output from the serial REPL. Full Example Code import time from board import SCL, SDA import busio import adafruit_ina219 i2c_bus = busio.I2C(SCL, SDA) ina219 = adafruit_ina219.
Python Docs Python Docs (https://adafru.it/C4O) © Adafruit Industries https://learn.adafruit.
Downloads Datasheets & Files Eagle PCB files for the INA219 breakout board (https://adafru.it/aRk) Arduino driver library (https://adafru.it/aRj) Data Sheet for the INA219 chip (https://adafru.it/aRl) Fritzing object in the Adafruit Fritzing library (https://adafru.it/aP3) Schematic & Fabrication Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-08-22 03:30:06 PM UTC Page 20 of 20