
Arduino Quick Start
Environment setup: Refer to Getting Started with Arduino IDE to complete the IDE installation, and install the corresponding board manager and required driver libraries according to your development board.
Required libraries:
Required hardware products:

G15 (SCL) and G13 (SDA), RGB LED IO are P5 (SYS_LEDR), P6 (SYS_LEDG), P7 (SYS_LEDB), and relay switch IO is P2 (REL_EN).The physical connection and assembly are shown below:
#include "M5StamPLC.h"
M5StamPLC_AC stamplc_ac;
void setup()
{
/* Init M5StamPLC */
M5StamPLC.begin();
M5StamPLC.Display.setFont(&fonts::FreeMonoBold12pt7b);
M5StamPLC.Display.drawCenterString("StamPLC AC", 120, 60);
/* Init M5StamPLC-AC */
while (!stamplc_ac.begin()) {
printf("M5StamPLC-AC init failed, retry in 1s...\n");
delay(1000);
}
}
void loop()
{
static bool relay_state = false;
/* Toggle M5StamPLC-AC relay state */
relay_state = !relay_state;
stamplc_ac.writeRelay(relay_state);
printf("Write M5StamPLC-AC Relay to %s\n", stamplc_ac.readRelay() ? "ON" : "OFF");
if (relay_state)
{
stamplc_ac.setStatusLight(0, 1, 0);
printf("Set M5StamPLC-AC status light to green\n");
}
else
{
stamplc_ac.setStatusLight(1, 0, 0);
printf("Set M5StamPLC-AC status light to red\n");
}
delay(1000);
}
Serial monitor feedback is as follows:
Write M5StamPLC-AC Relay to ON
Set M5StamPLC-AC status light to green
Write M5StamPLC-AC Relay to OFF
Set M5StamPLC-AC status light to red
...