MemoryError what limit am I hitting?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
stephenmhall
Posts: 4
Joined: Sun Sep 25, 2016 3:33 pm

Re: MemoryError what limit am I hitting?

Post by stephenmhall » Thu Sep 29, 2016 8:19 pm

Thanks to all, managed to get my head round building and freezing thanks to posts here and adafruit tutorials. I now have an Ubuntu VM set up for building my own frozen module MicroPython firmwares.

Works a charm, gone from about 6k free ram when it did run to about 17k :D

AidanJCav
Posts: 1
Joined: Fri Apr 24, 2020 5:04 pm

Re: MemoryError what limit am I hitting?

Post by AidanJCav » Fri Apr 24, 2020 5:09 pm

I don't know about micropython, but circuitpython has a relatively low line limit of around 250 lines. If (and again I have no idea if it does) micropython has the same problem, then maybe you can try getting rid of the empty lines in between code section, since they aren't necessary, just helpful when looking at the code from a human perspective.

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

Re: MemoryError what limit am I hitting?

Post by Roberthh » Fri Apr 24, 2020 6:20 pm

The size of the code that can be imported and executed depends on the size of the heap, and of the code structure. My personal rule of thumb is 10 lines of code/kByte heap. So for a 8266 with about 25k heap space it is ~250 lines. For a ESP32 with SPIRAM and it's 4 MB heap it's ~40.000 lines. You can play a little bit with lazy imports to push that number up. But the better effects on RAM usage are:
a) using pre-compiled code, where the compile is done on your PC, and even better
b) using frozen bytecode, where the compile is done on your PC and the code is stored in flash.

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

Re: MemoryError what limit am I hitting?

Post by pythoncoder » Sun Apr 26, 2020 6:09 am

Frozen bytecode is essential for serious work on ESP8266. You can run much bigger programs. Because they run in Flash they see a lot more free RAM so reliability is improved.
Peter Hinch
Index to my micropython libraries.

Post Reply