From 8f27e08c69bc38d2f8cebb029fc7ca7fb1e3aef5 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sat, 10 Jan 2026 19:16:43 +0100 Subject: [PATCH] update GitHub actions --- .github/workflows/arduino-lint.yml | 2 +- .github/workflows/arduino_test_runner.yml | 3 +- .github/workflows/jsoncheck.yml | 2 +- CHANGELOG.md | 4 ++ INA228.cpp | 30 +++++++--- INA228.h | 14 ++--- INA_comparison_table.md | 2 +- LICENSE | 2 +- README.md | 18 ++++-- examples/INA228_demo/INA228_demo.ino | 2 +- examples/INA228_demo_Wire1/.arduino-ci.yml | 28 ++++++++++ .../INA228_demo_Wire1/INA228_demo_Wire1.ino | 55 +++++++++++++++++++ .../INA228_demo_energy_charge.ino | 2 +- .../INA228_demo_two_devices.ino | 2 +- .../INA228_dump_config/INA228_dump_config.ino | 2 +- .../INA228_meta_data/INA228_meta_data.ino | 2 +- .../INA228_performance/INA228_performance.ino | 2 +- library.json | 2 +- library.properties | 2 +- 19 files changed, 140 insertions(+), 36 deletions(-) create mode 100644 examples/INA228_demo_Wire1/.arduino-ci.yml create mode 100644 examples/INA228_demo_Wire1/INA228_demo_Wire1.ino diff --git a/.github/workflows/arduino-lint.yml b/.github/workflows/arduino-lint.yml index 0ad60f4..aed264b 100644 --- a/.github/workflows/arduino-lint.yml +++ b/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: arduino/arduino-lint-action@v2 with: library-manager: update diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml index 1897982..a2a5f07 100644 --- a/.github/workflows/arduino_test_runner.yml +++ b/.github/workflows/arduino_test_runner.yml @@ -6,9 +6,8 @@ jobs: runTest: runs-on: ubuntu-latest timeout-minutes: 20 - steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/.github/workflows/jsoncheck.yml b/.github/workflows/jsoncheck.yml index 8804e69..2c52dc7 100644 --- a/.github/workflows/jsoncheck.yml +++ b/.github/workflows/jsoncheck.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: json-syntax-check uses: limitusus/json-syntax-check@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5d11f..e683a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.1] - 2026-01-10 +- update GitHub actions +- minor edits + ## [0.4.0] - 2025-08-20 - Fix #30, getKiloWattHour() (thanks to Eerth) - update GitHub actions diff --git a/INA228.cpp b/INA228.cpp index 3b06770..9e9e32d 100644 --- a/INA228.cpp +++ b/INA228.cpp @@ -1,6 +1,6 @@ // FILE: INA228.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.4.1 // DATE: 2024-05-09 // PURPOSE: Arduino library for the INA228, I2C, 20 bit, voltage, current and power sensor. // URL: https://github.com/RobTillaart/INA228 @@ -363,7 +363,8 @@ uint8_t INA228::getAverage() int INA228::setMaxCurrentShunt(float maxCurrent, float shunt) { // Shunt can be really small - if (shunt < 0.0001) return -2; // TODO error code + if (shunt < 0.0001) return -2; // TODO error code + if (maxCurrent < 0.0) return -3; // TODO error code _maxCurrent = maxCurrent; _shunt = shunt; _current_LSB = _maxCurrent * 1.9073486328125e-6; // pow(2, -19); @@ -375,8 +376,7 @@ int INA228::setMaxCurrentShunt(float maxCurrent, float shunt) { shunt_cal *= 4; } - // shunt_cal must be written to REGISTER. - // work in progress PR #7 + // shunt_cal must be written to its REGISTER. _writeRegister(INA228_SHUNT_CAL, shunt_cal); return 0; @@ -466,35 +466,47 @@ uint16_t INA228::getDiagnoseAlertBit(uint8_t bit) // // THRESHOLD AND LIMIT REGISTERS 12-17 // -// TODO - API ? - +// TODO (sync INA228) +// - API ? +// - return bool for setters +// - float voltage interface instead of uint16_t? breaking! void INA228::setShuntOvervoltageTH(uint16_t threshold) { // TODO ADCRANGE DEPENDENT + // Conversion Factor: 5 μV/LSB when ADCRANGE = 0 + // 1.25 μV/LSB when ADCRANGE = 1. + // float LSB = 5.0e-6; + // if (_ADCRange == 1) LSB = 1.25e-6; _writeRegister(INA228_SOVL, threshold); } uint16_t INA228::getShuntOvervoltageTH() { // TODO ADCRANGE DEPENDENT + // float LSB = 5.0e-6; + // if (_ADCRange == 1) LSB = 1.25e-6; return _readRegister(INA228_SOVL, 2); } void INA228::setShuntUndervoltageTH(uint16_t threshold) { // TODO ADCRANGE DEPENDENT + // float LSB = 5.0e-6; + // if (_ADCRange == 1) LSB = 1.25e-6; _writeRegister(INA228_SUVL, threshold); } uint16_t INA228::getShuntUndervoltageTH() { // TODO ADCRANGE DEPENDENT + // float LSB = 5.0e-6; + // if (_ADCRange == 1) LSB = 1.25e-6; return _readRegister(INA228_SUVL, 2); } void INA228::setBusOvervoltageTH(uint16_t threshold) { - if (threshold > 0x7FFF) return; + if (threshold > 0x7FFF) return; // false; //float LSB = 3.125e-3; // 3.125 mV/LSB. _writeRegister(INA228_BOVL, threshold); } @@ -520,13 +532,13 @@ uint16_t INA228::getBusUndervoltageTH() void INA228::setTemperatureOverLimitTH(uint16_t threshold) { - //float LSB = 7.8125e-3; // milliCelsius + //float LSB = 7.8125e-3; // milli degrees Celsius _writeRegister(INA228_TEMP_LIMIT, threshold); } uint16_t INA228::getTemperatureOverLimitTH() { - //float LSB = 7.8125e-3; // milliCelsius + //float LSB = 7.8125e-3; // milli degrees Celsius return _readRegister(INA228_TEMP_LIMIT, 2); } diff --git a/INA228.h b/INA228.h index e207105..5c01b55 100644 --- a/INA228.h +++ b/INA228.h @@ -1,7 +1,7 @@ #pragma once // FILE: INA228.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.4.1 // DATE: 2024-05-09 // PURPOSE: Arduino library for the INA228, I2C, 20 bit, voltage, current and power sensor. // URL: https://github.com/RobTillaart/INA228 @@ -16,7 +16,7 @@ #include "Wire.h" -#define INA228_LIB_VERSION (F("0.4.0")) +#define INA228_LIB_VERSION (F("0.4.1")) // for setMode() and getMode() @@ -116,7 +116,7 @@ class INA228 // raw integer interface. int32_t getShuntVoltageRAW(); - + // SHUNT CURRENT float getCurrent(); // Ampere float getAmpere() { return getCurrent(); }; @@ -191,12 +191,12 @@ class INA228 // read datasheet for details. use with care. // maxCurrent <= 204, (in fact no limit) // shunt >= 0.0001. - // returns _current_LSB; + // returns error code => 0 == OK; int setMaxCurrentShunt(float maxCurrent, float shunt); - bool isCalibrated() { return _current_LSB != 0.0; }; + bool isCalibrated() { return _current_LSB > 0.0; }; float getMaxCurrent(); float getShunt(); - float getCurrentLSB(); + float getCurrentLSB(); // <= 0.0 means not calibrated. // // SHUNT TEMPERATURE COEFFICIENT REGISTER 3 @@ -243,7 +243,7 @@ class INA228 // MANUFACTURER and ID REGISTER 3E and 3F // // typical value - uint16_t getManufacturer(); // 0x5449 + uint16_t getManufacturer(); // 0x5449 ("TI" in ASCII) uint16_t getDieID(); // 0x0228 uint16_t getRevision(); // 0x0001 diff --git a/INA_comparison_table.md b/INA_comparison_table.md index c74ac0a..dae9a6c 100644 --- a/INA_comparison_table.md +++ b/INA_comparison_table.md @@ -8,7 +8,7 @@ Comparison of my INA2xx libraries |:------------------|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:| | bits | 12 | 16 | 20 | 20 | 16 | 16 | 16 | 16 | 13 | | Max Voltage | 26 | 36 | 85 | 85 | 48 | 85 | 85 | 36 | 26 | -| Communication | I2C | I2C | I2C | SPI | I2C | SPI | SPI | I2C | I2C | +| Communication | I2C | I2C | I2C | SPI | I2C | I2C | SPI | I2C | I2C | | Channels | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 3 | | | | | | | | | | | | | getBusVoltage | Y | Y | Y | Y | Y | Y | Y | Y | Y | diff --git a/LICENSE b/LICENSE index 4f42d5c..6fde228 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024-2025 Rob Tillaart +Copyright (c) 2024-2026 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 47683a3..e991041 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ The INA228 also provides an **ALERT** line, to generate an interrupt in case a predefined threshold has been met. This can be an under- or over-voltage, temperature or power limit. The library does not handle these interrupts. +The alert / limits part of the library's API still needs a redesign. The library is limited tested and verified with hardware. @@ -259,7 +260,7 @@ This value is always positive. ### SHUNT VOLTAGE -- **float getShuntVoltage()** idem, Returns value in volts. +- **float getShuntVoltage()** idem. Returns value in volts. Note the value can be positive or negative as the INA228 is bidirectional. - **float getShuntVolt()** - **float getShuntMilliVolt()** @@ -274,10 +275,6 @@ Note this value can be positive or negative as the INA228 is bidirectional. - **float getMilliAmpere()** - **float getMicroAmpere()** -### TEMPERATURE - -- **float getTemperature()** returns the temperature in Celsius. - ### POWER - **float getPower()** returns the current x BusVoltage in Watt. @@ -286,6 +283,10 @@ Note this value can be positive or negative as the INA228 is bidirectional. - **float getMicroWatt()** - **float getKiloWatt()** +### TEMPERATURE + +- **float getTemperature()** returns the temperature in Celsius. + ### ENERGY See page 13++, page 32, 8.1.2 @@ -332,7 +333,7 @@ Read datasheet for details, section 7.6.1.1, page 22 - **uint8_t getConversionDelay()** return set value. - **void setTemperatureCompensation(bool on)** see Shunt temperature coefficient below. - **bool getTemperatureCompensation()** return set value. -- **bool setADCRange(bool flag)** flag = false => 164 mV, true => 41 mV +- **bool setADCRange(bool flag)** flag = false => ~163.84 mV, true => ~40.96 mV Since 0.3.1 setADCRange() calls setMaxCurrentShunt() to update the internal LSB values. - **bool getADCRange()** return set value. @@ -389,6 +390,8 @@ Read datasheet for details, section 7.6.1.2, page 22++ | INA228_4120_us | 7 | +### ADC Average + - **bool setAverage(uint8_t avg = INA228_1_SAMPLE)** - **uint8_t getAverage()** return set value. @@ -416,6 +419,7 @@ depends on breakout used, See section above. The shunt should be 0.0001 Ω and up. - returns 0 if OK. - returns -2 if shunt < 0.0001 Ohm. ( Mateksys == 0.0002 Ω ) + - returns -3 if maxCurrent < 0.0. - **bool isCalibrated()** is valid calibration value. The currentLSB > 0. - **float getMaxCurrent()** return set value. - **float getShunt()** return set value. @@ -504,6 +508,8 @@ might be changed / extended in the future. - test and verify. - DiagnoseAlertBit functions - redo API (0.2.0) +- keep in sync with INA226 where possible. +- keep in sync with INA238 where possible. #### Should diff --git a/examples/INA228_demo/INA228_demo.ino b/examples/INA228_demo/INA228_demo.ino index d5924c9..17e2b87 100644 --- a/examples/INA228_demo/INA228_demo.ino +++ b/examples/INA228_demo/INA228_demo.ino @@ -14,8 +14,8 @@ INA228 INA(0x40); void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/examples/INA228_demo_Wire1/.arduino-ci.yml b/examples/INA228_demo_Wire1/.arduino-ci.yml new file mode 100644 index 0000000..51b2ea4 --- /dev/null +++ b/examples/INA228_demo_Wire1/.arduino-ci.yml @@ -0,0 +1,28 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + # - uno + # - due + # - zero + # - leonardo + # - m4 + - esp32 + # - esp8266 + # - mega2560 + - rpipico + diff --git a/examples/INA228_demo_Wire1/INA228_demo_Wire1.ino b/examples/INA228_demo_Wire1/INA228_demo_Wire1.ino new file mode 100644 index 0000000..d9ee2d1 --- /dev/null +++ b/examples/INA228_demo_Wire1/INA228_demo_Wire1.ino @@ -0,0 +1,55 @@ +// +// FILE: INA228_demo_Wire1.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo core functions +// URL: https://github.com/RobTillaart/INA228 + + +#include "INA228.h" + + +INA228 INA(0x40, &Wire1); + + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print("INA228_LIB_VERSION: "); + Serial.println(INA228_LIB_VERSION); + Serial.println(); + + Wire1.begin(); + if (!INA.begin() ) + { + Serial.println("Could not connect. Fix and Reboot"); + while(1); + } + + INA.setMaxCurrentShunt(10, 0.015); + +} + + +void loop() +{ + Serial.println("\nVBUS\tVSHUNT\tCURRENT\tPOWER\tTEMP"); + for (int i = 0; i < 20; i++) + { + Serial.print(INA.getBusVoltage(), 3); + Serial.print("\t"); + Serial.print(INA.getShuntMilliVolt(), 3); + Serial.print("\t"); + Serial.print(INA.getMilliAmpere(), 3); + Serial.print("\t"); + Serial.print(INA.getMilliWatt(), 3); + Serial.print("\t"); + Serial.print(INA.getTemperature(), 3); + Serial.println(); + delay(1000); + } +} + + +// -- END OF FILE -- diff --git a/examples/INA228_demo_energy_charge/INA228_demo_energy_charge.ino b/examples/INA228_demo_energy_charge/INA228_demo_energy_charge.ino index be949d4..755ee24 100644 --- a/examples/INA228_demo_energy_charge/INA228_demo_energy_charge.ino +++ b/examples/INA228_demo_energy_charge/INA228_demo_energy_charge.ino @@ -15,8 +15,8 @@ INA228 INA(0x40); void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/examples/INA228_demo_two_devices/INA228_demo_two_devices.ino b/examples/INA228_demo_two_devices/INA228_demo_two_devices.ino index 0afdd0e..9742b67 100644 --- a/examples/INA228_demo_two_devices/INA228_demo_two_devices.ino +++ b/examples/INA228_demo_two_devices/INA228_demo_two_devices.ino @@ -15,8 +15,8 @@ INA228 INA2(0x41); void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/examples/INA228_dump_config/INA228_dump_config.ino b/examples/INA228_dump_config/INA228_dump_config.ino index 261663d..9939f85 100644 --- a/examples/INA228_dump_config/INA228_dump_config.ino +++ b/examples/INA228_dump_config/INA228_dump_config.ino @@ -14,8 +14,8 @@ INA228 INA(0x40); void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/examples/INA228_meta_data/INA228_meta_data.ino b/examples/INA228_meta_data/INA228_meta_data.ino index 3c4d635..77d477a 100644 --- a/examples/INA228_meta_data/INA228_meta_data.ino +++ b/examples/INA228_meta_data/INA228_meta_data.ino @@ -14,8 +14,8 @@ INA228 INA(0x40); void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/examples/INA228_performance/INA228_performance.ino b/examples/INA228_performance/INA228_performance.ino index dbf9d61..fa3fc35 100644 --- a/examples/INA228_performance/INA228_performance.ino +++ b/examples/INA228_performance/INA228_performance.ino @@ -19,8 +19,8 @@ volatile uint16_t value; void setup() { Serial.begin(115200); - Serial.println(__FILE__); Serial.println(); + Serial.println(__FILE__); Serial.print("INA228_LIB_VERSION: "); Serial.println(INA228_LIB_VERSION); Serial.println(); diff --git a/library.json b/library.json index 8a2308b..1b2a3ce 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/INA228.git" }, - "version": "0.4.0", + "version": "0.4.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 07df918..5a5bdee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=INA228 -version=0.4.0 +version=0.4.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for the INA228, I2C, 20 bit, voltage, current and power sensor.