ErriezINA219
v1.0.0
Esta é uma biblioteca Ina219 I2C/SMB DC/Current/Power Sensor para Arduino.
Qualquer hardware Arduino com uma interface TWI e suporte Wire.h .
| PINS PINS - INA219 | VCC | Gnd | SDA | SCL |
|---|---|---|---|---|
| Arduino UNO (placas ATMEGA328) | 5V | Gnd | A4 | A5 |
| Arduino Mega2560 | 5V | Gnd | D20 | D21 |
| Arduino Leonardo | 5V | Gnd | D2 | D3 |
| Arduino devido (atsam3x8e) | 3v3 | Gnd | 20 | 21 |
| ESP8266 | 3v3 | Gnd | Gpio4 (d2) | Gpio5 (d1) |
| Esp32 | 3v3 | Gnd | Gpio21 | Gpio22 |
Wire.h # include < Arduino.h >
# include < Wire.h >
# include < ErriezINA219.h >
// Default I2C Address 0x40
# define INA219_I2C_ADDRESS 0x40
// 0.1 Ohm shunt resistor
# define INA219_SHUNT_RESISTOR 0.1
// Create INA219 sensor object
INA219 ina219 = INA219(INA219_I2C_ADDRESS, INA219_SHUNT_RESISTOR);
void setup ()
{
// Initialize serial port
Serial. begin ( 115200 );
while (!Serial) {
;
}
Serial. println ( F ( " n Erriez INA219 voltage, current and power sensor example n " ));
// Initialize I2C
Wire. begin ();
Wire. setClock ( 400000 );
// Initialize INA219
while (!ina219. begin ()) {
Serial. println ( F ( " Error: INA219 not detected " ));
delay ( 3000 );
}
}
void loop ()
{
// Read from sensor
if (!ina219. read ()) {
Serial. println ( F ( " Error: INA219 read failed " ));
return ;
}
// Check valid conversion
if (!ina219. available ) {
Serial. println ( F ( " Error: INA219 not available " ));
return ;
}
// Print result
Serial. println ( F ( " INA219: " ));
Serial. print ( F ( " Bus voltage: " ));
Serial. print (ina219. busVoltage , 2 );
Serial. println ( F ( " V " ));
Serial. print ( F ( " Shunt voltage: " ));
Serial. print (ina219. shuntVoltage / 1000 , 1 );
Serial. println ( F ( " V " ));
Serial. print ( F ( " Current: " ));
Serial. print (ina219. current / 1000 , 1 );
Serial. println ( F ( " A " ));
Serial. print ( F ( " Power: " ));
Serial. print (ina219. power / 1000 , 1 );
Serial. println ( F ( " W " ));
// Wait some time
delay ( 1000 );
}Consulte a página do Wiki.