Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Feb 3, 2025
2 parents 79a5e16 + eb4754a commit 98e162a
Show file tree
Hide file tree
Showing 19 changed files with 541 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-esp-v2-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

unit:
- UnitWeightI2C
# - UnitMiniscale
- UnitMiniScales

board:
- m5stack-atom
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arduino-esp-v3-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

unit:
- UnitWeightI2C
# - UnitMiniscale
- UnitMiniScales

board:
- m5stack_atom
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arduino-m5-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

unit:
- UnitWeightI2C
# - UnitMiniscale
- UnitMiniScales

board:
- m5stack_atom
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/platformio-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

unit:
- UnitWeightI2C
# - UnitMiniscale
- UnitMiniScales

board:
- Core
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ M5UnitUnified is a library for unified handling of various M5 units products.

The Weight I2C Unit is a weight acquisition transducer unit that employs the "STM32+HX711 chip" solution, achieving precision weight measurement with 24-bit accuracy through I2C communication. It supports the parallel connection of multiple devices on the same I2C bus, providing users with greater flexibility in terms of a wider range and more data collection points. It is suitable for various applications such as industrial production, healthcare, logistics, laboratory research, and food processing.

### SKU:U177

Mini Scales Unit is an integrated mini weighing unit that combines a 5kg weighing sensor, an ADC acquisition chip (HX711), and a protocol conversion MCU to directly output weighing results. The product is equipped with an STM32F030F4P6 microcontroller, uses the I2C communication protocol for external communication, and supports multiple modules working together.

## Related Link
See also examples using conventional methods here.

- [Unit WeightI2C & Datasheet](https://docs.m5stack.com/en/unit/Unit-Weight%20I2C)

- [Unit MiniScales & Datashhet](https://docs.m5stack.com/en/unit/Unit-Mini%20Scales)

### Required Libraries:
- [M5UnitUnified](https://github.com/m5stack/M5UnitUnified)
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = M5Unit-WeightI2C
PROJECT_NAME = M5Unit-WEIGHT

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for UnitMiniScales
*/
#include "main/PlotToSerial.cpp"
111 changes: 111 additions & 0 deletions examples/UnitUnified/UnitMiniScales/PlotToSerial/main/PlotToSerial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for UnitMiniScales
*/
#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <M5UnitUnifiedWEIGHT.h>
#include <M5Utility.h>

using m5::unit::weighti2c::Mode;

namespace {
auto& lcd = M5.Display;
m5::unit::UnitUnified Units;
m5::unit::UnitMiniScales unit;

uint32_t idx{};
constexpr Mode mode_table[] = {Mode::Float, Mode::Int};

constexpr lgfx::rgb888_t color_table[] = {
{128, 16, 32},
{32, 128, 16},
{16, 32, 128},
{0, 0, 0},
};

} // namespace

void setup()
{
m5::utility::delay(2000);

M5.begin();

auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
Wire.begin(pin_num_sda, pin_num_scl, 100 * 1000U);

if (!Units.add(unit, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
unit.resetOffset();

M5_LOGI("M5UnitUnified has been begun");
M5_LOGI("%s", Units.debugInfo().c_str());

lcd.clear(TFT_DARKGREEN);
}

void loop()
{
M5.update();
auto touch = M5.Touch.getDetail();

Units.update();
if (unit.updated()) {
// Can be checked e.g. by serial plotters
if (!idx) {
M5_LOGI("\n>Weight:%f", unit.weight());
} else {
M5_LOGI("\n>iWeight:%d", unit.iweight());
}
}

// Button on MiniScales
if (unit.wasPressed()) {
static uint32_t cidx{};
unit.writeLEDColor((uint32_t)color_table[cidx]);
cidx = ++cidx % m5::stl::size(color_table);
}

// Behavior when BtnA is clicked changes depending on the value.
constexpr int32_t BTN_A_FUNCTION{-1};

if (M5.BtnA.wasClicked() || touch.wasClicked()) {
switch (BTN_A_FUNCTION) {
case 0: { // Change mode
if (++idx > 1) {
idx = 0;
}
unit.stopPeriodicMeasurement();
unit.startPeriodicMeasurement(mode_table[idx]);
} break;
case 1: { // Singleshot as text
static uint32_t sscnt{};
unit.stopPeriodicMeasurement();
char txt[16]{};
if (unit.measureSingleshot(txt)) {
M5_LOGI("\n>Singleshort:%s", txt);
} else {
M5_LOGE("Failed to measure");
}
// Return to periodic measurement after 8 measurements
if (++sscnt >= 8) {
sscnt = 0;
unit.startPeriodicMeasurement(Mode::Float);
}

} break;
}
}
}
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"M5UnitUnified": "https://github.com/m5stack/M5UnitUnified.git"
},
"version": "0.0.1",
"version": "0.0.2",
"frameworks": [
"arduino"
],
Expand All @@ -27,4 +27,4 @@
"docs/html"
]
}
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5Unit-WEIGHT
version=0.0.1
version=0.0.2
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack UNIT METER using M5UnitUnified
Expand Down
Loading

0 comments on commit 98e162a

Please sign in to comment.