Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
documentation:microcontroleurs:arduino:modules:ina219_va_meter:index [2025/05/01 14:02] – [I2C] f1sls | documentation:microcontroleurs:arduino:modules:ina219_va_meter:index [2025/05/04 14:42] (Version actuelle) – f1sls | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Voltmètre / Ampèremètre INA219 ====== | + | ====== Voltmètre / Ampèremètre INA219/ |
{{: | {{: | ||
\\ | \\ | ||
Ligne 11: | Ligne 11: | ||
===== I2C ===== | ===== I2C ===== | ||
- | I2C Address | ||
- | |||
The INA219 uses the I2C protocol to communicate with microcontrollers, | The INA219 uses the I2C protocol to communicate with microcontrollers, | ||
Ligne 77: | Ligne 75: | ||
==== Calibration Register (Address = 05h) ==== | ==== Calibration Register (Address = 05h) ==== | ||
This register is used to set the calibration value for the current and power calculations. It can be read or written to set the correct calibration value. | This register is used to set the calibration value for the current and power calculations. It can be read or written to set the correct calibration value. | ||
- | ===== WIRING ===== | ||
===== PINOUT ===== | ===== PINOUT ===== | ||
Ligne 88: | Ligne 85: | ||
* **Vin+** this pin connects to the positive terminal of the voltage supply that you want to measure. | * **Vin+** this pin connects to the positive terminal of the voltage supply that you want to measure. | ||
+ | ===== WIRING ===== | ||
+ | {{: | ||
+ | {{: | ||
===== Librairie(s) ===== | ===== Librairie(s) ===== | ||
* [[https:// | * [[https:// | ||
Ligne 97: | Ligne 97: | ||
==== ARDUINO CODE ==== | ==== ARDUINO CODE ==== | ||
<code cpp> | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | Adafruit_INA219 ina219; | ||
+ | |||
+ | void setup(void) | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | while (!Serial) | ||
+ | { | ||
+ | delay(1); | ||
+ | } | ||
+ | |||
+ | // Initialize the INA219. | ||
+ | if (! ina219.begin()) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | while (1) | ||
+ | { | ||
+ | delay(10); | ||
+ | } | ||
+ | } | ||
+ | // To use a slightly lower 32V, 1A range (higher precision on amps): | ||
+ | // | ||
+ | // Or to use a lower 16V, 400mA range, call: | ||
+ | // | ||
+ | |||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop(void) | ||
+ | { | ||
+ | float shuntvoltage = 0; | ||
+ | float busvoltage = 0; | ||
+ | float current_mA = 0; | ||
+ | float loadvoltage = 0; | ||
+ | float power_mW = 0; | ||
+ | |||
+ | shuntvoltage = ina219.getShuntVoltage_mV(); | ||
+ | busvoltage = ina219.getBusVoltage_V(); | ||
+ | current_mA = ina219.getCurrent_mA(); | ||
+ | power_mW = ina219.getPower_mW(); | ||
+ | loadvoltage = busvoltage + (shuntvoltage / 1000); | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.println("" | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code cpp> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | Adafruit_INA219 ina219; | ||
+ | |||
+ | void setup() { | ||
+ | // Open serial communications and wait for port to open: | ||
+ | Serial.begin(9600); | ||
+ | while (!Serial) { | ||
+ | ; // wait for serial port to connect. Needed for native USB port only | ||
+ | } | ||
+ | |||
+ | if (! ina219.begin()) { | ||
+ | Serial.println(" | ||
+ | while (1) { delay(10); } | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | float shuntvoltage = 0; | ||
+ | float busvoltage = 0; | ||
+ | float current_mA = 0; | ||
+ | float loadvoltage = 0; | ||
+ | float power_mW = 0; | ||
+ | |||
+ | shuntvoltage = ina219.getShuntVoltage_mV(); | ||
+ | busvoltage = ina219.getBusVoltage_V(); | ||
+ | current_mA = ina219.getCurrent_mA(); | ||
+ | power_mW = ina219.getPower_mW(); | ||
+ | loadvoltage = busvoltage + (shuntvoltage / 1000); | ||
+ | |||
+ | Serial.print(busvoltage); | ||
+ | Serial.print(shuntvoltage); | ||
+ | Serial.print(loadvoltage); | ||
+ | Serial.print(current_mA); | ||
+ | Serial.println(power_mW); | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
</ | </ |