Porting to M5Stack¶
Published on 2018-03-11 in Stage, a Tile and Sprite Engine.
One of the nicer MicroPython-capable boards with integrated color display out there is the M5Stack. It’s a bit pricey, but you get a really nice enclosure, and if you get the “faces” thing, even several keyboards. So I decided to try porting the Stage library to it first. After a day of work, mostly spent writing the driver for the ILI9341 display, I ended up with something like this:
The small square area is the 128×128 pixels for which the library was originally written. Of course with a bigger screen you can make games that use a larger area. But the rendering doesn’t look quite right. After half a day of debugging, I considerably simplified the driver, but I didn’t solve the issue until I tried to reduce the speed of the SPI clock down to 40MHz. I have forgotten that ESP32 has really fast SPI, which apparently this display can’t handle reliably. With that, I have proper rendering:
Now, the buttons. The keyboard attachments all use an ATmega328p chip working as an I2C slave on address 0x08 and reporting the pressed keys as a simple bit mask — pretty much like D1 Mini X-Pad Shield or project-26823 . That’s a problem, because I have to poll the bus, and if I do it only once a frame, I might lose keypresses. For now I used the naive code that just returns the current state of the buttons. I will need to see if I can use a timer to have a proper button handling, with a buffer and all that.
I also didn’t explore the sound yet. The ESP32 has a DAC, and the M5Stack has an amplifier and a speaker — you can tell, because you can hear every single GPIO toggle in that thing. But there is no ready-to- use functionality in MicroPython to simply play WAV files in the background, like there is in CircuitPython, so I might need to do some work there.