reducing ram usage or other solutions for my nanogui script with pico w #11011
Replies: 5 comments 11 replies
-
You don't mention it, so I ask if you are freezing the nanogui, and possibly other libraries, into a custom build of mp to gain memory? |
Beta Was this translation helpful? Give feedback.
-
i was planning to find out how to freeze something as soon as i have the script working stable. what i do see if i write a label or textbox on a small part of the screen it takes about 15kb for that moment and with only 19 free on average even an extra print statement can tip the scale. |
Beta Was this translation helpful? Give feedback.
-
I'm no expert, just a bumbling hobby programmer, but I think that freezing the code into a mp build means the code does not have to be copied into RAM when it runs. Maybe someone would give a better explanation. I had my first go at a custom build a month back and it was to freeze the nanogui and mqtt_as libraries from @peterhinch. I show the gc.memory() results when I run a script with .py files and the results when its run from a custom build. .py files: custom build: For the nanogui, following something peter has written I did not freeze the driver file, just the stuff in the gui dir.
I hope it helps :-) |
Beta Was this translation helpful? Give feedback.
-
To add some general comments. I'm quite surprised that you're running out of RAM on a Pico. I would try to determine whether the RAM is being used by from color_setup import ssd # Create a display instance
from gui.core.nanogui import refresh
from gui.core.writer import CWriter
from gui.core.colors import *
import gc
from gui.widgets.label import Label
import gui.fonts.freesans20 as freesans20 # Use whatever font you are using
refresh(ssd) # Initialise and clear display.
CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, freesans20, GREEN, BLACK, verbose=False)
wri.set_clip(True, True, False)
# End of boilerplate code. This is our application:
Label(wri, 2, 2, 'Hello world!')
refresh(ssd)
gc.collect()
gc.mem_free() # Display free RAM with the GUI loaded If the bulk of the RAM use is in the application then trawling the code for optimisations is the way forward. |
Beta Was this translation helpful? Give feedback.
-
@TLmv |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
i've got the nanogui library of Peter Hinch in use on a pico w combined with a I2C relay card and 6 OneWire sensors.
It also includes logging to a SD card and has a touchscreen.
as a display I have a 320x240px screen with a st7789 chip.
the script only refreshes the screen every 10 seconds, so i thought it would have plenty time to build uo the screen somewhere in those 10 seconds.
and while i was trying to create a extra pwm signal i ran out of memory.
all in all it seems i reached the limits, so i tried to see what my memory usage was, and added a few gc.mem_free() calls.
my first thought was that my script was hogging memory, but after testing it seemed i had not much to work with as is.
what i'm wondering is, can i get more free ram or should i consider something else, like using a different mcu or combining 2 picos to share the workload, stopping with the display and creating a webinterface....
as you can imagine, the script is a bit long to share here, but any suggestions how i can squeeze more out the pico are appreciated.
what i see in memory usage:
after loading machine, the onewire.ds library etc. it still has 137kb free
after loading color setup this drops to 89kb
after writer this drops to 80kb
after fplot it drops to 66kb
after loading 2 fonts (12 and 35 px) and colors it drops to 46kb
and when my main program starts , it's down to 33kb.
finally when running it has about 19kb of free memory on average.
cleaning up about 10kb would be enough i think.
I was thinking about if it would be possible to scale the small lettertype (12pc) to a larger font to save on memory, but then that wouldn't save much RAM is my guess, somebody else came with the idea that i should either drop the buffer to 2bit or that i use a buffer that is only 160x120px and then scale it to 320x240px, but i wouldn't know how or if that is possible.
any suggestion is welcom :)
Beta Was this translation helpful? Give feedback.
All reactions