M5GFX

M5GFX is a library for operating display devices for M5Stack products.

Include Header file and display definition

Include files differ for each device. The main device for M5Stack is M5GFX.h.

List of APIs dependent on header files

Some of the M5GFX APIs will not s out unless a header file exists. If you need the following APIs, please include the header file before M5GFX.h(or M5UnitLCD.h, M5UnitOLED.h, M5AtomDisplay.h).

API Required Header File
drawBmpFile SD.h
drawJpgFile SD.h
drawPngFile SD.h
drawQoiFile SD.h
drawBmpUrl HTTPClient.h
drawJpgUrl HTTPClient.h
drawPngUrl HTTPClient.h
drawQoiUrl HTTPClient.h
drawBmpFile SdFat.h
drawJpgFile SdFat.h
drawPngFile SdFat.h
drawQoiFile SdFat.h

M5GFX.h

Device: for M5Stack Core(Basic, Gray, Fire, M5Go), M5StackCore2, M5Tough, M5StickC, M5StickCPlus, M5CoreInk, M5Paper

Constructor:

M5GFX( void )

Example:

#include <M5GFX.h>
M5GFX display;

M5UnitLCD.h

Device: for M5Stack UnitLCD

Constructor Syntax:

M5UnitLCD( uint8_t pin_sda = Auto, uint8_t pin_scl = Auto, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E )

Constructor Parameters:

Parameter Type Description
pin_sda uint8_t SCA PIN number of M5 device (*1)
pin_scl uint8_t SCL PIN number of M5 device (*1)
i2c_freq uint32_t I2C frequency
i2c_port int8_t I2C Port(Usually unused)
i2c_address uint8_t I2C Address(Usually unused)

*1. Port.A and Grove ports(M5StickC/Plus/Atom) are automatically set even if omitted.

Example:


#include <M5UnitLCD.h>
M5UnitLCD display( 21, 22, 400000 ); // SDA, SCL, FREQ

Function

init()

Function:

Dynamically change the initial settings.

Syntax:

void init( uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E )

Example:

#include <M5UnitLCD.h>
M5UnitLCD display;

void setup() {
  display.init( 21, 22, 400000 );    // SCL, SDA, I2C_Freq
}

void loop() {
}

setup()

Function:

Dynamically change the initial settings.

Syntax:

void setup( uint8_t pin_sda = Auto, uint8_t pin_scl = Auto, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E )

Example:

#include <M5UnitLCD.h>
M5UnitLCD display;

void setup() {
  display.setup( 21, 22, 400000 );    // SCL, SDA, I2C_Freq
}

void loop() {
}

M5UnitOLED.h

Constructor

Device: for M5Stack UnitOLED

Constructor Syntax:

M5UnitOLED( uint8_t pin_sda = Auto, uint8_t pin_scl = Auto, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C )

Constructor Parameters:

Parameter Type Description
pin_sda uint8_t SCA PIN number of M5 device (*1)
pin_scl uint8_t SCL PIN number of M5 device (*1)
i2c_freq uint32_t I2C frequency
i2c_port int8_t I2C Port(Usually unused)
i2c_address uint8_t I2C Address(Usually unused)

*1. Port.A and Grove ports(M5StickC/Plus/Atom) are automatically set even if omitted.

Example:


#include <M5UnitLCD.h>
M5UnitLCD display( 21, 22, 400000 ); // SDA, SCL, FREQ

Function

init()

Function:

Dynamically change the initial settings.

Syntax:

void init( uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C )

Example:

#include <M5UnitOLED.h>
M5UnitOLED display;

void setup() {
  display.init( 21, 22, 400000 );    // SCL, SDA, I2C_Freq
}

void loop() {
}

setup()

Function:

Dynamically change the initial settings.

Syntax:

void setup( uint8_t pin_sda = Auto, uint8_t pin_scl = Auto, uint32_t i2c_freq = 400000, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C )

Example:

#include <M5UnitOLED.h>
M5UnitOLED display;

void setup() {
  display.setup( 21, 22, 400000 );    // SCL, SDA, I2C_Freq
}

void loop() {
}

M5AtomDisplay.h

Constructor

Device: for M5Stack AtomDisplay / AtomDisplayLite

Constructor Syntax:

M5AtomDisplay( unit16_t logical_width = 1280, uint16_t logical_height = 720, float refresh_rate = 0.0f, output_width = 0, uint16_t output_height = 0, uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0)

Constructor Parameters:

Parameter Type Description(*1)
logical_width uint16_t Logical screen widths handled by the program
logical_height uint16_t Logical screen heights handled by the program
refresh_rate float Screen Refresh Rate(*2)
output_width uint16_t Actual output screen width
output_height uint16_t Actual output screen height
scale_w uint_fast8_t Magnification of logical_width
scale_h uint_fast8_t Magnification of logical_height

*1. Maximum resolution depends on available memory. *2. The refresh rate you can specify depends on the monitor you are using.

example resolution ・1280 x 720 x 60Hz ・1920 x 1080 x 24Hz ・320 x 240 x 240Hz

Example:


#include <M5AtomDisplay.h>
M5AtomDisplay display( 640, 480, 60 );

Function

setResolution()

Function:

Dynamically change the initial settings.

Syntax:

void setResolution( unit16_t logical_width = 1280, uint16_t logical_height = 720, float refresh_rate = 0.0f, output_width = 0, uint16_t output_height = 0, uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0 )

Example:

#include <M5AtomDisplay.h>
M5AtomDisplay display;

void setup() {
  display.setResolution( 320, 240, 60 );    // logical_width, logical_height, refresh_rate
}

void loop() {
}
On This Page