M5GFX is a library for operating display devices on M5Stack products. Users can call APIs in this library to achieve various display effects and touch effects.
Each device requires different header files. M5Stack devices mainly use the header file M5GFX.h
; other devices such as Unit LCD require the header file M5UnitLCD.h
, and similarly for Unit OLED and Atom Display.
Supported devices:
M5Stack Core Controllers, such as M5Fire, M5Core2, M5Tough, M5StickC, M5Paper, M5Tab, etc.
Constructor prototype:
M5GFX(void)
Description:
Sample program:
#include <M5GFX.h>
M5GFX display;
void setup() {
display.begin();
uint16_t x = display.width() / 2;
uint16_t y = display.height() / 2;
display.drawCenterString("M5Stack", x, y);
}
void loop() {
}
Supported devices:
M5Stack Unit LCD
Constructor prototype:
M5UnitLCD( uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ,
int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E )
Description:
Parameters:
i2c_port
and i2c_addr
will be automatically configured as PORT.A and 0x3E even if not specified.Function prototype:
void init( uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITLCD_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E )
Description:
Parameters:
Function prototype:
setup(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ,
int8_t i2c_port = -1, uint8_t i2c_addr = 0x3E)
Description:
Parameters:
Sample program:
#include <M5UnitLCD.h>
M5UnitLCD display;
void setup() {
display.init( 21, 22, 400000 );
display.setup( 21, 22, 400000 );
uint16_t x = display.width() / 2;
uint16_t y = display.height() / 2;
display.drawCenterString("M5Stack", x, y);
}
void loop() {
}
Supported devices:
M5Stack Unit OLED
Constructor prototype:
M5UnitOLED( uint8_t pin_sda = M5UNITOLED_SDA, uint8_t pin_scl = M5UNITOLED_SCL, uint32_t i2c_freq = M5UNITOLED_FREQ,
int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C)
Description:
Parameters:
i2c_port
and i2c_addr
will be automatically configured as PORT.A and 0x3C even if not specified.Function prototype:
void init( uint8_t pin_sda, uint8_t pin_scl, uint32_t i2c_freq = M5UNITOLED_FREQ, int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C )
Description:
Parameters:
Function prototype:
setup(uint8_t pin_sda = M5UNITLCD_SDA, uint8_t pin_scl = M5UNITLCD_SCL, uint32_t i2c_freq = M5UNITLCD_FREQ,
int8_t i2c_port = -1, uint8_t i2c_addr = 0x3C)
Description:
Parameters:
Sample program:
#include <M5UnitOLED.h>
M5UnitOLED display;
void setup() {
display.init( 21, 22, 400000 );
display.setup( 21, 22, 400000 );
uint16_t x = display.width() / 2;
uint16_t y = display.height() / 2;
display.drawCenterString("M5Stack", x, y);
}
void loop() {
}
Supported devices:
M5Stack Atom Display, AtomDisplayLite
Constructor prototype:
M5AtomDisplay( unit16_t logical_width = 1280, uint16_t logical_height = 720, float refresh_rate = 0.0f, uint16_t output_width = 0, uint16_t output_height = 0,
uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0, uint32_t pixel_clock = 74250000)
Description:
Parameters:
Function prototype:
bool setResolution(uint16_t logical_width = 0, uint16_t logical_height = 0, float refresh_rate = 0.0f, uint16_t output_width = 0, uint16_t output_height = 0,
uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0, uint32_t pixel_clock = 74250000)
Description:
Parameters:
Sample program:
#include <M5AtomDisplay.h>
M5AtomDisplay display( 640, 480, 60 );
void setup() {
display.setResolution( 320, 240, 60 );
uint16_t x = display.width() / 2;
uint16_t y = display.height() / 2;
display.drawCenterString("M5Stack", x, y);
}
void loop() {
}
Some APIs in M5GFX must include other corresponding header files in addition to M5GFX.h (or M5UnitLCD.h, M5UnitOLED.h, M5AtomDisplay.h), otherwise they cannot be called successfully.
The relevant APIs and header files are as follows:
API | Required header file |
---|---|
drawBmpFile | SD.h or SPIFFS.h |
drawJpgFile | SD.h or SPIFFS.h |
drawPngFile | SD.h or SPIFFS.h |
drawQoiFile | SD.h or SPIFFS.h |
drawBmpUrl | HTTPClient.h |
drawJpgUrl | HTTPClient.h |
drawPngUrl | HTTPClient.h |
drawQoiUrl | HTTPClient.h |
SD.h
or SPIFFS.h
depending on whether the image data is stored on an external memory card or in the main controller's memory.