G11 (SCL)
, G12 (SDA)
.#include <M5Unified.h>
#include <M5GFX.h>
#include "MODULE_4_20MA.h"
#define channel 3
M5GFX display;
MODULE_4_20MA meter;
void show_current_value(void) {
M5.Display.fillScreen(WHITE);
M5.Display.setCursor(0, 0);
M5.Display.println("Module 4-20mA Demo");
M5.Display.setCursor(0, 50);
M5.Display.printf("CH%d Current:%.2fmA\r\n", channel,
(float)(meter.getCurrentValue(channel - 1)) / 100.0);
Serial.printf("CH%d ADC_12Bits_Value:%d\r\n", channel, meter.getADC12BitsValue(channel - 1));
M5.Display.printf("CH%d ADC_12Bits_Value:%d\r\n", channel, meter.getADC12BitsValue(channel - 1));
M5.Display.printf("CH%d Cal_Current:%d\r\n", channel, meter.getCurrentValue(channel - 1));
}
void setup() {
M5.begin();
Serial.begin(115200);
M5.Display.fillScreen(WHITE);
M5.Display.setTextColor(BLACK);
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
M5.Display.setCursor(0, 0);
M5.Display.println("Module 4-20mA Demo");
while (!(meter.begin(&Wire, MODULE_4_20MA_ADDR, 12, 11, 100000UL))) {
M5.Display.fillScreen(WHITE);
M5.Display.setCursor(0, 0);
M5.Display.println("No Module!");
}
Serial.printf("Firmware Version:%d.%d.%d\r\n", meter.getFirmwareVersion(),
meter.getI2CAddress(), meter.getFirmwareVersion());
Serial.printf("I2C Address:%02X\r\n", meter.getI2CAddress());
delay(500);
}
void loop() {
show_current_value();
delay(1000);
}
Download Mode: Different devices need to enter download mode before program burning, and this step may vary for different main control devices. For details, please refer to the device program download tutorial list at the bottom of the Arduino IDE Getting Started Guide page to view specific operation methods.
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.