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

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
BoKKeR
Posts: 16
Joined: Sun Dec 10, 2017 4:10 pm

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

Post by BoKKeR » Sun Dec 10, 2017 4:19 pm

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

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

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

Post by jickster » Mon Dec 11, 2017 12:23 am

RAM or flash?


Sent from my iPhone using Tapatalk

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

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

Post by pythoncoder » Mon Dec 11, 2017 5:24 am

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.
Peter Hinch
Index to my micropython libraries.

User avatar
BoKKeR
Posts: 16
Joined: Sun Dec 10, 2017 4:10 pm

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

Post by BoKKeR » Mon Dec 11, 2017 10:06 am

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

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

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

Post by pythoncoder » Thu Dec 14, 2017 2:15 pm

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.
Peter Hinch
Index to my micropython libraries.

User avatar
BoKKeR
Posts: 16
Joined: Sun Dec 10, 2017 4:10 pm

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

Post by BoKKeR » Thu Dec 14, 2017 2:21 pm

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

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

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

Post by pythoncoder » Fri Dec 15, 2017 6:54 am

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
Peter Hinch
Index to my micropython libraries.

User avatar
BoKKeR
Posts: 16
Joined: Sun Dec 10, 2017 4:10 pm

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

Post by BoKKeR » Sat Dec 16, 2017 4:17 pm

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.
Last edited by BoKKeR on Sat Dec 16, 2017 4:27 pm, edited 1 time in total.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

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

Post by SpotlightKid » Sat Dec 16, 2017 4:25 pm

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

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

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

Post by pythoncoder » Mon Dec 18, 2017 6:51 am

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.
Peter Hinch
Index to my micropython libraries.

Post Reply