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. Pressure sensor - arduino low memory (SOLVED)

Pressure sensor - arduino low memory (SOLVED)

Scheduled Pinned Locked Moved Troubleshooting
pressure
25 Posts 7 Posters 13.9k Views 2 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.
  • N Offline
    N Offline
    niccodemi
    wrote on last edited by niccodemi
    #1

    When I compile pressure sensor sketch I get below error in Arduino IDE.

    pressure.jpg

    I can add it to Vera but it only works for few hours (3-4) and then stops responding. I tried disabling DEBUG but that didn't help (it did reduce storage space).

    Is there anything else to do in order to reduce dynamic memory usage?

    1 Reply Last reply
    0
    • BulldogLowellB Offline
      BulldogLowellB Offline
      BulldogLowell
      Contest Winner
      wrote on last edited by
      #2

      you can start by putting all of your string constants into program space instead of SRAM:

      use the F() macro and PROGMEM

      instead of this:

      char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"};
      

      and this:

      Serial.print("Temperature = ");
      

      try this:

      char *weather[] PROGMEM = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"};
      

      and this:

      Serial.print(F("Temperature = "));
      

      what board are you compiling it for?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        niccodemi
        wrote on last edited by
        #3

        @BulldogLowell I will try your suggestions. It's for Nano.

        N 1 Reply Last reply
        0
        • N niccodemi

          @BulldogLowell I will try your suggestions. It's for Nano.

          N Offline
          N Offline
          niccodemi
          wrote on last edited by
          #4

          @BulldogLowell can I change any other line with PROGMEM? After changing one you suggested I got 1% more.

          F() macro doesn't compile.

          press1.jpg

          1 Reply Last reply
          0
          • BulldogLowellB Offline
            BulldogLowellB Offline
            BulldogLowell
            Contest Winner
            wrote on last edited by
            #5

            the F() macro does work.... what's your sketch look like now? is it exactly as is in the examples?

            for me that compiles to

            Binary sketch size: 24,452 bytes (of a 30,720 byte maximum)
            

            selecting the Nano with ATmega 328

            N 3 Replies Last reply
            0
            • BulldogLowellB BulldogLowell

              the F() macro does work.... what's your sketch look like now? is it exactly as is in the examples?

              for me that compiles to

              Binary sketch size: 24,452 bytes (of a 30,720 byte maximum)
              

              selecting the Nano with ATmega 328

              N Offline
              N Offline
              niccodemi
              wrote on last edited by
              #6

              @BulldogLowell only things modified now are: disabled DEBUG in Myconfig.h and replaced PROGMEM line you suggested earlier. If I try to use F() I get compiling error. This is on IDE 1.5.8 and Nano 328.

              Sketch uses 18,002 bytes. Global variables use 1616 bytes (78%). I still get low memory warning.

              1 Reply Last reply
              0
              • BulldogLowellB BulldogLowell

                the F() macro does work.... what's your sketch look like now? is it exactly as is in the examples?

                for me that compiles to

                Binary sketch size: 24,452 bytes (of a 30,720 byte maximum)
                

                selecting the Nano with ATmega 328

                N Offline
                N Offline
                niccodemi
                wrote on last edited by
                #7

                @BulldogLowell just noticed that if I don't use PROGMEM then F() macro compiles ok.

                1 Reply Last reply
                0
                • BulldogLowellB BulldogLowell

                  the F() macro does work.... what's your sketch look like now? is it exactly as is in the examples?

                  for me that compiles to

                  Binary sketch size: 24,452 bytes (of a 30,720 byte maximum)
                  

                  selecting the Nano with ATmega 328

                  N Offline
                  N Offline
                  niccodemi
                  wrote on last edited by
                  #8

                  @BulldogLowell I used F() on all Serialprints("") and I got below sketch size. What is your dynamic memory usage?

                  pressure.jpg

                  1 Reply Last reply
                  0
                  • BulldogLowellB Offline
                    BulldogLowellB Offline
                    BulldogLowell
                    Contest Winner
                    wrote on last edited by
                    #9

                    When I upgraded to the 1.5.8 version of the IDE I had a lot of problems with some of the libraries I used that were bundled withe the IDE. Ethernet library have me troubles too.
                    I also noticed the same thing with F() and PROGMEM.

                    I reverted my IDE and all is well now.

                    Sorry I can't be more helpful...

                    N 1 Reply Last reply
                    0
                    • BulldogLowellB BulldogLowell

                      When I upgraded to the 1.5.8 version of the IDE I had a lot of problems with some of the libraries I used that were bundled withe the IDE. Ethernet library have me troubles too.
                      I also noticed the same thing with F() and PROGMEM.

                      I reverted my IDE and all is well now.

                      Sorry I can't be more helpful...

                      N Offline
                      N Offline
                      niccodemi
                      wrote on last edited by
                      #10

                      @BulldogLowell So which IDE are you using now? I can try with the same version. What is your dynamic memory usage?

                      1 Reply Last reply
                      0
                      • sundberg84S Offline
                        sundberg84S Offline
                        sundberg84
                        Hardware Contributor
                        wrote on last edited by
                        #11

                        I had some problems using F() in some variables like Serial.println(F(somevariable))
                        A good start is to change all Serial.println("Mytext") with Serial.println(F("Mytext"))

                        Andreas

                        Controller: Proxmox VM - Home Assistant
                        MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                        MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                        RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                        BulldogLowellB 1 Reply Last reply
                        0
                        • sundberg84S sundberg84

                          I had some problems using F() in some variables like Serial.println(F(somevariable))
                          A good start is to change all Serial.println("Mytext") with Serial.println(F("Mytext"))

                          Andreas

                          BulldogLowellB Offline
                          BulldogLowellB Offline
                          BulldogLowell
                          Contest Winner
                          wrote on last edited by BulldogLowell
                          #12

                          @sundberg84 said:

                          I had some problems using F() in some variables like Serial.println(F(somevariable))
                          A good start is to change all Serial.println("Mytext") with Serial.println(F("Mytext"))

                          Andreas

                          you had those problems because you cannot store a variable in flash (program space) only constants.

                          the compiler will automatically hold numeric constants in flash, but string constants have to be so identified for that to happen. otherwise the consume space in SRAM

                          variables initialized as const are also saved in program space:

                          const char *dayOfWeek[] = { "Null","Sunday ","Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
                          
                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            niccodemi
                            wrote on last edited by
                            #13

                            I tried IDE 1.0.5 and codebender with same results - sensor stops responding after 3-4 hours. Is anyone running this sensor successfully?
                            Upon searching for arduino board with more SRAM I found arduino micro. It has 2.5 KB SRAM (0.5 KB more than Nano). Would it work with Mysensors?

                            1 Reply Last reply
                            0
                            • hekH Offline
                              hekH Offline
                              hek
                              Admin
                              wrote on last edited by
                              #14

                              You could try with some other Arduino library for the pressure sensor perhaps.

                              N 1 Reply Last reply
                              0
                              • hekH hek

                                You could try with some other Arduino library for the pressure sensor perhaps.

                                N Offline
                                N Offline
                                niccodemi
                                wrote on last edited by
                                #15

                                @hek sure, I can try. Do you have anything specific in mind?

                                1 Reply Last reply
                                0
                                • hekH Offline
                                  hekH Offline
                                  hek
                                  Admin
                                  wrote on last edited by
                                  #16

                                  Did a quick google but I couldn't find anything good.

                                  How do you power your pressure sensor? It could be the radio that hangs after a potential power-spike.

                                  1 Reply Last reply
                                  0
                                  • m26872M Offline
                                    m26872M Offline
                                    m26872
                                    Hardware Contributor
                                    wrote on last edited by
                                    #17

                                    Why not start with a more simple sketch?
                                    #include <SPI.h>
                                    #include <MySensor.h>
                                    #include <Wire.h>
                                    #include <Adafruit_BMP085.h>

                                        #define BARO_CHILD 0
                                        #define TEMP_CHILD 1
                                        
                                        unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in seconds)
                                        
                                        Adafruit_BMP085 bmp = Adafruit_BMP085();      // Digital Pressure Sensor 
                                        MySensor gw;
                                        
                                        float lastPressure = -1;
                                        float lastTemp = -1;
                                        boolean metric; 
                                        MyMessage tempMsg(TEMP_CHILD, V_TEMP);
                                        MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
                                        
                                        void setup() {
                                          gw.begin();
                                        
                                          // Send the sketch version information to the gateway and Controller
                                          gw.sendSketchInfo("Pressure Sensor", "1.0");
                                        
                                          if (!bmp.begin()) {
                                            Serial.println("Could not find a valid BMP085 sensor, check wiring!");
                                            while (1) { }
                                          }
                                        
                                          // Register sensors to gw (they will be created as child devices)
                                          gw.present(BARO_CHILD, S_BARO);
                                          gw.present(TEMP_CHILD, S_TEMP);
                                          metric =  gw.getConfig().isMetric;
                                        }
                                        
                                        void loop() {
                                          float pressure = bmp.readPressure()/100;
                                          float temperature = bmp.readTemperature();
                                          
                                          if (!metric) {
                                            // Convert to fahrenheit
                                            temperature = temperature * 9.0 / 5.0 + 32.0;
                                          }
                                          
                                        //  int forecast = sample(pressure);
                                        
                                          Serial.print("Temperature = ");
                                          Serial.print(temperature);
                                          Serial.println(metric?" *C":" *F");
                                          Serial.print("Pressure = ");
                                          Serial.print(pressure);
                                          Serial.println(" Pa");
                                        
                                        
                                          if (temperature != lastTemp) {
                                            gw.send(tempMsg.set(temperature,1));
                                            lastTemp = temperature;
                                          }
                                        
                                          if (pressure != lastPressure) {
                                            gw.send(pressureMsg.set(pressure, 0));
                                            lastPressure = pressure;
                                          }
                                        
                                          gw.sleep(SLEEP_TIME);
                                        }
                                    
                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      niccodemi
                                      wrote on last edited by
                                      #18

                                      pressure sensor and radio are powered off Nano. There is capacitor on radio vcc / gnd pins. I will try simple sketch and report back.

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        MagKas
                                        wrote on last edited by
                                        #19

                                        @niccodemi and @hek : unfortunately there is a bug in the sketch for the pressuresensor.
                                        I have to go now but I will look up how I fixed this and report here in the evening!

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          MagKas
                                          wrote on last edited by MagKas
                                          #20

                                          @niccodemi:

                                          Here I am again.

                                          The problem is in the sample() function. It saves the pressure every minute in the array pressureSamples[]. This one is declared for 180 values which means you can use pressureSamples[0] to pressureSamples[179]. Writing to pressureSamples[180] means you are writing outside the defined array and might be writing over some other stuff in your program.
                                          In my case it resulted in radio messages which got status 'fail' all the time. First I thought it was a problem with the radio but after debugging I found the problem to be the sample() function. It always happened exactly 180 minutes after I restarted the Arduino...

                                          You have to change the following lines of code:

                                          if (minuteCount > 180)
                                            minuteCount = 6;
                                          

                                          into:

                                          if (minuteCount == 180)
                                            minuteCount = 5;
                                          

                                          The problem with the original code was that it wrote a value to pressureSamples[180] before it restarted with 6 again (which should be 5 according to me).

                                          When looking at the code I also found that the wrong samples seem to be used for the first 5 minutes. If minuteCount has reached the value of 5 it means that samples 0 to 4 has been filled. The code is using 1 to 5 in stead.

                                          To fix this, change the code under if (minuteCount == 5) into:

                                          pressureAvg[0] = ((pressureSamples[0] + pressureSamples[1]
                                          		+ pressureSamples[2] + pressureSamples[3] + pressureSamples[4])
                                          		/ 5);
                                          

                                          To be clear: this bug is not something @hek introduced, he just used the code supplied by the link in the sample()-function.

                                          Edit: But maybe he can make sure the sketch is updated so no one else will get the same problems? :)

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


                                          24

                                          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