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.8k 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
    #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
                  • hekH Offline
                    hekH Offline
                    hek
                    Admin
                    wrote on last edited by
                    #21

                    Thanks @MagKas!

                    I've pushed an update to github.

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

                      @hek: great, but not completely correct...

                      It should be: if (minuteCount == 180)

                      Could you also consider to update the sketch with my proposal in my other comment for the pressuresensor-sketch regarding changing

                      float pressure = bmp.readPressure()/100;
                      

                      to

                      float pressure = bmp.readSealevelPressure(205)/100; // 205 meters above sealevel
                      

                      I assume most people would like to have the same pressure values as the local wheather station or airport has.

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

                        @MagKas

                        Ok, done!
                        Also had to update to the latest library-version to get the readSealevelPressure()-function.

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

                          thanks, pressure sensors works ok with updated code (7 hours now).

                          1 Reply Last reply
                          0
                          • nikitech0103N Offline
                            nikitech0103N Offline
                            nikitech0103
                            wrote on last edited by
                            #25

                            Still this code is working?

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


                            12

                            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