Specific Hardware

M5Stack devices

On M5Stack devices, LovyanGFX may at some point become the packaged display driver. Until then, there are two ways of using LovyanGFX if you want to play with its more powerful features already. To show how they are different, let’s show how to make a red circle using the regular TFT_eSPI version that comes with the present M5Stack software.

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Lcd.fillCircle(160, 120, 100, TFT_RED);
}

void loop() {
}

Note

In these examples we assume an M5Stack Core2 device. These examples also apply to the original three-button M5Stack device and the M5StickC device. In that case, simply replace M5Core2.h by M5Stack.h or M5StickC.h respectively.

Option 1: coexist

Now the first way to use LovyanGFX is to include it after the M5Stack core. That means there are two display drivers, but we only use LovyanGFX. The red circle example from above would become:

#include <M5Core2.h>
#include <LovyanGFX.hpp>

static LGFX lcd;

void setup() {
  M5.begin(false);
  lcd.init();
  lcd.fillCircle(160, 120, 100, TFT_RED);
}

void loop() {
}

As you can see we still call M5.begin(), but we supply a false argument. This causes the M5Stack software to not initialise the display driver. We then initialise the lcd device we defined as an instance of LGFX before. This device can then be used as if it were M5.lcd. You cannot use both at the same time.

As you can see the LovyanGFX driver auto-detects what device it is in. You can manually set it for boards where auto-detection is not (yet) supported, see the bigger example below.

Option 2: ESP32-Chimera-Core

Or you can use the ESP32-Chimera-Core, which replaces M5Stack.h completely. In that case you can use M5.Lcd, it uses LovyanGFX as the driver. Just like LovyanGFX, ESP32-Chimera-Core is made to auto-detect which device it is running on. So the red circle example would become:

#include <ESP32-Chimera-Core.h>

void setup() {
  M5.begin();
  M5.Lcd.fillCircle(160, 120, 100, TFT_RED);
}

void loop() {
}