Xinyuan-LilyGO / LilyGo-EPD-4-7-OWM-Weather-Display

Using the LilyGo EPD 4.7" display to show OWM Weather Data
65 stars 27 forks source link

ESP32 - Allocating too big graphic buffer - blocks whole MicroPython #2

Open georgik opened 1 year ago

georgik commented 1 year ago

Model: LilyGO TTGO T5-4.7" E-Paper ESP32 (not S3) "free" memory after booting MicroPython: 4085216 (import gc; gc.mem_free()) Code in repl: buffer = [ 0 for i in range(0, int(960 * 540 / 2)) ] Based on code: https://github.com/Xinyuan-LilyGO/LilyGo-EPD-4-7-OWM-Weather-Display/tree/web/micropython

MicroPython is blocked for long period of time. Allocating such big block is not recommended for ESP32 which has ROM functions in the middle of memory space. Big buffer might cause overwrite of the data. This is not case of S3 where ROM data are stored in different location.

Working allocation: buffer = [ 0 for i in range(0, int(960 * 100 / 2)) ] Workaround: drawing in small chunks and doing update part by part. Workaround 2: use ESP32-S3 model

georgik commented 1 year ago

Correction: The root cause of the problem are not ROM functions, but usage of PSRAM which is slower than limited SRAM. Once the allocation is too big, the MicroPython grabs available memory from PSRAM which is way slower. That explains delays on REPL.

kubark42 commented 1 year ago

Thanks a lot for posting this, it helped me understand why things hung when I was doing simple image writes.