Reached the memory limits of the ESP8266 board. Now what?
Reached the memory limits of the ESP8266 board. Now what?
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?
RAM or flash?
Sent from my iPhone using Tapatalk
Sent from my iPhone using Tapatalk
- 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?
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.
Index to my micropython libraries.
Re: Reached the memory limits of the ESP8266 board. Now what?
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
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
- 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?
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.
Index to my micropython libraries.
Re: Reached the memory limits of the ESP8266 board. Now what?
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
- 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?
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
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.
Index to my micropython libraries.
Re: Reached the memory limits of the ESP8266 board. Now what?
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.
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: Reached the memory limits of the ESP8266 board. Now what?
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
https://github.com/micropython/micropyt ... /README.md
- 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?
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.
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.
Index to my micropython libraries.