Page 1 of 3

Reached the memory limits of the ESP8266 board. Now what?

Posted: Sun Dec 10, 2017 4:19 pm
by BoKKeR
hey, I just got my board that I bought to replace a raspberry pi as it seemed to be an overkill for the project, both from the HW and price point. Half or 1/3 of the code is done but I am starting to hit the memory barrier. I looked into what can be done. It does not seem to be possible to expand the memory by switching chips at the moment. The only other way seems to be mounting an SD card. How reliable is this solution? Are there other boards in the same price range that have little more under the hood and support micropython? (ordered an esp32 already). Or should I just drastically cut down my code? Is there a way to slim down the FW? Thanks

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Mon Dec 11, 2017 12:23 am
by jickster
RAM or flash?


Sent from my iPhone using Tapatalk

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Mon Dec 11, 2017 5:24 am
by pythoncoder
If the limit is RAM the solution is to use frozen bytecode. This is documented here http://docs.micropython.org/en/latest/p ... ained.html.

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Mon Dec 11, 2017 10:06 am
by BoKKeR
I would actually say both. sh1106 lib, custom font. When I try to upload the code I get:

raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last
):\r\n File "<stdin>", line 1, in <module>\r\nOSError: 28\r\n')

and if I try to run it with ampy I get

raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last
):\r\n File "<stdin>", line 4, in <module>\r\nMemoryError: \r\n')

I tried to get the SD card to work. It reads fine but won't write and it disappears from time to time. I will try packing later today

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Thu Dec 14, 2017 2:15 pm
by pythoncoder
Fonts can take a great deal of RAM. You might be interested in this https://github.com/peterhinch/micropyth ... -to-py.git which is a means of converting industry standard font files into Python source. The aim is to freeze the files as bytecode. The font data for each glyph can be accessed with minimal RAM usage.

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Thu Dec 14, 2017 2:21 pm
by BoKKeR
Yes that is the method I used for my font. I think it's the libraries I use that eat Up the space and ram. I heard that the esp8266 can handle around 200-250 lines of code . This might seem like a stupid measurement but I am way over 300-400

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Fri Dec 15, 2017 6:54 am
by pythoncoder
If you're compiling on the target hardware there tends to be an approximate maximum size of an individual module which can be compiled. For example on the Pyboard I reckon it's roughly 1K LOC. But if you're using frozen bytecode the limit becomes much larger and hard to quantify.

In my experience the practical RAM limit tends to result from heap fragmentation rather than sheer code volume, in which case there can often be ways of reducing this. http://docs.micropython.org/en/latest/e ... ained.html

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Sat Dec 16, 2017 4:17 pm
by BoKKeR
based on this post: https://learn.adafruit.com/micropython- ... en-modules I will need to build a new firmware with my script. This is not a problem but this is not an ideal development process. How can I approach developing the script some other way? Is there a way to run the script in a virtual environment? If I take the approach from the site I will have to recompile and reflash my esp8266 every time I change something under the development process.

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Sat Dec 16, 2017 4:25 pm
by SpotlightKid
Before you resort to frozen bytecode, you can try whether using pre-compiled *.mpy module files saves you enough RAM (at least while developing):

https://github.com/micropython/micropyt ... /README.md

Re: Reached the memory limits of the ESP8266 board. Now what?

Posted: Mon Dec 18, 2017 6:51 am
by pythoncoder
Indeed. The approach I use with large applications is to split the app into modules. Modules which are largely debugged get frozen. I keep the module under development as Python source so it can be turned round quickly. If that module is still too big then I cross compile.

Failing all that a fast multi-core PC and make -j 8 (or other suitable number) are your friends.