Wish M5Stack - ESP32 Support


Licensed User
Longtime User
Hello every Body,

is there someone how likes to write a Library or Wrapper for the M5Stack Board?

Official Site:

GitHub Project with Arduino Library and some cool examples:

There are 3 Boards called "Cores":
- ESP32 Basic Core IoT Development Kit
- ESP32 GREY Development Kit with 9Axis Sensor
- M5Stack FIRE IoT Development Kit (PSRAM 2.0)
There are many "Modules" and "Units" available.

The general use in B4r is possible.
It works to compile and run basic code but the Board has a SPI ILI9341 TFT and Hardware Buttons.
They didn´t work.

I changed the SPI Pins in the "Adafruit_ILI9341.cpp" library like this:
// Constructor when using hardware SPI.  Faster, but must use SPI pins
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
 // _cs   = cs;
 // _dc   = dc;
 // _rst  = rst;
 // hwSPI = true;
 // _mosi  = _sclk = 0;
  _cs   = 15;
  _dc   = 2;
  _mosi  = 13;
  _miso = 12;
  _sclk = 14;
  _rst  = -1;
  hwSPI = false;

Look here in Post #7: https://www.b4x.com/android/forum/t...dafruit_ili9341-touch-sensitive-screen.75276/
But have no succsess.

I have purchased the Grey Board with Keyboard Faces:

The Arduino examples are running very good but i failed to use the Arduion Librarys in B4r to use the TFT.

Please Help:)

THX @all

PS. sorry for my bad English
  • Like
Reactions: gma


Licensed User
Longtime User
Hello every Body

Sorry that`s embarrassing, after i make an B4r update from v2.51 to 3.00 now i´m able to use the TFT without problems.

Here the Code:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public const APP_Version As String = "v1.0"                                    'Version
    Public Serial1 As Serial                                                    'Debug
    Private WiFiConnect As ESP8266WiFi                                            'WiFi
    Public Debug As Boolean = True                                                'Show Debug Messages
End Sub

Private Sub AppStart
    Delay(1500)                                                                    'short delay to show debug Messages
    If Debug Then Log("( Info  ) AppStart")
    If Debug Then Log("( Info  ) APP_Version: ", APP_Version)
    If Debug Then Log("( Info  ) Show Debug Messages: ", getBoolean(Debug))
    WiFiConnect.Connect2("[YOUR ACCESS POINT]", "[AP PASSWORD]")
    'C Code
    RunNative("setup", Null)
    RunNative("fill", Null)
    RunNative("text", Null)
    RunNative("number", Null)
    RunNative("hex", Null)
    RunNative("bigtxt", Null)
    RunNative("font2", Null)
    RunNative("formatting", Null)
End Sub

#Region "Helpers"
    Private Sub getBoolean (bol As Boolean) As String                            'Convert Boolen to String
        If bol = True Then
            Return "True"
            Return "False"
        End If
    End Sub
#End Region

#if C
#include <M5Stack.h>

#define TFT_GREY 0x5AEB // New colour

void setup(B4R::Object* unused) {
  // M5.Lcd.setRotation(2);
void fill(B4R::Object* unused) {
  // Fill screen with grey so we can see the effect of printing with and without
  // a background colour defined
void text(B4R::Object* unused) {
  // Set "cursor" at top left corner of display (0,0) and select font 2
  // (cursor will move to next line automatically during printing with 'M5.Lcd.println'
  //  or stay on the line is there is room for the text with M5.Lcd.print)
  M5.Lcd.setCursor(0, 0, 2);
  // Set the font colour to be white with a black background, set text size multiplier to 1
  // We can now plot text on screen using the "print" class
  M5.Lcd.println("Hello World!");
void number(B4R::Object* unused) {
  // Set the font colour to be yellow with no background, set to font 7
  M5.Lcd.setTextColor(TFT_YELLOW); M5.Lcd.setTextFont(7);
void hex(B4R::Object* unused) {
  // Set the font colour to be red with black background, set to font 4
  M5.Lcd.setTextColor(TFT_RED,TFT_BLACK);    M5.Lcd.setTextFont(4);
  //M5.Lcd.println(3735928559L, HEX); // Should print DEADBEEF

void bigtxt(B4R::Object* unused) {
  // Set the font colour to be green with black background, set to font 4
  M5.Lcd.println("I implore thee,");

void font2(B4R::Object* unused) {
  // Change to font 2
  M5.Lcd.println("my foonting turlingdromes.");
  M5.Lcd.println("And hooptiously drangle me");
  M5.Lcd.println("with crinkly bindlewurdles,");
  // This next line is deliberately made too long for the display width to test
  // automatic text wrapping onto the next line
  M5.Lcd.println("Or I will rend thee in the gobberwarts with my blurglecruncheon, see if I don't!");
void formatting(B4R::Object* unused) {
  // Test some print formatting functions
  float fnumber = 123.45;
   // Set the font colour to be blue with no background, set to font 4
  M5.Lcd.setTextColor(TFT_BLUE);    M5.Lcd.setTextFont(4);
  M5.Lcd.print("Float = "); M5.Lcd.println(fnumber);           // Print floating point number
  M5.Lcd.print("Binary = "); M5.Lcd.println((int)fnumber, BIN); // Print as integer value in binary
  M5.Lcd.print("Hexadecimal = "); M5.Lcd.println((int)fnumber, HEX); // Print as integer number in Hexadecimal
//  delay(10000);
#End If

Before I did the update, I had a lot of library errors, so I relinked the dependent libraries in the include statements.
That was the problem.
Now after the update, it compiles without Errors.

I hope it helps.

THX @all

PS. If anyone is interested I would be happy about a library or a wrapper anyway.


Active Member
Licensed User
Longtime User
This is a very intriguing product range and I have just placed an order. I hope it's something that B4R can handle. :)


Licensed User
Longtime User
You can use the code above to program the M5 to test the Display and you can use inline c but there is no B4r library at this time.:)


Licensed User
Longtime User
Hi, just found this M5Stack lineup, I'm interested in libs too! :)