pdf-icon

LCD Screen

The screen resolution is 320x240, with the origin (0,0) at the top left corner of the screen

Color code:

Definition Hex value 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

Class name: LCD

begin()

Function:

Initialize for use

Function prototype:

void begin()

Note:
1. If you do not want to use M5.begin() to initialize the LCD, please call this function before using the display

Example of use:

#include <M5Stack.h>

void setup() {
 M5.Lcd.begin(); //Initialize M5Stack
}

void loop() {
}

sleep()

Function:

Put the display into power saving mode

Function prototype:

void sleep()

Example of use:

#include <M5Stack.h>

void setup() {
 M5.Lcd.begin(); //Initialize M5Stack
 M5.Lcd.sleep();  //Switch to sleep mode
}

void loop() {
}

clear()

Function:

Clears the contents of the display

Function prototype:

void clear()

Example of use:

#include <M5Stack.h>

void setup() {
 M5.Lcd.begin(); //Initialize M5Stack
 M5.Power.begin();
 M5.Lcd.fillScreen(RED);
 delay(1000);
 M5.Lcd.clear();  //Clear the contents of the display
}

void loop() {
}

wakeup()

Function:

Resume display from power saving mode

Function prototype:

void wakeup()

Example of use:

#include <M5Stack.h>

void setup() {
 M5.Lcd.begin(); //Initialize M5Stack
 M5.Lcd.wakeup(); //Resume display from power saving mode
}

void loop() {
}

hight()

Function:

drawNumber()

Functionality:

Displays an integer at (x,y).

Function Prototype:

void drawNumber(long long_num, int32_t poX, int32_t poY)

Parameter Type Description
long_num long Number
poX int32_t X coordinate
poY int32_t Y coordinate

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawNumber(99, 55, 100);   // Display the integer 100 at (55,100)
}

void loop(){
}

drawChar()

Functionality:

Displays a character at (X,Y) using font.

Function Prototype:

int16_t drawChar(int16_t uniCode, int32_t x, uint16_t y, uint8_t font)

Parameter Type Description
uniCode int16_t Character
x int32_t X coordinate
y uint16_t Y coordinate
font uint8_t Font

Usage Example:

#include <M5Stack.h>
void setup() {
  M5.begin(); // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawChar('A', 160, 120, 2);    // Display character 'A' at (160,120) using font 2
}
void loop(){
}

drawFloat()

Functionality:

Displays a floating-point number at (X,Y) with dp decimal places.

Function Prototype:

int16_t drawFloat(float floatNumber, uint8_t dp, int32_t poX, int32_t poY)

Parameter Type Description
floatNumber float The floating number
dp uint8_t Decimal places
poX int32_t X coordinate
poY int32_t Y coordinate

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawFloat(3.1415928,7,100,100);    // Display the floating-point number 3.1415928 with 7 decimal places at (100,100)
}

void loop() {}

drawPixel()

Functionality:

Draws a pixel at (x,y).

Function Prototype:

void drawPixel(int32_t x, int32_t y, uint32_t color)

Parameters:

Parameter Description Type
x X coordinate int32_t
y Y coordinate int32_t
color Color uint32_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawPixel(22,22,RED);  // Draws a red pixel at (22,22)
}

void loop() {}

drawLine()

Functionality:

Draws a line from point (x0,y0) to point (x1,y1) in the specified color (color).

Function Prototype:

void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color)

Parameter Type Description
x* int32_t X coordinate
y* int32_t Y coordinate
color uint32_t Color

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawLine(200, 0, 200, 200, GREEN);  // Draws a green line from point (200,0) to point (200,200)
}

void loop(){
}

drawRect()

Functionality:

Draws a rectangle frame at (x,y) in the specified color, with width and height as w and h respectively.

Function Prototype:

void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
w int32_t Width of the rectangle
h int32_t Height of the rectangle
color uint32_t Color

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawRect(180, 12, 122, 10, BLUE);  // Draws a blue rectangle frame at (180,12) with width 122 and height 10
}

void loop(){
}

fillRect()

Functionality:

Draws a filled rectangle at (x,y) in the specified color, with width and height as w and h respectively.

Function Prototype:

void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
w int32_t Rectangle width (pixels)
h int32_t Rectangle height (pixels)
color uint32_t Color

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.fillRect(150, 120, 122, 10, BLUE); // Draws a blue filled rectangle at (150,120) with a width of 122 and height of 10
}

void loop(){
}

drawRoundRect()

Functionality:

Draws a rounded rectangle frame at (x,y) with width w, height h, corner radius r, and color color.

Function Prototype:

void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color)

Parameter Type Description
x int32_t X coordinate of the top-left corner
y int32_t Y coordinate of the top-left corner
w int32_t Rectangle width (pixels)
h int32_t Rectangle height (pixels)
r int32_t Corner radius
color uint32_t Color

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawRoundRect(55,55,30,50,10,GREEN);   // Draws a rounded rectangle frame at (55,55) with width 30, height 50, corner radius 10, and color green
}

void loop() {}

fillRoundRect()

Functionality:

Draws a filled rounded rectangle at (x,y) with width w, height h, corner radius r, and color color.

Function Prototype:

void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color)

Parameter Type Description
x int32_t X coordinate of the top-left corner
y int32_t Y coordinate of the top-left corner
w int32_t Rectangle width (pixels)
h int32_t Rectangle height (pixels)
r int32_t Corner radius
color uint32_t Color

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.fillRoundRect(55, 55, 30, 50, 10, GREEN); // Draws a filled rounded rectangle at (55,55) with width 30, height 50, corner radius 10, and color green
}

void loop()

drawCircle()

Functionality:

Draws a circle outline at (x,y) with radius r and in color color.

Function Prototype:

void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)

Parameters:

Parameter Description Type
x0 X coordinate of the circle's center int32_t
y0 Y coordinate of the circle's center int32_t
r Circle's radius int32_t
color Circle's color uint32_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawCircle(100, 100, 50, RED);   // Draws a red circle outline at (100,100) with a radius of 50
}

void loop() {}

fillCircle()

Functionality:

Draws a filled circle at (x,y) with radius r and in color color.

Function Prototype:

void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color)

Parameters:

Parameter Description Type
x0 X coordinate of the circle's center int32_t
y0 Y coordinate of the circle's center int32_t
r Circle's radius int32_t
color Circle's color uint32_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.fillCircle(100, 100, 50, RED); // Draws a filled red circle at (100,100) with a radius of 50
}

void loop() {}

drawEllipse()

Functionality:

Draws an ellipse outline at (x,y) with width rx, height ry, and in color color.

Function Prototype:

void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color)

Parameters:

Parameter Description Type
x0 X coordinate of the ellipse's center int16_t
y0 Y coordinate of the ellipse's center int16_t
rx Ellipse's width (pixels) int32_t
ry Ellipse's height (pixels) int32_t
color Ellipse's color uint16_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawEllipse(160, 100, 60, 100, YELLOW); // Draws a yellow ellipse outline at (160,100) with width 60 and height 100
}

void loop() {}

fillEllipse()

Functionality:

Draws a filled ellipse at (x,y) with width rx, height ry, and in color color.

Function Prototype:

void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color)

Parameters:

Parameter Description Type
x0 X coordinate of the ellipse's center int16_t
y0 Y coordinate of the ellipse's center int16_t
rx Ellipse's width (pixels) int32_t
ry Ellipse's height (pixels) int32_t
color Ellipse's color uint16_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.fillEllipse(160, 100, 60, 100, YELLOW);    // Draws a filled yellow ellipse at (160,100) with width 60 and height 100
}

void loop() {}

drawTriangle()

Functionality:

Draws a triangle outline with vertices at (x1, y1), (x2, y2), (x3, y3).

Function Prototype:

void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color)

Parameters:

Parameter Description Type
x* X coordinate of vertex * int32_t
y* Y coordinate of vertex * int32_t
color Triangle's color uint32_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Draws a yellow triangle outline with vertices at (30,30), (180,100), and (80,150)
}

void loop() {}

fillTriangle()

Functionality:

Draws a filled triangle with vertices at (x1, y1), (x2, y2), (x3, y3).

Function Prototype:

void fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color)

Parameters:

Parameter Description Type
x* X coordinate of vertex * int32_t
y* Y coordinate of vertex * int32_t
color Triangle's color uint32_t

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Draws a filled yellow triangle with vertices at (30,30), (180,100), and (80,150)
}

void loop() {}

drawXBitmap()

Functionality:

Draws a bitmap.

Function Prototype:

void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)

Parameter Type Description
x int16_t X coordinate
y int16_t Y coordinate
bitmap const uint8_t Bitmap image
w int16_t Width (pixels)
h int16_t Height (pixels)
color uint16_t Color

Usage Example:

See the sketch example under: M5Stack -> Advanced -> Display -> drawXBitmap

drawBitmap()

Functionality:

Draws a bitmap.

Function Prototypes:

  • drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data)
  • drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t *data)
  • drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data, uint16_t transparent)
  • drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint8_t *data)
  • drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint8_t *data)
Parameter Type Description
x0 int16_t X coordinate
y0 int16_t Y coordinate
w int16_t Width (pixels)
h int16_t Height (pixels)
data uint16_t* / uint8_t* Bitmap data
transparent uint16_t Transparent color code
Note:
1. Color codes are represented by a total of 16 bits: 5 bits for red, 6 bits for green, and 5 bits for blue.

Usage Example:

See the sketch example under: M5Stack -> games -> Tetris

drawBmpFile()

Functionality:

Reads a bitmap from a file and draws it.

Function Prototype:

void drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y)

Parameter Type Description
fs fs::FS File stream
path const char * File path (SD, SPIFFS)
x int16_t X coordinate
y int16_t Y coordinate
Note:
1. May not scale according to size and bit depth
2. Requires the Arduino ESP32 filesystem uploader to be installed in advance.

Usage 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 to .c files. You can use it to convert some pictures and use the above API to draw the images on the screen. bin2code.py

drawJpg()

Functionality:

Reads JPEG format image data from memory and draws it.

Function Prototype:

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) {

Parameter Type Description
jpg_data uint8_t * Data pointer
jpg_len size_t Data length
x uint16_t X-coordinate
y uint16_t Y-coordinate
maxWidth uint16_t Maximum width (pixels)
maxHeight uint16_t Maximum height (pixels)
offX uint16_t Offset X (pixels)
offY uint16_t Offset Y (pixels)
scale jpeg_div_t Scale

Scale (jpeg_div_t):

Definition Function
JPEG_DIV_NONE No care.
JPEG_DIV_2 1/2 scale
JPEG_DIV_4 1/4 scale
JPEG_DIV_8 1/8 scale
JPEG_DIV_MAX MAX scale
Note:
1. May not scale depending on size, bit depth, and format (progressive, etc.)
2. tetris_img download

Usage Example:

#include <M5Stack.h>
extern uint8_t tetris_img[];    // Reference the array storing the image, needs to be in the same folder as xxx.ino beforehand

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.drawJpg(tetris_img, 34215);    // Read the jpeg file named tetris_img from memory
}
void loop(){
}

drawJpgFile()

Functionality:

Reads JPEG data from a file stream and draws it.

Function Prototype:

void drawJpgFile(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)

Parameter Type Description
fs fs::FS File stream
path const char * File path
x uint16_t X-coordinate
y uint16_t Y-coordinate
maxWidth uint16_t Max Width (pixels)
maxHeight uint16_t Max Height (pixels)
offX uint16_t Offset X (pixels)
offY uint16_t Offset Y (pixels)
scale jpeg_div_t Scale

Scale (jpeg_div_t):

Definition Function
JPEG_DIV_NONE No care.
JPEG_DIV_2 1/2 scale
JPEG_DIV_4 1/4 scale
JPEG_DIV_8 1/8 scale
JPEG_DIV_MAX MAX scale
Note:
1. May not scale depending on size and format (progressive, etc.)

progressBar()

Functionality:

Displays a progress bar.

Function Prototype:

void progressBar(int x, int y, int w, int h, uint8_t val)

Parameter Type Description
x int X-coordinate
y int Y-coordinate
w int Width (pixels)
h int Height (pixels)
val uint8_t Progress (0-100%)
Note:
1. The progress bar will be displayed in blue.

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.progressBar(0, 0, 240, 20, 20);    // Display a progress bar at (0,0) with a width of 240, height of 20, and 20% progress
}

void loop() {
}

qrcode()

Functionality:

Generates a QR code.

Function Prototype:

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)

Parameter Type Description
string char * / String& String to embed in QR
x uint16_t X-coordinate
y uint16_t Y-coordinate
width uint8_t Width (pixels)
version uint8_t QR code version
Note:
1. Please choose the appropriate QR code version according to the number of characters.

Usage Example:

#include <M5Stack.h>

void setup() {
  M5.Lcd.begin();   // Initialize M5Stack
  M5.Power.begin();
  M5.Lcd.qrcode("http://www.m5stack.com", 50, 10, 220, 6);
}

void loop() {
}

Sprite

setColorDepth()

Functionality:

Sets the color depth.

Function Prototype:

void* TFT_eSprite::setColorDepth(int8_t b)

Usage Example:

#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
    M5.begin();          // Init M5Stack. Initialize M5Stack
    M5.Power.begin();    // Init power. Initialize power module
    img.setColorDepth(8); // Set color depth. Set the color depth
    img.setTextSize(2);
    img.createSprite(320, 240);  //Create a 320x240 canvas. Create a canvas of 320x240
}

void loop() {}

Note: The corresponding color depth should be set before creating a canvas.

createSprite()

Functionality:

Creates a canvas of specified width and height.

Function Prototype:

void createSprite(int16_t w, int16_t h, uint8_t frames)

Parameter Type Description
x int16_t X coordinate
y int16_t Y coordinate
frames uint8_t Color depth [1~2, optional]

Usage Example:

#include <M5Stack.h>

TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
    M5.begin();  // Initialize M5Stack
    M5.Power.begin();
    img.setColorDepth(8);  // Set the color depth to 8 bits. Set color depth to 8 bits
    img.createSprite(320, 240);  //Create a 320x240 canvas. Create a canvas of 320x240
    img.fillSprite(RED);         //Fill the canvas with red. Fill the canvas with red
    img.pushSprite(0,0);  // Push the canvas to the screen at (0,0). Push the canvas to the screen at (0,0)
}

void loop() {}

fillSprite()

Functionality:

Fills the Sprite with a specified color.

Function Prototype:

void fillSprite(uint32_t color)

Parameter Type Description
color int32_t filled color

Usage Example:

#include <M5Stack.h>

TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
    M5.begin();  // Initialize M5Stack
    M5.Power.begin();
    img.setColorDepth(8);  // Set the color depth to 8 bits. Set color depth to 8 bits
    img.createSprite(320, 240);  //Create a 320x240 canvas. Create a canvas of 320x240
    img.fillSprite(RED);         //Fill the canvas with red. Fill the entire canvas with red
    img.pushSprite(0,0);  // Push the canvas to the screen at (0,0). Push the canvas to the screen at (0,0)
}

void loop() {}
}

pushSprite()

Functionality:

Pushes the canvas to a specified coordinate, setting a transparent color.

Function Prototype:

void pushSprite(int32_t x, int32_t y, uint16_t transparent)

Parameter Type Description
x int32_t X coordinate
y int32_t Y coordinate
transparent int16_t Transparent color (optional)

Usage Example:

#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  img.createSprite(320, 240);   // Create a 320x240 canvas
  img.fillSprite(RED);  // Fill the entire canvas with red
  img.fillCircle(100, 100, 20, GREEN);
  img.pushSprite(0, 0, GREEN);  // Push the canvas to the screen at (0,0) and set green as the transparent color
}

void loop() {}

height()

Functionality:

Returns the height of the Sprite.

Usage Example:

#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  img.createSprite(320, 240);   // Create a 320x240 canvas
  img.fillSprite(RED);  // Fill the entire canvas with red
  img.pushSprite(0, 0, WHITE);  // Push the canvas to the screen at (0,0) and set white as the transparent color
  M5.Lcd.print(img.height());   // Print the height of the canvas on the screen
}

void loop() {}

deleteSprite()

Functionality:

Deletes the canvas from memory.

Usage Example:

#include <M5Stack.h>
TFT_eSprite img = TFT_eSprite(&M5.Lcd);

void setup() {
  M5.begin();  // Initialize M5Stack
  M5.Power.begin();
  img.deleteSprite();   // Delete the canvas from memory
}

void loop() {}
Note:
LCD and img both inherit from this file In_eSPI.h , and their usage is similar.
On This Page