项目作者: Erriez

项目描述 :
INA219 I2C Voltage/Current/Power sensor library for Arduino
高级语言: C++
项目地址: git://github.com/Erriez/ErriezINA219.git
创建时间: 2020-08-29T09:18:37Z
项目社区:https://github.com/Erriez/ErriezINA219

开源协议:MIT License

下载


Erriez INA219 I2C/SMB Voltage/Current/Power Monitor library for Arduino

Build Status

This is an INA219 I2C/SMB DC Voltage/Current/Power sensor library for Arduino.

INA219

Library features

  • High Accuracy: max 0.5%
  • Measure Voltage 0..26V DC
  • Measure Current 0..2000mA DC (with default 0.1 Ohm shunt)
  • Measure Power in Watt (Software Voltage * Current calculation)
  • Configurable shunt resistor value
  • Configurable I2C address for multiple sensors
  • Power-down / power-up control
  • Low-level register access

Hardware

Any Arduino hardware with a TWI interface and Wire.h support.

Pins board - INA219 VCC GND SDA SCL
Arduino UNO (ATMega328 boards) 5V GND A4 A5
Arduino Mega2560 5V GND D20 D21
Arduino Leonardo 5V GND D2 D3
Arduino DUE (ATSAM3X8E) 3V3 GND 20 21
ESP8266 3V3 GND GPIO4 (D2) GPIO5 (D1)
ESP32 3V3 GND GPIO21 GPIO22

Examples

Documentation

Library dependencies

  • Wire.h

Getting started

  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include <ErriezINA219.h>
  4. // Default I2C Address 0x40
  5. #define INA219_I2C_ADDRESS 0x40
  6. // 0.1 Ohm shunt resistor
  7. #define INA219_SHUNT_RESISTOR 0.1
  8. // Create INA219 sensor object
  9. INA219 ina219 = INA219(INA219_I2C_ADDRESS, INA219_SHUNT_RESISTOR);
  10. void setup()
  11. {
  12. // Initialize serial port
  13. Serial.begin(115200);
  14. while (!Serial) {
  15. ;
  16. }
  17. Serial.println(F("\nErriez INA219 voltage, current and power sensor example\n"));
  18. // Initialize I2C
  19. Wire.begin();
  20. Wire.setClock(400000);
  21. // Initialize INA219
  22. while (!ina219.begin()) {
  23. Serial.println(F("Error: INA219 not detected"));
  24. delay(3000);
  25. }
  26. }
  27. void loop()
  28. {
  29. // Read from sensor
  30. if (!ina219.read()) {
  31. Serial.println(F("Error: INA219 read failed"));
  32. return;
  33. }
  34. // Check valid conversion
  35. if (!ina219.available) {
  36. Serial.println(F("Error: INA219 not available"));
  37. return;
  38. }
  39. // Print result
  40. Serial.println(F("INA219:"));
  41. Serial.print(F(" Bus voltage: "));
  42. Serial.print(ina219.busVoltage, 2);
  43. Serial.println(F(" V"));
  44. Serial.print(F(" Shunt voltage: "));
  45. Serial.print(ina219.shuntVoltage / 1000, 1);
  46. Serial.println(F(" V"));
  47. Serial.print(F(" Current: "));
  48. Serial.print(ina219.current / 1000, 1);
  49. Serial.println(F(" A"));
  50. Serial.print(F(" Power: "));
  51. Serial.print(ina219.power / 1000, 1);
  52. Serial.println(F(" W"));
  53. // Wait some time
  54. delay(1000);
  55. }

Library installation

Please refer to the Wiki page.

Other Arduino Libraries and Sketches from Erriez