// #include const int INA226_ADDR = 0x44; // SCL - GPIO5 - D1 // SDA - GPIO4 - D2 bool isConnected(uint8_t addr) { Wire.beginTransmission(addr); return ( Wire.endTransmission() == 0); } static void writeRegister(byte reg, word value) { Wire.beginTransmission(INA226_ADDR); Wire.write(reg); Wire.write((value >> 8) & 0xFF); Wire.write(value & 0xFF); Wire.endTransmission(); } static word readRegister(byte reg) { word res = 0x0000; Wire.beginTransmission(INA226_ADDR); Wire.write(reg); if (Wire.endTransmission() == 0) { if (Wire.requestFrom(INA226_ADDR, 2) >= 2) { res = Wire.read() * 256; res += Wire.read(); } } return res; } void setup() { Serial.begin(115200); Wire.begin(4,5); // sda,scl if (isConnected(INA226_ADDR)) Serial.println("connected"); Serial.print("Manuf : "); Serial.println(readRegister(0xFE)); // Configuration Register Standard Einstellung 0x4127, hier aber 16 Werte Mitteln > 0x4427 writeRegister(0x00, 0x4427); // 1.1ms Volt und Strom A/D-Wandlung, Shunt und VBus continous } const float rShunt = 0.01; const float iFact = 0.0000025 / rShunt; const float vFact = 0.00119; void loop() { float volt = readRegister(0x02) * vFact; Serial.print(volt,3); Serial.print(" V, Current: "); // Seite 24: Shunt Spannung +- 81,92mV mit 16 Bit, LSB 2,5uV int16_t shuntvolt = readRegister(0x01); float current = shuntvolt * iFact; // * LSB / R Serial.print(current,3); Serial.println(); delay(1000); }