Skip to content

Commit 6a6ea23

Browse files
committed
Merge branch 'develop'
2 parents 3a4ce01 + d665de4 commit 6a6ea23

File tree

15 files changed

+2109
-18
lines changed

15 files changed

+2109
-18
lines changed

.github/workflows/arduino-esp-v2-build-check.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
- 'examples/UnitUnified/**.hpp'
2222
- 'examples/UnitUnified/**.h'
2323
- 'examples/UnitUnified/**.c'
24-
- '**arduino-esp-v2-build-check.yml'
24+
- '**/arduino-esp-v2-build-check.yml'
2525
pull_request:
2626
paths:
2727
- 'src/unit/**.cpp'
@@ -33,7 +33,7 @@ on:
3333
- 'examples/UnitUnified/**.hpp'
3434
- 'examples/UnitUnified/**.h'
3535
- 'examples/UnitUnified/**.c'
36-
- '**arduino-esp-v2-build-check.yml'
36+
- '**/arduino-esp-v2-build-check.yml'
3737
workflow_dispatch:
3838

3939
defaults:
@@ -65,6 +65,7 @@ jobs:
6565
- UnitVmeter
6666
- UnitKmeterISO
6767
- UnitDualKmeter
68+
- UnitINA226
6869

6970
board:
7071
- m5stack-atom
@@ -84,6 +85,9 @@ jobs:
8485
archi:
8586
- esp32
8687

88+
build-properties:
89+
- "-DUSING_UNIT_INA226_10A"
90+
8791
include:
8892
# Specific sketches
8993
- sketch: GraphicalMeter

.github/workflows/arduino-esp-v3-build-check.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020
- 'examples/UnitUnified/**.hpp'
2121
- 'examples/UnitUnified/**.h'
2222
- 'examples/UnitUnified/**.c'
23-
- '**arduino-esp-v3-build-check.yml'
23+
- '**/arduino-esp-v3-build-check.yml'
2424
pull_request:
2525
paths:
2626
- 'src/unit/**.cpp'
@@ -32,7 +32,7 @@ on:
3232
- 'examples/UnitUnified/**.hpp'
3333
- 'examples/UnitUnified/**.h'
3434
- 'examples/UnitUnified/**.c'
35-
- '**arduino-esp-v3-build-check.yml'
35+
- '**/arduino-esp-v3-build-check.yml'
3636
workflow_dispatch:
3737

3838
defaults:
@@ -64,6 +64,7 @@ jobs:
6464
- UnitVmeter
6565
- UnitKmeterISO
6666
- UnitDualKmeter
67+
- UnitINA226
6768

6869
board:
6970
- m5stack_atom
@@ -100,6 +101,9 @@ jobs:
100101
archi:
101102
- esp32
102103

104+
build-properties:
105+
- "-DUSING_UNIT_INA226_10A"
106+
103107
include:
104108
# Specific sketches
105109
- sketch: GraphicalMeter

.github/workflows/arduino-m5-build-check.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ on:
2525
- 'examples/UnitUnified/**.hpp'
2626
- 'examples/UnitUnified/**.h'
2727
- 'examples/UnitUnified/**.c'
28-
- '**arduino-m5-build-check.yml'
28+
- '**/arduino-m5-build-check.yml'
2929
pull_request:
3030
paths:
3131
- 'src/unit/**.cpp'
@@ -41,7 +41,7 @@ on:
4141
- 'examples/UnitUnified/**.hpp'
4242
- 'examples/UnitUnified/**.h'
4343
- 'examples/UnitUnified/**.c'
44-
- '**arduino-m5-build-check.yml'
44+
- '**/arduino-m5-build-check.yml'
4545
workflow_dispatch:
4646

4747
defaults:
@@ -73,6 +73,7 @@ jobs:
7373
- UnitVmeter
7474
- UnitKmeterISO
7575
- UnitDualKmeter
76+
- UnitINA226
7677

7778
board:
7879
- m5stack_atom
@@ -102,40 +103,43 @@ jobs:
102103
# - m5stack_unit_cams3
103104

104105
platform-version:
105-
- 2.1.2
106+
- 3.2.1
106107

107108
platform:
108109
- m5stack
109110

110111
archi:
111112
- esp32
112113

114+
build-properties:
115+
- "-DUSING_UNIT_INA226_10A"
116+
113117
include:
114118
# Specific sketches
115119
- sketch: GraphicalMeter
116120
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
117-
platform-version: 2.1.2
121+
platform-version: 3.2.1
118122
platform: m5stack
119123
archi: esp32
120124
board: m5stack_core
121125
build-properties: "-DUSING_UNIT_VMETER"
122126
- sketch: GraphicalMeter
123127
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
124-
platform-version: 2.1.2
128+
platform-version: 3.2.1
125129
platform: m5stack
126130
archi: esp32
127131
board: m5stack_core
128132
build-properties: "-DUSING_UNIT_AMETER"
129133
- sketch: GraphicalMeter
130134
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
131-
platform-version: 2.1.2
135+
platform-version: 3.2.1
132136
platform: m5stack
133137
archi: esp32
134138
board: m5stack_core
135139
build-properties: "-DUSING_UNIT_KMETER_ISO"
136140
- sketch: GraphicalMeter
137141
platform-url: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
138-
platform-version: 2.1.2
142+
platform-version: 3.2.1
139143
platform: m5stack
140144
archi: esp32
141145
board: m5stack_core

.github/workflows/platformio-build-check.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ on:
2121
- 'examples/UnitUnified/**.hpp'
2222
- 'examples/UnitUnified/**.h'
2323
- 'examples/UnitUnified/**.c'
24-
- '/platformio-build-check.yml'
25-
- '**platformio.ini'
24+
- '**/platformio-build-check.yml'
25+
- '**/platformio.ini'
2626
pull_request:
2727
paths:
2828
- 'src/unit/**.cpp'
@@ -39,7 +39,7 @@ on:
3939
- 'examples/UnitUnified/**.h'
4040
- 'examples/UnitUnified/**.c'
4141
- '**/platformio-build-check.yml'
42-
- '**platformio.ini'
42+
- '**/platformio.ini'
4343
workflow_dispatch:
4444

4545
defaults:
@@ -69,6 +69,7 @@ jobs:
6969
- UnitVmeter
7070
- UnitKmeterISO
7171
- UnitDualKmeter
72+
- UnitINA226_10A
7273

7374
board:
7475
- Core
@@ -146,6 +147,11 @@ jobs:
146147
framework: Arduino
147148
espressif32: latest
148149
unit: UnitDualKmeter
150+
- example: PlotToSerial
151+
board: Core
152+
framework: Arduino
153+
espressif32: latest
154+
unit: UnitINA226_1A
149155

150156
exclude:
151157
- unit: UnitDualKmeter

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ At the same time, the module also has built-in voltage and signal isolation chip
4343

4444
In addition, the module has a built-in dial code on off, which can easily switch different I2C addresses to meet the different application needs of users. It can be applied to multiple scenarios such as industrial automation and instrument detection.
4545

46+
### SKU:U200
47+
48+
Unit INA226-10A is a fully isolated high-precision current and voltage measurement unit, suitable for scenarios measuring DC 0 ~ 30V voltage and up to 10A current, supporting simultaneous voltage and current measurements.
49+
50+
### SKU:U200-1A
51+
52+
Unit INA226-1A is a fully isolated high-precision current, voltage, and power measurement unit, suitable for scenarios measuring DC 0 ~ 30V voltage and up to 1A current, supporting simultaneous voltage and current measurements.
4653

4754
## Related Link
4855
See also examples using conventional methods here.
@@ -51,6 +58,8 @@ See also examples using conventional methods here.
5158
- [Unit Vmeter & Datasheet](https://docs.m5stack.com/en/unit/vmeter)
5259
- [Unit KMeterISO & Datasheet](https://docs.m5stack.com/en/unit/KMeterISO%20Unit)
5360
- [Unit DualKmeter & Datasheet](https://docs.m5stack.switch-science.com/en/module/DualKmeter%20Module13.2)
61+
- [Unit INA226-10A & Datasheet](https://docs.m5stack.com/en/unit/Unit_INA226-10A)
62+
- [Unit INA226-1A & Datasheet](https://docs.m5stack.com/en/unit/Unit_INA226-1A)
5463

5564

5665
## Required Libraries:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
Example using M5UnitUnified for UnitINA226
8+
*/
9+
// *************************************************************
10+
// Choose one define symbol to match the unit you are using
11+
// *************************************************************
12+
#if !defined(USING_UNIT_INA226_1A) && !defined(USING_UNIT_INA226_10A) && !defined(USING_UNIT_INA226_10A_IN_TAB5)
13+
// #define USING_UNIT_INA226_1A
14+
// #define USING_UNIT_INA226_10A
15+
// #define USING_UNIT_INA226_10A_IN_TAB5
16+
#endif
17+
#include "main/PlotToSerial.cpp"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
Example: UnitINA226
8+
*/
9+
#include <M5Unified.h>
10+
#include <M5UnitUnified.h>
11+
#include <M5UnitUnifiedMETER.h>
12+
#include <Wire.h>
13+
14+
// *************************************************************
15+
// Choose one define symbol to match the unit you are using
16+
// *************************************************************
17+
#if !defined(USING_UNIT_INA226_1A) && !defined(USING_UNIT_INA226_10A) && !defined(USING_UNIT_INA226_10A_IN_TAB5)
18+
// #define USING_UNIT_INA226_1A
19+
// #define USING_UNIT_INA226_10A
20+
// #define USING_UNIT_INA226_10A_IN_TAB5
21+
#endif
22+
23+
namespace {
24+
auto& lcd = M5.Display;
25+
m5::unit::UnitUnified Units;
26+
#if defined(USING_UNIT_INA226_1A)
27+
28+
#pragma message "Using 1A"
29+
m5::unit::UnitINA226_1A unit;
30+
31+
#elif defined(USING_UNIT_INA226_10A)
32+
33+
#pragma message "Using 10A"
34+
m5::unit::UnitINA226_10A unit;
35+
36+
#elif defined(USING_UNIT_INA226_10A_IN_TAB5)
37+
38+
#pragma message "Using 10A (Tab5)"
39+
m5::unit::UnitINA226_10A unit;
40+
#if !defined(CONFIG_IDF_TARGET_ESP32P4)
41+
#error "Compile not for Tab5"
42+
#endif
43+
44+
#else
45+
#error "Choose unit"
46+
#endif
47+
} // namespace
48+
49+
void setup()
50+
{
51+
M5.begin();
52+
53+
// The screen shall be in landscape mode
54+
if (lcd.height() > lcd.width()) {
55+
lcd.setRotation(1);
56+
}
57+
58+
#if defined(USING_UNIT_INA226_10A_IN_TAB5)
59+
auto board = M5.getBoard();
60+
if (board != m5::board_t::board_M5Tab5) {
61+
M5_LOGE("Core is NOT Tab5");
62+
while (true) {
63+
m5::utility::delay(10000);
64+
}
65+
}
66+
auto pin_num_sda = 31;
67+
auto pin_num_scl = 32;
68+
M5_LOGI("Pin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
69+
Wire1.end();
70+
Wire1.begin(pin_num_sda, pin_num_scl, 400000U);
71+
72+
if (!Units.add(unit, Wire1) || !Units.begin()) {
73+
M5_LOGE("Failed to begin");
74+
lcd.clear(TFT_RED);
75+
while (true) {
76+
m5::utility::delay(10000);
77+
}
78+
}
79+
80+
#else
81+
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
82+
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
83+
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
84+
85+
Wire.end();
86+
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
87+
if (!Units.add(unit, Wire) || !Units.begin()) {
88+
M5_LOGE("Failed to begin");
89+
lcd.clear(TFT_RED);
90+
while (true) {
91+
m5::utility::delay(10000);
92+
}
93+
}
94+
#endif
95+
96+
lcd.setFont(&fonts::AsciiFont8x16);
97+
98+
M5_LOGI("M5UnitUnified has been begun");
99+
M5_LOGI("%s", Units.debugInfo().c_str());
100+
lcd.clear(TFT_DARKGREEN);
101+
}
102+
103+
void loop()
104+
{
105+
using namespace m5::unit::ina226;
106+
107+
M5.update();
108+
auto touch = M5.Touch.getDetail();
109+
Units.update();
110+
111+
if (unit.updated()) {
112+
M5.Log.printf(">A:%f\n>SV:%f\n>BV:%f\n>W:%f\n", unit.current(), unit.shuntVoltage(), unit.voltage(),
113+
unit.power());
114+
115+
lcd.startWrite();
116+
lcd.fillRect(0, 0, lcd.width(), 16 * 4);
117+
lcd.setCursor(0, 0);
118+
lcd.printf(
119+
" C:%5.2f mA\n"
120+
"SV:%5.2f mV\n"
121+
"BV:%5.2f mV\n"
122+
" P:%5.2f mW",
123+
unit.current(), unit.shuntVoltage(), unit.voltage(), unit.power());
124+
lcd.endWrite();
125+
}
126+
127+
if (M5.BtnA.wasClicked() || touch.wasClicked()) {
128+
static bool single{};
129+
single = !single;
130+
if (single) {
131+
M5.Speaker.tone(1500, 20);
132+
Data d{};
133+
unit.stopPeriodicMeasurement();
134+
if (unit.measureSingleshot(d)) {
135+
M5.Log.printf("Single:A:%f SV:%f BV:%f W:%f\n", unit.current(), unit.shuntVoltage(), unit.voltage(),
136+
unit.power());
137+
} else {
138+
M5_LOGE("Failed to measureSingleshot");
139+
}
140+
} else {
141+
M5.Speaker.tone(2500, 20);
142+
M5.Log.printf("Start periodic\n");
143+
unit.startPeriodicMeasurement();
144+
}
145+
}
146+
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"m5stack/M5UnitUnified": ">=0.1.0"
1515
},
16-
"version": "0.2.0",
16+
"version": "0.2.1",
1717
"frameworks": [
1818
"arduino"
1919
],

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5Unit-METER
2-
version=0.2.0
2+
version=0.2.1
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack UNIT METER using M5UnitUnified

0 commit comments

Comments
 (0)