
Arduino Quick Start


G2 (SDA) and G1 (SCL).5kg. To avoid damaging the sensor, do not exceed the rated capacity. Zero calibration or taring is recommended before the first measurement.#include <M5Unified.h>
#include <M5GFX.h>
#include "UNIT_SCALES.h"
M5Canvas canvas(&M5.Lcd);
UNIT_SCALES scales;
void setup() {
M5.begin();
M5.Lcd.begin();
canvas.setFont(&fonts::FreeMonoBold12pt7b);
canvas.createSprite(M5.Lcd.width(), M5.Lcd.height());
// Initialize PORT.A I2C and retry until the unit responds.
Wire.begin();
while (!scales.begin(&Wire, EX_SDA, EX_SCL, DEVICE_DEFAULT_ADDR)) {
Serial.println("Unit Mini Scales connect error");
M5.Lcd.print("Unit Mini Scales connect error");
delay(1000);
}
// Set the unit status LED to dim green.
scales.setLEDColor(0x001000);
}
void loop() {
float weight = scales.getWeight();
float gap = scales.getGapValue();
int adc = scales.getRawADC();
// Redraw the weight and raw ADC values.
canvas.fillSprite(BLACK);
canvas.drawCenterString("Unit Mini Scale Test", 160, 10);
canvas.setTextColor(WHITE);
canvas.setCursor(10, 50);
canvas.printf("WEIGHT:");
canvas.setTextColor(GREEN);
canvas.printf("%.2fg", weight);
canvas.setCursor(10, 100);
canvas.setTextColor(WHITE);
canvas.printf("ADC:");
canvas.setTextColor(GREEN);
canvas.printf("%d", adc);
canvas.setTextColor(ORANGE);
canvas.drawCenterString("Touch Screen to Offset", 160, 200);
canvas.pushSprite(0, 0);
// Tap the screen to use the current load as the zero offset.
M5.update();
if (M5.Touch.getDetail().wasClicked()) {
scales.setOffset();
}
}
setOffset() and set the current load as zero. After taring, place an object on or remove it from the weighing plate to observe changes in the weight and ADC values.