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

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

Post by BoKKeR » Mon Dec 18, 2017 5:32 pm

That looks interesting and I will probably do the same as the alternative is switching to RPI zero which costs 4x as much as the esp. I got this error tho.

Code: Select all

     raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'\r\n ets Jan  8 2013,rst cause:1, bo
t mode:(3,0)\r\n\r\nload 0x40100000, len 31100, room 16 \r\ntail 12\r\nchksum 0
e3\r\nho 0 tail 12 room 4\r\nload 0x3ffe8000, len 1084, room 12 \r\ntail 0\r\nc
ksum 0xc0\r\nload 0x3ffe8440, len 3248, room 8 \r\ntail 8\r\nchksum 0xe1\r\ncsu
 0xe1\r\n\x0e\x0c', b'$\xdc\x9f|\xfe\x1b\x9f\xe0\x8e{N#\x8f\x80\x84')
is it ram related? btw how realistic is running micropython under windows or under a emulator?

User avatar
hase
Posts: 3
Joined: Thu Jan 11, 2018 1:24 pm
Location: Berlin, Germany, Europe, Earth
Contact:

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

Post by hase » Thu Jan 11, 2018 2:47 pm

[quote=BoKKeR post_id=23974 time=1513618333 user_id=3489]
is it ram related? btw how realistic is running micropython under windows or under a emulator?
[/quote]

I am developing the logic for my applications on Linux, using the micropython unix port.
Its fast, has basically no RAM limits etc.

Maybe that is the "emulator" you are looking for?

Once I am happy with a modules performance, that goes into the frozen modules, so the interpreter on the board does not need to compile it; this will save RAM.

What caused your actual ampy-error is hard to tell.
hase

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 Jan 11, 2018 10:23 pm

I actually ended up with the same solution. Running micropython on a rpi. Too bad i2c is not supported

Vrettel
Posts: 1
Joined: Fri Jan 12, 2018 12:44 pm

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

Post by Vrettel » Fri Jan 12, 2018 1:32 pm

[quote=pythoncoder post_id=23803 time=1512969876 user_id=265]
If the limit is RAM the solution is to use frozen bytecode. This is documented here [url]http://docs.micropython.org/en/latest/p ... ained.html[/url].
[/quote]

Hello,

I also face problems with limited memory on ESP8266. I read the documentation concerning some tricks that can be done in order to save RAM. In my situation, I use 5 modules loaded on the board's filesystem. I use mpy-cross to compile the code before uploading to ESP.
I also use the garbage collector in specific points on code to manage fragmentation.
When measuring the initial memory left with gc.mem_free() before WiFi connection, my result is about 20K or less. My current program produces memory allocation errors even after using pre-compiled modules.
I would like to extend my program so I believe 20K limit is a part of the problem. My questions are:
1) Building my own custom micropython image with less modules (only the modules that I need) would increase the memory left for my program (20K) ?
2) Freezing some of my modules inside the firmware would have an important impact on free memory ?
3) Do you have any suggestion on how to increase the available memory for my code?

Thanks in advance,
George

User avatar
hase
Posts: 3
Joined: Thu Jan 11, 2018 1:24 pm
Location: Berlin, Germany, Europe, Earth
Contact:

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

Post by hase » Fri Jan 12, 2018 6:12 pm

Vrettel wrote:
Fri Jan 12, 2018 1:32 pm
pythoncoder wrote:
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.
3) Do you have any suggestion on how to increase the available memory for my code?
I am pretty new to the Micropython table, so I am basically operating on educated guesses at the moment.
My education for thoses guesses is about 30 years of fiddling with microcontrollers, though.

I still have to look into implementation details of the Micropyton interpreter, but I think it is safe to say that strings and names of objects use RAM. Again: I am guessing and may be completely wrong. :mrgreen:
Maybe you can measure the impact of this by tracing the gc.mem_free() output over the runtime of your program and running two versions: one regular, the other with names of variables, objects, keys (indexes into dictionaries) replaced by very short strings.
This could be done with a C preprocessor and a bunch of #define statements.

I am planning to do just that when my current projects hits the RAM ceiling - and I am sure it will. Sometime.
But it is on the back burner for now, a customer called today and I am off to a job next week.

Oh, btw: the 20k RAM you have at the start of the program is pretty much all the ESP8266 will ever have.
If you already know this not to be sufficient, you better switch to another hardware richt away.
The ESP32 might be an alternative, or running the ESP8266 with the factory firmware (AT command set) and running the logic on a secondary µC.

hth
hase

cefn
Posts: 205
Joined: Tue Aug 09, 2016 10:58 am

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

Post by cefn » Fri Jan 12, 2018 9:28 pm

I managed to squeeze a bit more memory out by building my own image, but it was a black art which I never fully understood, although I increased available memory quite a bit, I never knew exactly how and I was told by well-informed people that at least some of the things I was doing shouldn't be done, or would have no effect, but I seemed to get a whole lot more RAM out of it.

The discussion finished with a commit to my own fork based on micropython HEAD at that time, but no doubt things would need to be changed to match a newer build process.
viewtopic.php?t=3312#p19371

Not advising you to make the same changes, and it's gnarly to build this way but the changes I made could be candidates for investigation/consideration.

Are you in a position to share your code. Bit tricky to judge what optimisations might be possible without seeing it.

OutoftheBOTS_
Posts: 402
Joined: Mon Nov 20, 2017 10:18 am

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

Post by OutoftheBOTS_ » Sat Jan 13, 2018 4:45 am

I also had the trouble of running out of RAM on ESP8266 and it was good learning experience for me to become more memory management and conservative but in the end I now use the ESP32 with 4Meg of flash plus 4Meg of psRAM now I have memory to burn :)

The ESP32 has many other improved features as well, 1 of the biggest that I use all the time is the increased I/0 pins

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 Jan 20, 2018 1:09 pm

4Meg of PSram? what do you mean by that? how ?

OutoftheBOTS_
Posts: 402
Joined: Mon Nov 20, 2017 10:18 am

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

Post by OutoftheBOTS_ » Sat Jan 20, 2018 9:11 pm

The ESP32 comes prebuilt in a couple of different modules mainly hte Wroom and Wrover modules. The Wroom has the extended 4mb flash for storage space but only ther standard 512kb of operating RAM but the Wrover modules come with 4mb of extended flash and another 4mb of extended operating RAM too see this thread viewtopic.php?f=18&t=3553&p=23425&hilit=wrover#p23425

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 Jan 20, 2018 10:46 pm

ah I see. and they are double the price also.

Post Reply