G1 (SCL)
and G2 (SDA)
.#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);
M5.Display.printf("Current:%.2fmA\r\n", (float)(meter.getCurrentValue(0)) / 100.0);
M5.Display.printf("ADC_Value:%.2f\r\n", (float)(meter.getADC12BitsValue(0)) / 100.0);
M5.Display.printf("Cal_Current:%.2fmA", (float)(meter.getCurrentValue(0)));
}
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.