Farewell Loboris, Hello LittlevGL

A project log for Street Sense

Portable electronic device to measure air and noise pollution

Mike TeachmanMike Teachman 10/26/2019 at 02:305 Comments

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.

The result:

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.


Mike Teachman wrote 02/14/2020 at 00:13 point

Hi Ryan,

I used the C driver for the display, not the python version.  A couple of weeks ago I updated my littlevGL fork.  I added a new argument to the display initializer that controls SPI bus initialization.  There is likely a better way to do this.  For example, in the Loboris port, the ILI9341 driver can share the SPI device with other devices - it doesn't need any argument in the initializer call.  Here is the commit:

  Are you sure? yes | no

Ryan Fobel wrote 02/14/2020 at 22:36 point

Cool, thanks for the link! I managed to implement your workaround with the C driver and also submitted a related issue here:

  Are you sure? yes | no

Ryan Fobel wrote 02/12/2020 at 22:13 point

Hi Mike, thanks for your post! I'm a big fan of the ESP32, micropython and LittlevGL, and have also been trying to combine them in a new project using an m5stack module ( I've run up against a similar issue to the one you described (i.e., a conflict between the ILI9341 display and SDCard sharing a common SPI bus). The comments in your code mention a workaround that involves removing the SPI bus init from LittlevGL, but I can't find the specific changes anywhere. I assume that it involves modifying this file?

  Are you sure? yes | no

Mike Teachman wrote 12/26/2019 at 20:57 point

Good idea.  I'll post a topic on this project.  Thanks again for all your hard work and effort to figure out a mapping to MicroPython. 

  Are you sure? yes | no

Amir Gonnen wrote 11/05/2019 at 11:49 point

Thank you for your post! Very interesting project!

If you want, LittlevGL forum has a "My Projects" category where you can share LittlevGL based projects.
It would be great if you could write something there about Street Sense!

Also, if you need any help related to LittlevGL, the forum is a great place to ask.

  Are you sure? yes | no