Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. [solved] Sensor freezes - Low memory available, stability problems may occur.

[solved] Sensor freezes - Low memory available, stability problems may occur.

Scheduled Pinned Locked Moved Troubleshooting
18 Posts 5 Posters 5.8k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gohanG gohan

    A friend of mine told me that atmel studio is more efficient at compiling than the arduino ide, I haven't tested it yet but maybe somebody could confirm.

    alexsh1A Offline
    alexsh1A Offline
    alexsh1
    wrote on last edited by
    #7

    @gohan Well could be, but it is too late to teach an old dog a new trick in my case. I am comfortable with Arduino IDE - I can flash atmega, ESP, SAMD etc.

    1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #8

      If that was the case, you could use the atmel studio just for sw upload. Myself I'm using visual studio preferably, it makes it faster to write code but for quick modification I still use the arduino ide

      1 Reply Last reply
      0
      • scalzS Offline
        scalzS Offline
        scalz
        Hardware Contributor
        wrote on last edited by scalz
        #9

        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.

        alexsh1A 1 Reply Last reply
        0
        • gohanG Offline
          gohanG Offline
          gohan
          Mod
          wrote on last edited by
          #10

          Shouldn't the compiler exclude all functions that aren't used in the code?

          alexsh1A 1 Reply Last reply
          0
          • gohanG gohan

            Shouldn't the compiler exclude all functions that aren't used in the code?

            alexsh1A Offline
            alexsh1A Offline
            alexsh1
            wrote on last edited by
            #11

            @gohan no, the compiler compiles whatever you ask to compile. It's your duty to "improve" your code by excluding stuff you are not using

            1 Reply Last reply
            0
            • gohanG Offline
              gohanG Offline
              gohan
              Mod
              wrote on last edited by
              #12

              Back in the days when I was studying, compilers used to have code optimizers built in... Oh well... Never mind 😅

              1 Reply Last reply
              0
              • scalzS scalz

                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.

                alexsh1A Offline
                alexsh1A Offline
                alexsh1
                wrote on last edited by
                #13

                @scalz I'm with you, but just like you I just do not have time for it. There is Teensy 3.2 with excellent footprint and 10 times speed and memory. So I just feel like if I'm going to spend time, it has to be not yesterday's technology.

                1 Reply Last reply
                2
                • gohanG Offline
                  gohanG Offline
                  gohan
                  Mod
                  wrote on last edited by gohan
                  #14

                  Just for info, that's what I found on arduino forum

                  Eighteen Hints to Reduce Code Size

                  1. Compile with full size optimization.
                  2. Use local variables whenever possible.
                  3. Use the smallest applicable data type. Use unsigned if applicable.
                  4. If a non-local variable is only referenced within one function, it should be declared static.
                  5. Collect non-local data in structures whenever natural. This increases the possibility of indirect addressing without pointer reload.
                  6. Use pointers with offset or declare structures to access memory mapped I/O.
                  7. Use for(;;) { } for eternal loops.
                  8. Use do { } while(expression) if applicable.
                  9. Use descending loop counters and pre-decrement if applicable.
                  10. Access I/O memory directly (i.e., do not use pointers).
                  11. Declare main as C_task if not called from anywhere in the program.
                  12. Use macros instead of functions for tasks that generates less than 2-3 lines assembly code.
                  13. 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.
                  14. Code reuse is intra-modular. Collect several functions in one module (i.e., in one file) to increase code reuse factor.
                  15. 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.
                  16. Optimize C_startup to not initialize unused segments (i.e., IDATA0 or IDATA1 if all variables are tiny or small).
                  17. If possible, avoid calling functions from inside the interrupt routine.
                  18. Use the smallest possible memory model.
                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    ftw64
                    wrote on last edited by
                    #15

                    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").

                    alexsh1A mfalkviddM 2 Replies Last reply
                    0
                    • F ftw64

                      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").

                      alexsh1A Offline
                      alexsh1A Offline
                      alexsh1
                      wrote on last edited by
                      #16

                      @ftw64 thanks - very helpful

                      1 Reply Last reply
                      0
                      • F ftw64

                        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").

                        mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by mfalkvidd
                        #17

                        @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.

                        F 1 Reply Last reply
                        1
                        • mfalkviddM mfalkvidd

                          @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.

                          F Offline
                          F Offline
                          ftw64
                          wrote on last edited by
                          #18

                          @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.

                          1 Reply Last reply
                          1
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          18

                          Online

                          11.7k

                          Users

                          11.2k

                          Topics

                          113.1k

                          Posts


                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • MySensors
                          • OpenHardware.io
                          • Categories
                          • Recent
                          • Tags
                          • Popular