M5Stack Core2

at first glance

The product description of M5Stack’s new Core2 suggested correction of all hardware flaws of the Fire (see this earlier post), so I decided to give it a try and get me one, also because the Core2 has a capacitive touch screen.

The device arrived nicely packed and, like all M5Stack products, looks quite nice and well built. The included usb-C cable, although a bit short, enables you to get started right away.

 

The Core2 comes preloaded with a Factory-test application, showing some of its features. A first impression already revealed the following improvements compared to the Fire:

  • Separate (properly working) buttons for On/Off and Reset
  • No more unwanted noises from the speaker
  • Useless Grove port (exposing hard-wired PSRAM pins 16 & 17) has been dropped

And the most notable new features:

  • Capacitive touch screen (works great)
  • Real Time Clock (RTC)
  • Vibration motor
  • AXP192 Power Management Chip
  • I2S amplifier

There’s one design choice that I don’t understand. The broken out GPIO pins of the so called M Bus are hidden behind what looks like a simple plastic cover, but in fact this cover holds a circuit board that contains the microphone and the IMU sensor. Removing the cover can easily damage the circuit or its components, so I decided to leave it in place. That still gives access to the external I2C bus (pins 32 & 33) via the red Grove Port A (standard I2C pins 21 & 22 are internally used by the touch screen, the RTC, the IMU sensor and the power management chip).

In order to program the Core2 from the Arduino IDE, you have to:

Add the board via the Boards Manager. Make sure to add the following link to the ‘Additional Boards Manager URLs’ field (File->Preferences->Settings):

https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

The board will then appear in the boards list as M5Stack-Core2.

Install the M5Core2 library. At the time of writing, I recommend to install it by importing a zip file from https://github.com/m5stack/M5Core2. Installing it via Arduino IDE’s Library Manager will give you an older version with the same version number! (version 0.0.1). The older version has a very basic Touch library, whereas the Github version supports multiple touch, drag, swipe etc. and uses an easier and more powerful API. Moreover, the newer touch.h file opens with an extended comment section that explains its usage in great detail. Very well done!

You may also have to install a driver for the CP2104 USB to serial chip, if your PC doesn’t already have it. It can be found here.


Although I’m still starting to explore the Core2 myself, here are some tips that may be useful for other starters.

Setting the RTC

The preloaded Factory-test application shows a button for setting the Real Time Clock, but that function is not implemented. I found a very well written sketch on Github that not only lets you sync the RTC with an NTP server, but also demonstrates basic touch functions (using the older touch library) in very readable code. It can be found here.

Use all features of the touch screen

As mentioned earlier, the comment section in touch.h of the newer library version (on Github) explains everything very clearly and even gives some examples. Note that the touch screen is larger than the LCD display: 320×280 pixels, so it can be used for emulating the three buttons on earlier models (note the red circles)

Control the green LED and the vibration motor

Both the green power LED and the vibration motor are controlled directly by the AXP192 Power Management chip. This small sketch continuously switches them on an off.

(the internal speaker can be enabled/disabled by similar commands, e.g. M5.Axp.SetSpkEnable (true); )

Using the TFT display

Under the hood, M5Stack uses Bodmer’s TFT_eSPI library. Once you have included <M5Core2.h>, the display object can be referred to as M5.Lcd. All TFT_eSPI methods will work fine on this object. Sprites can also be associated with it:

This means that existing ESP32 sketches that include the TFT_eSPI library can easily be ported to M5Stack versions that use the M5Stack library instead. Don’t forget to initialize the display by including the following line in setup() :

(the four parameters enable the display, SD slot, UART and I2C, respectively)

Using the AXP192 Power Management chip

A look at the file AXP192.h from the M5Core2 library shows an impressive list of status values that can be retrieved from this chip. There’s also a lot of useful functions, most of them with descriptive names. The ScreenBreath() function is supposed to set the display’s brightness, but it doesn’t work in my sketches…