The M5Core screen is 320x240
pixels, with the upper left corner of the screen as the origin (0,0).
The following API uses the RGB565 color coding format
Color code.
COLOR | HEX | R | G | B |
---|---|---|---|---|
BLACK | 0x0000 | 0 | 0 | 0 |
NAVY | 0x000F | 0 | 0 | 128 |
DARKGREEN | 0x03E0 | 0 | 128 | 0 |
MAROON | 0x7800 | 128 | 0 | 0 |
PURPLE | 0x780F | 128 | 0 | 128 |
OLIVE | 0x7BE0 | 128 | 128 | 0 |
LIGHTGREY | 0xC618 | 192 | 192 | 192 |
DARKGREY | 0x7BEF | 128 | 128 | 128 |
BLUE | 0x001F | 0 | 0 | 255 |
GREENYELLOW | 0xB7E0 | 180 | 255 | 0 |
GREEN | 0x07E0 | 0 | 255 | 0 |
YELLOW | 0xFFE0 | 255 | 255 | 0 |
ORANGE | 0xFDA0 | 255 | 180 | 0 |
PINK | 0xFC9F | 255 | 255 | 16 |
CYAN | 0x07FF | 0 | 255 | 255 |
DARKCYAN | 0x03EF | 0 | 128 | 128 |
RED | 0xF800 | 255 | 0 | 0 |
MAGENTA | 0xF81F | 255 | 0 | 255 |
WHITE | 0xFFFF | 255 | 255 | 255 |
Syntax:
void begin();
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
}
void loop() {
}
Syntax:
void sleep();
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
M5.Lcd.sleep();
}
void loop() {
}
Syntax:
void clear()
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
M5.Power.begin();
M5.Lcd.fillScreen(RED);
delay(1000);
M5.Lcd.clear();
}
void loop() {
}
Syntax:
void wakeup();
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
M5.Power.begin();
M5.Lcd.fillScreen(RED);
delay(1000);
M5.Lcd.sleep();
delay(6000);
M5.Lcd.wakeup();
}
void loop() {
}
Syntax:
int16_t height(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print(M5.Lcd.height());
}
void loop() {
}
Syntax:
int16_t width(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print(M5.Lcd.width());
}
void loop() {
}
Syntax:
int16_t getCursorX(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print("Hello");
int X = M5.Lcd.getCursorX();
M5.Lcd.print(X);
}
void loop(){
}
Syntax:
int16_t getCursorY(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print("Hello");
int X = M5.Lcd.getCursorY();
M5.Lcd.print(Y);
}
void loop(){
}
Syntax:
uint8_t getRotation()
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print(M5.Lcd.getRotation());
}
void loop(){
}
Syntax:
uint8_t getTextDatum(void);
Description:
Parameters:
Return:
// These enumerate the text plotting alignment (reference datum point)
#define TL_DATUM 0 // Top left (default)
#define TC_DATUM 1 // Top centre
#define TR_DATUM 2 // Top right
#define ML_DATUM 3 // Middle left
#define CL_DATUM 3 // Centre left, same as above
#define MC_DATUM 4 // Middle centre
#define CC_DATUM 4 // Centre centre, same as above
#define MR_DATUM 5 // Middle right
#define CR_DATUM 5 // Centre right, same as above
#define BL_DATUM 6 // Bottom left
#define BC_DATUM 7 // Bottom centre
#define BR_DATUM 8 // Bottom right
#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on)
#define C_BASELINE 10 // Centre character baseline
#define R_BASELINE 11 // Right character baseline
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.drawString("hello", 160, 120, 2);
M5.Lcd.print(M5.Lcd.getTextDatum());
}
void loop(){
}
Syntax:
void setCursor(int16_t x, int16_t y);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setCursor(0, 30);
M5.Lcd.printf("Hello M5");
}
void loop() {}
Syntax:
void setRotation(uint8_t m);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setRotation(2);
M5.Lcd.fillEllipse(160, 100, 60, 100, YELLOW);
delay(1000);
M5.Lcd.setRotation(1);
M5.Lcd.fillEllipse(160, 100, 60, 100, GREEN);
}
void loop() {}
Syntax:
void setBrightness(uint8_t brightness);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillScreen(RED);
}
void loop() {
M5.update();
for(int i=0; i<255;i++){
M5.Lcd.setBrightness(i);
delay(10);
}
for(int i=255; i>0;i--){
M5.Lcd.setBrightness(i);
delay(10);
}
}
Syntax:
uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
M5.Power.begin();
M5.Lcd.fillScreen(M5.Lcd.alphaBlend(128, 0X00FF00, 0XFF0000));
}
void loop() {
}
Syntax:
void loadFont(String fontName, fs::FS &ffs);
void loadFont(String fontName, bool flash);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.loadFont("filename", SD);
}
void loop() {
}
Syntax:
void unloadFont(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.unloadFont();
}
void loop() {
}
Syntax:
uint16_t fontsLoaded()
Description:
Parameters:
Return:
Return:
#ifdef LOAD_GLCD
fontsloaded = 0x0002; // Bit 1 set
#endif
#ifdef LOAD_FONT2
fontsloaded |= 0x0004; // Bit 2 set
#endif
#ifdef LOAD_FONT4
fontsloaded |= 0x0010; // Bit 4 set
#endif
#ifdef LOAD_FONT6
fontsloaded |= 0x0040; // Bit 6 set
#endif
#ifdef LOAD_FONT7
fontsloaded |= 0x0080; // Bit 7 set
#endif
#ifdef LOAD_FONT8
fontsloaded |= 0x0100; // Bit 8 set
#endif
#ifdef LOAD_FONT8N
fontsloaded |= 0x0200; // Bit 9 set
#endif
#ifdef SMOOTH_FONT
fontsloaded |= 0x8000; // Bit 15 set
#endif
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print(M5.Lcd.fontsLoaded());
}
void loop() {
}
Syntax:
void fillScreen(uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillScreen(RED);
}
void loop(){
}
Syntax:
void invertDisplay(boolean i);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillScreen(RED);
}
void loop() {
M5.Lcd.invertDisplay(1);
delay(1000);
M5.Lcd.invertDisplay(0);
}
Syntax:
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
Description:
Parameters:
uint8_t r:
uint8_t g:
uint8_t b:
uint32_t color:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
uint16_t colorvalue = 0;
colorvalue = color565(255, 255, 255);
M5.Lcd.fillEllipse(160, 100, 60, 100, colorvalue);
}
void loop() {}
Syntax:
size_t print(const char str[]);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.print("this is a print text function");
}
void loop() {
}
Syntax:
int16_t textWidth(const String& string);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
String text = "hello ";
M5.Lcd.print(text);
M5.Lcd.print(M5.Lcd.textWidth(text));
}
void loop() {}
Syntax:
void setTextSize(uint8_t s);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(4);
M5.Lcd.print("Hello M5Stack");
}
void loop() {
}
Syntax:
void setTextColor(uint16_t color);
void setTextColor(uint16_t color, uint16_t backgroundcolor);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextColor(RED,BLACK);
}
void loop(){
}
Syntax:
void setTextWrap(boolean wrapX, boolean wrapY);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextWrap(true, true);
M5.Lcd.print("hello M5Stack hello M5Stack hello M5Stack hello M5Stack hello M5Stack hello M5Stack hello M5Stack hello M5Stack");
}
void loop() {}
Syntax:
void setTextPadding(uint16_t x_width);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
}
void loop() {
M5.Lcd.drawString("Orbitron 32", 160, 60, 2);
delay(2000);
M5.Lcd.setTextPadding(M5.Lcd.width() - 20);
M5.Lcd.drawString("Orbitron 32 with padding", 160, 60, 2);
delay(2000);
}
Syntax:
void setTextDatum(uint8_t datum);
Description:
Parameters:
Return:
// These enumerate the text plotting alignment (reference datum point)
#define TL_DATUM 0 // Top left (default)
#define TC_DATUM 1 // Top centre
#define TR_DATUM 2 // Top right
#define ML_DATUM 3 // Middle left
#define CL_DATUM 3 // Centre left, same as above
#define MC_DATUM 4 // Middle centre
#define CC_DATUM 4 // Centre centre, same as above
#define MR_DATUM 5 // Middle right
#define CR_DATUM 5 // Centre right, same as above
#define BL_DATUM 6 // Bottom left
#define BC_DATUM 7 // Bottom centre
#define BR_DATUM 8 // Bottom right
#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on)
#define C_BASELINE 10 // Centre character baseline
#define R_BASELINE 11 // Right character baseline
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.drawString("hello", 160, 120, 2);
}
void loop(){
}
Syntax:
void drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawFastHLine(3, 100, 255, GREEN);
}
void loop() {
}
Syntax:
void drawFastVLine(int32_t x, int32_t y, int32_t w, uint32_t color);
Description:
Parameters:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawFastVLine(100, 0, 255, TFT_GREEN);
}
void loop(){
}
Syntax:
int16_t drawString(const char *string, int32_t poX, int32_t poY, uint8_t font);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawString("Hello M5", 160, 100, 2);
}
void loop(){
}
Syntax:
void drawNumber(long long_num, int32_t poX, int32_t poY);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawNumber(99, 55, 100);
}
void loop(){
}
Description:
Syntax:
int16_t drawChar(int16_t uniCode, int32_t x, uint16_t y, uint8_t font);
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawChar('A', 160, 120, 2);
}
void loop(){
}
Syntax:
int16_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawFloat(3.1415928,7,100,100);
}
void loop() {}
Syntax:
void drawPixel(int32_t x, int32_t y, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawPixel(22,22,RED);
}
void loop() {}
Syntax:
void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color);
Description:
Parameters:
Return:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawLine(200, 0, 200,2000,GREEN);
}
void loop(){
}
Syntax:
void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawRect(180, 12, 122, 10, BLUE);
}
void loop(){
}
Syntax:
void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillRect(150, 120, 122, 10, BLUE);
}
void loop(){
}
Syntax:
void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawRoundRect(55,55,30,50,10,GREEN);
void loop() {}
Syntax:
void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillRoundRect(55, 55, 30, 50, 10, GREEN);
}
void loop() {}
Syntax:
void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawCircle(100, 100, 50, RED);
}
void loop() {}
Syntax:
void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillCircle(100, 100, 50, RED);
}
void loop() {}
Syntax:
void drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawEllipse(160, 100, 60, 100, YELLOW);
}
void loop() {}
Syntax:
void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillEllipse(160, 100, 60, 100, YELLOW);
}
void loop() {}
Syntax:
void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW);
}
void loop() {}
Syntax:
void fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW);
}
void loop() {}
Syntax:
void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
Description:
Parameters:
Example:
Syntax:
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t *data);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data, uint16_t transparent);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint8_t *data);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint8_t *data);
Description:
Parameters:
Return:
Syntax:
void drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y);
Description:
Parameters:
Return:
Example:
#include "FS.h"
//#include "SPIFFS.h"
#include <M5Stack.h>
void setup(){
M5.begin(true, false, false, false);
M5.Power.begin();
M5.Lcd.drawBmpFile(SD, "/p2.bmp",0,0);
//M5.Lcd.drawBmpFile(SPIFFS, "/p2.bmp", 0, 0);
}
We provide a script that can be used to convert jpg
images -> .c
files, which can be used to convert a number of images and draw them to the screen using the API above:.
Syntax:
void drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x,uint16_t y, uint16_t maxWidth, uint16_t maxHeight,uint16_t offX, uint16_t offY, jpeg_div_t scale);
Description:
Parameters:
Return:
Note:|1. Depending on the size and number of bits may not be able to expand
2. Need to pre-install
Arduino ESP32 filesystem uploader
in advance.
Example:
#include <M5Stack.h>
extern uint8_t tetris_img[];
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.drawJpg(tetris_img, 34215);
}
void loop(){
}
Syntax:
void drawJpgFiledrawJpgFile(fs::FS &fs, const char *path, uint16_t x,uint16_t y,uint16_t maxWidth, uint16_t maxHeight, uint16_t offX,uint16_t offY, jpeg_div_t scale);
Description:
Parameters:
Return:
Syntax:
void progressBar(int x, int y, int w, int h, uint8_t val);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.progressBar(0, 0, 240, 20, 20);
}
void loop() {
}
Syntax:
void qrcode(const char *string, uint16_t x, uint16_t y, uint8_t width, uint8_t version);
void qrcode(const String &string, uint16_t x, uint16_t y, uint8_t width, uint8_t version);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
void setup() {
M5.Lcd.begin();
M5.Power.begin();
M5.Lcd.qrcode("http://www.m5stack.com", 50, 10, 220, 6);
}
void loop() {
}
Syntax:
void* TFT_eSprite::setColorDepth(int8_t b);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.setColorDepth(8);
img.setTextSize(2);
img.createSprite(320, 240);
}
void loop() {}
Syntax:
void *createSprite(int16_t w, int16_t h, uint8_t frames);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.setColorDepth(8); // Set the color depth to 8 bits.
img.createSprite(320, 240); //Create a 320x240 canvas.
img.fillSprite(RED); //Fill the canvas with red.
img.pushSprite(0,0); // Push the canvas to the screen at (0,0).
}
void loop() {}
Syntax:
void fillSprite(uint32_t color);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.setColorDepth(8); // Set the color depth to 8 bits.
img.createSprite(320, 240); //Create a 320x240 canvas.
img.fillSprite(RED); //Fill the canvas with red.
img.pushSprite(0,0); // Push the canvas to the screen at (0,0).
}
void loop() {}
}
void loop() {}
Syntax:
void pushSprite(int32_t x, int32_t y, uint16_t transparent);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.createSprite(320, 240);
img.fillSprite(RED);
img.fillCircle(100,100,20,GREEN);
img.pushSprite(0, 0, GREEN);
}
void loop() {}
Syntax:
int16_t width(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.createSprite(320, 240);
img.fillSprite(RED);
img.pushSprite(0, 0, WHITE);
M5.Lcd.print(img.width());
}
void loop() {}
Syntax:
int16_t height(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.createSprite(320, 240);
img.fillSprite(RED);
img.pushSprite(0, 0, WHITE);
M5.Lcd.print(img.height());
}
void loop() {}
Syntax:
void deleteSprite(void);
Description:
Parameters:
Return:
Example:
#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Power.begin();
img.deleteSprite();
}
void loop() {}