When I started this project the most capable version of MicroPython on the ESP32 device was found in the Loboris port. It was an easy decision to build the Street Sense project on top of this version.
A year later the situation has changed. The Loboris port has remained stagnant for over a year. On the other hand the mainline of MicroPython has advanced significantly and now provides the ESP32 feature set that is needed for this project. I decided to move back to the mainline.
But, one key feature is still missing from the mainline version: good support for a graphical display like the ILI9341 which is used in this project. Loboris built outstanding graphic support in his port. I considered porting his work, but it is a very unique implementation and involves some re-write of the ESP-IDF SPI drivers. Not a good choice for porting.
In February 2019 a Hackaday post announced that the LittlevGLgraphics library had been ported to MicroPython. I had never heard of LittlevGL before then. I made note of the blog post and revisited it in September 2019 when I started hunting for a replacement graphics library. LittlevGL has more than enough graphics support for my needs so I decided to attempt an integration with my project.
The integration of LittlevGL into MicroPython is quite well described. Big thank you to the developer Amir Gonnen who figured out how to bind LittlevGL objects into MicroPython. Quite amazing and innovative work. I'm humbled by these great programmers who are able to realize these advances in design. Here's one thing I can say about GUI design in MicroPython: It rocks. You can iterate so quickly. I'll guess 5x faster with LittlevGL-MicroPython than compiled C.
Most of the integration work involved modification of the MicroPython Makefile. If you would like to make a similar integration into your MicroPython project my GitHub commit might save you some time.
It was all going smoothly until I started seeing problems with SD Card operation that would happen immediately after the LittlevGL library was initialized. In the Street Sense design, the ILI9341 display and external SD Card share the same SPI bus. Perhaps a bad idea, but I ran out of ESP32 gpio pins and had to economize. Without getting into details, this turned out to be a big problem to solve. It took about a week to figure out and even called for some oscilloscope work on more than one occasion. In the end I found a way to make it work, but don't fully understand why it works. Usually I dig deeper to understand why, but I'm so worn out by this problem I just want to move on. The solution: run the LittlegVL SPI bus in full-duplex mode. For some reason this allows the graphics library to play nice with the SD Card on the SPI bus. Again, I don't know why.
Some stats on the LittlevGL addition to MicroPython. Without any feature pruning it blew out the ROM partition of MicroPython with the ESP32 continually resetting after being flashed with the firmware. The graphics library has a configuration file that allows features to be turned on and off. With a small effort I was able to make LittlevGL fit into MicroPython.
- ROM (flash memory): about 156kB
- Time to display a 320x240 pixel image: 120ms (ESP32 running at 240MHz, SPI bus at 20MHz)
There is likely a lot more that can be removed to save flash space, but it's not really important to find these efficiencies at this point.
To wrap up this project update: Street Sense is back on the mainline of MicroPython and has great graphics support for the display using the LittlevGL library.
Lastly. A big shout out to Boris Lovosevic for leading the way on the ESP32 port of MicroPython. Your work has helped many. An outstanding developer.