Thanks for that tip. I tried it with only the above code in main.py, it works.pythoncoder wrote:Assuming you've double checked that bme280.py on the ESP8266 is correct, I suspect you have run out of RAM. Are you running it from webrepl? It might be worth not running webrepl and using a direct connection. Executing the following after the error may be informative:Code: Select all
import micropython micropython.mem_info()
I added code to make it report memory at key points:
Code: Select all
Memory BEFORE BME import: 22272
Memory AFTER BME import: 18624
BME values: ('24.72C', '1009.63hPa', '0.00%')
Memory now: 17360
Memory AFTER gc.collect(): 19008
Question: If instead of having bme280.py as a separate python script like this, I added it to the build folders and compiled it into the firmware, what difference would you expect it to make in terms of memory usage..?
Would this approach materially improve the ability to load several modules without running out of memory like this?
Unfortunately for me, my compiler toolchain is still broken, and it will be a hassle to keep recompiling modules into the full firmware bin ...
Could I compile the module concerned to bytecode:
Code: Select all
'python -m py_compile_files bme280.py' ==> bme280.pyc...
That at least would be significantly faster for me to make and test changes - but would this make much difference to these shortage of memory errors?
(I am guessing that compiling it into the bin will make the greatest difference because that is in flash. The bytecode .pyc files would still take ram but would be maybe 60% of the original in size...)
Thoughts?