
Arduino Quick Start

G1 (SCL) and G2 (SDA). The example converts the current register value at 0.01mA/LSB into mA and also displays the raw ADC value limited to its lower 12 bits.#include <M5Unified.h>
#include "MODULE_4_20MA.h"
#include <M5GFX.h>
MODULE_4_20MA meter;
void show_current_value(void) {
M5.Display.fillScreen(WHITE);
M5.Display.setCursor(0, 0);
M5.Display.println("Unit 4-20mA Demo");
M5.Display.setCursor(0, 50);
const uint16_t current_raw = meter.getCurrentValue(0);
const uint16_t adc_raw = meter.getADC12BitsValue(0) & 0x0FFF;
M5.Display.printf("Current: %.2f mA\r\n", current_raw / 100.0f);
M5.Display.printf("ADC raw: %u", static_cast<unsigned>(adc_raw));
}
void setup() {
M5.begin();
Serial.begin(115200);
M5.Display.fillScreen(WHITE);
M5.Display.setTextColor(BLACK);
M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
M5.Display.setCursor(0, 0);
while (!(meter.begin(&Wire, MODULE_4_20MA_ADDR, 2, 1, 100000UL))) {
M5.Display.println("No Module!");
}
}
void loop() {
show_current_value();
delay(1000);
}Download Mode: Different devices require entering download mode before program burning. This step may vary depending on the main control device. For details, refer to the device program download tutorial list at the bottom of the Arduino IDE Getting Started Guide page for specific operations.
For CoreS3: Press and hold the reset button (about 2 seconds) until the internal green LED lights up, then release. The device will now enter download mode and wait for burning. The green LED turns off after the button is released, confirming that the device is in download mode.
