m5_hello.py
The official M5Stack MicroPython firmware exposes lcd/text/rect in three calls: a button counter with zero compilation. Scripting mode meets the case's 320×240 screen.
Hardware required
An M5Stack Core Basic/Gray (ESP32 in an enclosure with a 320×240 TFT, A/B/C buttons, speaker, microSD slot, 110 mAh battery). None (the « M5Stack » MicroPython firmware flashed on the board).
Wiring
No wiring. Flash the firmware via M5Launcher or esptool, then copy main.py by drag-and-drop (disk mode).
How it works
The m5 module wraps the ILI9341 (RGB565 colors) and buttons as a bitmap read; rtc.tick gives milliseconds. The 50 ms loop debounces with a time guard. In the Arduino IDE (esp32 package), board « M5Stack-Core-ESP32 »; install the « M5Stack » (or M5Unified) library from the Library Manager, then Upload.
Going further
Draw a live graph of the mic (uarray module + RMS), or drive the Grove I2C from the REPL console.
m5_hello.py
# MicroPython M5Stack (firmware « M5Stack ») : ecran + boutons sans IDE.
# Flasher le binaire M5Stack sur la carte, copier ce fichier en main.py.
from m5 import lcd, led, rtc
import time, m5
lcd.color(0, 0, 0)
lcd.text(20, 20, "M5Stack MicroPython", 0xFFFF, 4) # RGB565, taille 4
compteur = 0
dernier = 0
while True:
boutons = m5.buttons() # (A, B, C) -> bits
if boutons & 0x1 and time.ticks_ms() - dernier > 300:
compteur += 1
dernier = time.ticks_ms()
lcd.rect(20, 90, 280, 50, 0xF800)
lcd.text(30, 100, "Appuis : %d" % compteur, 0x07E0, 4)
if boutons & 0x4: # bouton C : efface
lcd.rect(20, 90, 280, 50, 0)
compteur = 0
lcd.text(20, 180, "uptime %d s" % rtc.tick() // 1000, 0x001F, 2)
time.sleep_ms(50)