[solved] Sensor freezes - Low memory available, stability problems may occur.
-
Another possible optimization, is to dig into the sensor libs you're using, and disable/remove/comment etc.. things you don't need. i'm pretty sure in BME280 there are stuff you don't need in some functions (just quick looked).
When using multiple libs and sensors, you can save a lot like this. Libs are there for providing us lot of features, but not necessarily needed in your final fw. -
Another possible optimization, is to dig into the sensor libs you're using, and disable/remove/comment etc.. things you don't need. i'm pretty sure in BME280 there are stuff you don't need in some functions (just quick looked).
When using multiple libs and sensors, you can save a lot like this. Libs are there for providing us lot of features, but not necessarily needed in your final fw. -
Just for info, that's what I found on arduino forum
Eighteen Hints to Reduce Code Size
- Compile with full size optimization.
- Use local variables whenever possible.
- Use the smallest applicable data type. Use unsigned if applicable.
- If a non-local variable is only referenced within one function, it should be declared static.
- Collect non-local data in structures whenever natural. This increases the possibility of indirect addressing without pointer reload.
- Use pointers with offset or declare structures to access memory mapped I/O.
- Use for(;;) { } for eternal loops.
- Use do { } while(expression) if applicable.
- Use descending loop counters and pre-decrement if applicable.
- Access I/O memory directly (i.e., do not use pointers).
- Declare main as C_task if not called from anywhere in the program.
- Use macros instead of functions for tasks that generates less than 2-3 lines assembly code.
- Reduce the size of the Interrupt Vector segment (INTVEC) to what is actually needed by the application. Alternatively, concatenate all the CODE segments into one declaration and it will be done automatically.
- Code reuse is intra-modular. Collect several functions in one module (i.e., in one file) to increase code reuse factor.
- In some cases, full speed optimization results in lower code size than full size optimization. Compile on a module by module basis to investigate what gives the best result.
- Optimize C_startup to not initialize unused segments (i.e., IDATA0 or IDATA1 if all variables are tiny or small).
- If possible, avoid calling functions from inside the interrupt routine.
- Use the smallest possible memory model.
-
A lot of debug code in this sketch has not been enclosed between #ifdef MYDEBUG/#endif blocks. Even if you disable MYDEBUG, most of the Serial.print() lines remain 'active'.
Try to comment most of the Serial.print() code or add the #ifdef statements to have the compiler ignore these Serial.print() lines.
Most memory in this sketch is eaten up by the strings ("xxx"). -
A lot of debug code in this sketch has not been enclosed between #ifdef MYDEBUG/#endif blocks. Even if you disable MYDEBUG, most of the Serial.print() lines remain 'active'.
Try to comment most of the Serial.print() code or add the #ifdef statements to have the compiler ignore these Serial.print() lines.
Most memory in this sketch is eaten up by the strings ("xxx"). -
A lot of debug code in this sketch has not been enclosed between #ifdef MYDEBUG/#endif blocks. Even if you disable MYDEBUG, most of the Serial.print() lines remain 'active'.
Try to comment most of the Serial.print() code or add the #ifdef statements to have the compiler ignore these Serial.print() lines.
Most memory in this sketch is eaten up by the strings ("xxx"). -
@ftw64 since the strings are wrapped in F() they actually do not use (global) ram. When using F(), the strings are only stored in flash.
So while adding #ifdef around the print statements will save flash, it will not save ram.
@mfalkvidd Oh, cool. I missed that (and I didn't know that, and I learned something today :-)). Yep, in that case it wouldn't help much.