peter-l5 / MicroPython_SCD4X

MicroPython driver for Sensirion SCD40 and SCD41. Derived from the Adafruit CircuitPython version
MIT License
5 stars 1 forks source link

Memory errors? #1

Closed bocephasj closed 1 year ago

bocephasj commented 1 year ago

When running I get this : MemoryError: memory allocation failed, allocating %u bytes

running this on Xbee3 with scd41 attached to grove board I am fairly new to Python/MicroPython. willing to pay for assistance in getting this setup working!!!

peter-l5 commented 1 year ago

Hi, sounds like an interesting project. I've not used the xbee3, but see that it has less memory than the raspberry pi pico, which I typically use. There's a xBee3 MicroPython memory management tips page although that looks fairly advanced. Is there more from the log or console that you can post that would give context to the problem. Also is it on start up, or running or when? You can ask MicroPython to report the amount of memory used, that may be worth added to your code to give insight into where the problem is happening. For some general background on memory issues this page might give pointers towards solutions. Is your code on GitHub? Hope this helps, at least a little.

peter-l5 commented 1 year ago

Reporting on memory usage you can be done using the garbage collection module:

import gc

And to report usage, for example:

print('Initial free memory: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))

You can repeat this at various points and edit the text "Initial free memory" according to the stage of the code.

Let me know if if this helps!

peter-l5 commented 1 year ago

Hi @bocephasj , just checking in with you, I wondered if the comments and links had been any use? (It was interesting to me to read the materials in any event.) If I don't hear further from you I'll close this issue in a few days.

peter-l5 commented 1 year ago

closing as resolved

jbdesbas commented 3 months ago

I had a memory issue on ESP8266 micropython, solved by removing all docstrings ✅. According to the community, ESP8266 Can handle ~300 lines python files.