Prof. J. Walter - Informationstechnik, Mikrocomputertechnik, Digitale Medien Quellcode
Hochschule Karlsruhe Logo Energieeffiziente Mikrocontroller
Feinstaubmessung
Wintersemester 2021
Uli Hochreither
Benedikt Fautz

Quellcode

Arudino IDE v1.8.15
Adafruit_INA219.h v1.1.1


IDE Settings


#include <Adafruit_INA219.h>

#define SAMPLETIME 50 //ms

Adafruit_INA219 ina219;

unsigned long tStart;
unsigned long tStop;
float s1, s2, s3, s4;

void setup() {
    Serial.begin(115200);
    Serial.println("Messung Start");

    if (! ina219.begin()) {
        Serial.println("Failed to find INA219 chip");
        while (1) { delay(10); }
    }
    ina219.setCalibration_16V_400mA();
}

void loop() {
    tStart = millis();

    s1 = ina219.getShuntVoltage_mV();
    s2 = ina219.getBusVoltage_V();
    s3 = ina219.getCurrent_mA();
    s4 = ina219.getPower_mW();

    Serial.print(tStart);
    Serial.print("; ");
    Serial.print(s1);
    Serial.print("; ");
    Serial.print(s2);
    Serial.print("; ");
    Serial.print(s3);
    Serial.print("; ");
    Serial.print(s4);
    Serial.println();

    tStop = millis();
    delay(SAMPLETIME-(tStop-tStart));
}


Download Quellcode

  Mit Unterstützung von Prof. J. Walter Wintersemester 2021