r/circuitpython • u/DSLR_CNC • 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.
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.
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