Limitations of MicroPython with ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Peter
Posts: 2
Joined: Tue Dec 04, 2018 7:33 pm

Limitations of MicroPython with ESP32

Post by Peter » Wed May 29, 2019 8:28 pm

I'm about to launch into a "larger" project using MicroPython on ESP32/WROVER with 4MB PSRAM and 4MB Flash. Can anyone offer ideas/help as to what limitations I will encounter in terms of realistic code size? Also; I read the having the RAM available is very important ... my intuition tells me that is true?

EDIT 1 :
Thanks very much for the useful comments. The project uses an ESP32 as a controller for a radio that addresses a few hundred register settings and I'm implementing the communications stack in Python .. usually this is done in c, c++ etc. but its time for something new, hopefully easier in the end. we'll see. I tried the concept using MicroPython as a LoRa controller on a Heltec board and it seems both feasible and fairly painless albeit there is not much protocol stacking going on with LoRa unlike some other IEEE standards based radios.
Last edited by Peter on Thu May 30, 2019 5:33 pm, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Limitations of MicroPython with ESP32

Post by Roberthh » Thu May 30, 2019 7:58 am

The questions is, what do you call realistic. The WRoVER module has 4 MB PSRAM and 4 MB flash. That is available for code and data. The size of memory needed for code depends on how you compile and store the code. In the most simple way, the code will be compiled on the board. For that stage, I use as Rule-of-Thumb an estimation of 100 bye per source line, meaing that with 4MB PSRAM you can compile about 40000 lines of code. That will take a while. After compilation the required space is RAM is much smaller. You can do the compile on a PC and import a mpy file, which is much smaller and takes less space in RAM, just like after the on-board compilation. Even less space is used by embedding the code into flash as frozen bytecode. I have no experience with large code files, how they affect the loader map. my actual build includes 4300 lines of source code.
How much RAM is required for data of you application should be analyzed by you, which is not an easy task. Keep in mind, that some headroom must be left for the dynamic heap. If you allocate may objects with different sizes at runtime, you may get problems with heap fragmentation when trying to allocate space for a large object. See also the hints of @pythoncoder about that topic and the documentation http://docs.micropython.org/en/latest/r ... ained.html

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Large projects on ESP32 with PSRAM

Post by pythoncoder » Thu May 30, 2019 8:47 am

It would be interesting to hear from anyone with experience of large projects. Mine top out at about 4KLOC on a Pyboard 1.x (with use of frozen bytecode). This has 192KiB of RAM. Clearly an ESP32 with 4MiB of RAM could support much larger projects. Has anyone quantified this in practice?
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Limitations of MicroPython with ESP32

Post by kevinkk525 » Thu May 30, 2019 9:23 am

My project doesn't get bigger than 4KLOC (as .mpy) either, even when using a lot of sensors. Working fine on an ESP32 without PSRAM.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply