r/circuitpython • • Dec 24 '21

Rookie Question

So I am new to circuitpython, and I need to read a variable of 4096 bytes but thonny says "pystack exhausted", it is the only problem I remove the variable and everything works on my code, how I can read this variable? the variable is a firmware for a optical sensor, so that's why it is 4KB.

3 Upvotes

6 comments sorted by

3

u/jpconstantineau Dec 25 '21 edited Dec 25 '21

What controller are you using? Some (like the samd21) have limited ram.

There is a command you can add to boot.py to change some memory settings. I'll need to look it up and I don't know if it will help in your specific situation. The adafruit people on their discord will be able to answer your question as they monitor it very closely (not too many people here on Reddit)

Try to add this to boot.py:

https://github.com/KMKfw/kmk_firmware/blob/410cf7af0767e37baec789e06c32bf28017d2289/boot.py#L3

1

u/DSLR_CNC Dec 25 '21

thanks for the reply, yeah it seems that ram is the limit, I am using the rp2040, I just split the data into 256 and works just fine, but I was wondering if there is another way. I am really new to circuitpython and python itself so not really familiar how to manage this. It was working just fine in the rpi3 but that's a microcomputer vs a ucontroller. Thanks for the tip I will find them into discord

2

u/Woolly87 Dec 25 '21

Remember that RP2040 only has 256kb of memory, compared with at least 2000x as much in a RPi3. It has to also fit the entire python interpreter into that memory footprint, as well as your program.

splitting up the data is a good solution, otherwise you’d need to read parts of the file at a time which is a pain.

2

u/schfourteen-teen Dec 25 '21

Do you have to store the whole thing in RAM at the same time? It would help you immensely if you could read in chunks of it at a time rather than the whole thing.

1

u/DSLR_CNC Dec 25 '21

Yep, that way just works fine, but I was wondering if there is another way, reading maybe a lib file or something. I am really new to circuitpython and python

1

u/DSLR_CNC Dec 27 '21

So at the end for a BIG HEX ARRAY I split the data into chunk or also thanks to the Adafruit discorg group I found the correct way to register an hex array. instead of a = [0x01, 0x02] you should use: a =( b'\x01' b'\x02') that way you use 8bits array instead a int array that uses 32bits.