
Arduino Quick Start
APIs and example programs related to the display of CoreP4X.
3.3.10-aM5CoreP4X0.3.10.3.1The display reset is controlled by M5IOE1 IO11, the backlight by M5IOE1 IO9/PWM1, the display power by M5IOE1 IO10, and the touch reset by M5IOE1 IO8. After power-on, M5Unified automatically completes panel initialization and power enabling.
#include <M5Unified.h>
M5Canvas canvas(&M5.Display);
static void drawBorder()
{
const int screenW = M5.Display.width();
const int screenH = M5.Display.height();
canvas.drawRect(0, 0, screenW, screenH, TFT_BLACK);
canvas.drawRect(4, 4, screenW - 8, screenH - 8, TFT_BLACK);
canvas.drawRect(8, 8, screenW - 16, screenH - 16, TFT_BLACK);
}
static void drawMainDemo()
{
const int screenW = M5.Display.width();
const int centerX = screenW / 2;
canvas.fillSprite(TFT_WHITE);
drawBorder();
canvas.setTextDatum(middle_center);
canvas.setTextSize(1);
canvas.setFont(&fonts::FreeSansBold24pt7b);
canvas.setTextColor(TFT_BLACK);
canvas.drawString("CORE", centerX, 150);
canvas.setTextColor(TFT_BLUE);
canvas.drawString("P4X", centerX, 214);
canvas.setFont(&fonts::FreeSansBold12pt7b);
canvas.setTextColor(TFT_BLACK);
canvas.drawString("Panel: ST7102 + CST3530", centerX, 292);
char resolutionText[32];
snprintf(resolutionText, sizeof(resolutionText), "Resolution: %d x %d", screenW, M5.Display.height());
canvas.setFont(&fonts::FreeSans18pt7b);
canvas.setTextColor(TFT_BLUE);
canvas.drawString(resolutionText, centerX, 338);
canvas.setFont(&fonts::FreeSans12pt7b);
canvas.setTextColor(TFT_BLACK);
canvas.drawString("MIPI DSI 2-Lane", centerX, 382);
const uint16_t colors[] = {
TFT_RED, TFT_YELLOW, TFT_GREEN, TFT_CYAN, TFT_BLUE, TFT_MAGENTA
};
const int barX = 40;
const int barY = 420;
const int barW = screenW - 80;
const int barH = 36;
const int cellW = barW / 6;
for (int i = 0; i < 6; ++i) {
const int x = barX + i * cellW;
const int w = (i == 5) ? (barX + barW - x) : cellW;
canvas.fillRect(x, barY, w, barH, colors[i]);
canvas.drawRect(x, barY, w, barH, TFT_BLACK);
}
canvas.pushSprite(0, 0);
}
void setup()
{
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5.begin(cfg);
M5.Display.setRotation(0);
M5.Display.setBrightness(160);
canvas.createSprite(M5.Display.width(), M5.Display.height());
drawMainDemo();
Serial.printf("display: %d x %d\n", M5.Display.width(), M5.Display.height());
}
void loop()
{
M5.update();
delay(100);
}After uploading, the screen displays the CoreP4X product name, ST7102 panel information, 480 x 480 resolution, MIPI DSI interface description, and a six-color test bar at the bottom on a white background.
