💬 Atmospheric Pressure Sensor
-
This thread contains comments for the article "Atmospheric Pressure Sensor" posted on MySensors.org.
-
Anybody feeling like adopting this to the BME280 and including temperature and humidity readings?? Low cost single chip and power usage looks fairly low...
@ksga
I think I will do that. It seems to be able to run it from 1.8V to 5V.
Now BME280 is cheaper than it was 1 year ago, i think.
http://www.ebay.com/itm/I2C-SPI-Breakout-Temperature-Humidity-Barometric-Pressure-BME280-Digital-Sensor-/272267632353?hash=item3f646a5ee1:g:07oAAOSwnFZXV9L2 -
@ksga
I think I will do that. It seems to be able to run it from 1.8V to 5V.
Now BME280 is cheaper than it was 1 year ago, i think.
http://www.ebay.com/itm/I2C-SPI-Breakout-Temperature-Humidity-Barometric-Pressure-BME280-Digital-Sensor-/272267632353?hash=item3f646a5ee1:g:07oAAOSwnFZXV9L2 -
BME280 is quite nice. I got one last year that I added to my gateway and it worked flawlessly since then.
If you remove the gateway/esp8266 top part you should be able to directly use code from https://github.com/emc2cube/MyWeatherGatewayESP8266 (which was updated from this one anyway)
-
I just ordered one at ebay...
Nice to see that other weatherstations make use of this code. -
So I added the My Sensors board file, added the my sensors libary through library manager, coped the adafruit library and tried to compile. Arduino: 1.8.1 (Windows 8.1), Board: "Arduino Mini, ATmega328"
C:\Users\eddy\Documents\Arduino\bmpTest\bmpTest.ino: In function 'void setup()':
bmpTest:95: error: 'getConfig' was not declared in this scope
metric = getConfig().isMetric; ^exit status 1
'getConfig' was not declared in this scopeThis report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Did I miss something? -
@boblasure I am not sure why, but the name of getConfig was changed. See https://forum.mysensors.org/topic/5841/getconfig-was-not-declared-in-this-scope-v2-1-1-fixed/ if you want to upgrade to 2.1.1 again.
-
I tried to modify the weather forecast script to run each 5 minutes instead of every minute but now I am getting strange forecasts and sometimes unknown conditions.
Doesn't anybody tried to accomplish this ? -
I found some problems in code. I did make some change to be able to get value. I replace "float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;" by "float pressure = bmp.readPressure() / 100 ;"
I'll make a PR on GitHub when everything will be well tested. :)
-
Hi, i've a problem with the bmp180 with domoticz. I use raspberry pi with domoticz and mysensor v2 and nrf24 on gpio, i receive data but i think is wrong. The temperature is 31°C and pressure is 728. I put my altitude in the sketch.
Can you help me?
Best regards. -
Hi, i've a problem with the bmp180 with domoticz. I use raspberry pi with domoticz and mysensor v2 and nrf24 on gpio, i receive data but i think is wrong. The temperature is 31°C and pressure is 728. I put my altitude in the sketch.
Can you help me?
Best regards.Welcome to the MySensors community @James-Flosse !
Could you post your sketch and debug output from the node and the gateway?
If you haven't looked at it already, https://www.mysensors.org/build/debug#enabling-debug-logging has information on how to enable debug logging.
-
Hi @mfalkvidd. This is the debug output and my code
2269 MCO:REG:REQ 2277 TSF:MSG:SEND,3-3-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2287 TSF:MSG:READ,0-0-3,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2293 MCO:PIM:NODE REG=1 2295 MCO:BGN:STP 2306 MCO:BGN:INIT OK,TSP=1 Forecast at minute 1 dP/dt = 0.00kPa/h --> unknown Temperature = 31.00 *C Pressure = 728.00 hPa Forecast = unknown 2359 TSF:MSG:SEND,3-3-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:31.0 2369 TSF:MSG:SEND,3-3-0-0,s=0,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:728 2381 TSF:MSG:SEND,3-3-0-0,s=0,c=1,t=5,pt=0,l=7,sg=0,ft=0,st=OK:unknown 2387 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 2394 MCO:SLP:TPD// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <Adafruit_BMP085.h> #define BARO_CHILD 0 #define TEMP_CHILD 1 const float ALTITUDE = 688; // <-- adapt this value to your own location's altitude. // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute. const unsigned long SLEEP_TIME = 60000; const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" }; enum FORECAST { STABLE = 0, // "Stable Weather Pattern" SUNNY = 1, // "Slowly rising Good Weather", "Clear/Sunny " CLOUDY = 2, // "Slowly falling L-Pressure ", "Cloudy/Rain " UNSTABLE = 3, // "Quickly rising H-Press", "Not Stable" THUNDERSTORM = 4, // "Quickly falling L-Press", "Thunderstorm" UNKNOWN = 5 // "Unknown (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor float lastPressure = -1; float lastTemp = -1; int lastForecast = -1; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h be dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; bool metric; MyMessage tempMsg(TEMP_CHILD, V_TEMP); MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage forecastMsg(BARO_CHILD, V_FORECAST); void setup() { if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } metric = getControllerConfig().isMetric; } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pressure Sensor", "1.1"); // Register sensors to gw (they will be created as child devices) present(BARO_CHILD, S_BARO); present(TEMP_CHILD, S_TEMP); } 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(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); if (temperature != lastTemp) { send(tempMsg.set(temperature, 1)); lastTemp = temperature; } if (pressure != lastPressure) { send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } sleep(SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = UNKNOWN; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = UNKNOWN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWN; } // uncomment when debugging Serial.print(F("Forecast at minute ")); Serial.print(minuteCount); Serial.print(F(" dP/dt = ")); Serial.print(dP_dt); Serial.print(F("kPa/h --> ")); Serial.println(weather[forecast]); return forecast; }2017-03-09 10:52:56.474 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:52:56.475 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:52:56.488 (GATEWAY) Temp (Temp) 2017-03-09 10:52:56.497 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:52:56.503 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:53:40.053 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:53:40.054 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:53:40.067 (GATEWAY) Temp (Temp) 2017-03-09 10:53:40.075 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:53:40.081 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:14.102 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:54:14.104 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:54:14.148 (GATEWAY) Temp (Temp) 2017-03-09 10:54:14.162 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:14.172 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:26.662 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:54:26.664 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:54:26.676 (GATEWAY) Temp (Temp) 2017-03-09 10:54:26.685 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:26.691 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:44.122 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:54:44.123 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:54:44.136 (GATEWAY) Temp (Temp) 2017-03-09 10:54:44.145 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:44.150 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:50.417 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 10:54:51.225 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 10:54:51.227 (GATEWAY) Temp (Temp) 2017-03-09 10:54:51.236 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:54:51.242 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:55:55.513 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:58:05.600 (GATEWAY) Temp (Temp) 2017-03-09 10:58:05.608 (GATEWAY) General/Barometer (Baro) 2017-03-09 10:59:10.651 (GATEWAY) Temp (Temp) 2017-03-09 11:01:20.704 (GATEWAY) Temp (Temp) 2017-03-09 11:02:00.701 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:02:00.702 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:02:00.715 (GATEWAY) Temp (Temp) 2017-03-09 11:02:00.723 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:00.728 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:31.650 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:02:31.652 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:02:31.664 (GATEWAY) Temp (Temp) 2017-03-09 11:02:31.673 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:31.678 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:38.872 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:02:38.873 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:02:38.886 (GATEWAY) Temp (Temp) 2017-03-09 11:02:38.894 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:38.900 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:41.863 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:02:41.864 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:02:41.887 (GATEWAY) Temp (Temp) 2017-03-09 11:02:41.895 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:41.901 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:49.208 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:02:49.209 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:02:49.232 (GATEWAY) Temp (Temp) 2017-03-09 11:02:49.240 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:02:49.245 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:03:54.286 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:04:59.319 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:06:04.359 (GATEWAY) Temp (Temp) 2017-03-09 11:06:04.368 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:06:36.109 MySensors: Node: 3, Sketch Name: Pressure Sensor 2017-03-09 11:06:36.111 MySensors: Node: 3, Sketch Version: 1.1 2017-03-09 11:06:36.123 (GATEWAY) Temp (Temp) 2017-03-09 11:06:36.132 (GATEWAY) General/Barometer (Baro) 2017-03-09 11:06:36.137 (GATEWAY) General/Barometer (Baro)