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. Development
  3. Conversion to mysensors 2.0 for BMP180

Conversion to mysensors 2.0 for BMP180

Scheduled Pinned Locked Moved Development
8 Posts 4 Posters 3.7k 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.
  • denis91D Offline
    denis91D Offline
    denis91
    wrote on last edited by
    #1

    Hi,

    Since yesteday, I has trying to convert a script for a BMP180 mysensors but I have a error.

    The old script in mysensors 1.5 is

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Pressure sensor example using BMP085 module  
     * http://www.mysensors.org/build/pressure
     *
     */
     
    #include <SPI.h>
    #include <MySensor.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 
    MySensor gw;
    
    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;
    boolean metric;
    MyMessage tempMsg(TEMP_CHILD, V_TEMP);
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
    
    
    void setup() 
    {
    	gw.begin();
    
    	// Send the sketch version information to the gateway and Controller
    	gw.sendSketchInfo("Pressure Sensor", "1.1");
    
    	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.readSealevelPressure(ALTITUDE) / 100.0;
    	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) 
    	{
    		gw.send(tempMsg.set(temperature, 1));
    		lastTemp = temperature;
    	}
    
    	if (pressure != lastPressure) 
    	{
    		gw.send(pressureMsg.set(pressure, 0));
    		lastPressure = pressure;
    	}
    
    	if (forecast != lastForecast)
    	{
    		gw.send(forecastMsg.set(weather[forecast]));
    		lastForecast = forecast;
    	}
    
    	gw.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;
    }
    

    and my script proposed in mysensors 2.0

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Pressure sensor example using BMP085 module  
     * http://www.mysensors.org/build/pressure
     *
     */
    
    #include <MyConfig.h>
    #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;
    boolean metric;
    MyMessage tempMsg(TEMP_CHILD, V_TEMP);
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
    
    
    void presentation()  
    {
    //	gw.begin();
    
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Pressure Sensor", "1.1");
    
    	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)
    	present(BARO_CHILD, S_BARO);
    	present(TEMP_CHILD, S_TEMP);
    	metric = getConfig().isMetric;
    }
    
    void loop() 
    {
    	float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
    	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;
    }
    

    When I tried to compile, Arduino said :

    Arduino : 1.6.11 (Windows 10), Carte : "Arduino Nano, ATmega328"
    
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino: In function 'void loop()':
    
    PressureSensorVDM2:112: error: 'sample' was not declared in this scope
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorvDM.ino: At global scope:
    
    PressureSensorvDM:46: error: redefinition of 'const float ALTITUDE'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:39:13: note: 'const float ALTITUDE' previously defined here
    
    PressureSensorvDM:49: error: redefinition of 'const long unsigned int SLEEP_TIME'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:42:21: note: 'const long unsigned int SLEEP_TIME' previously defined here
    
    PressureSensorvDM:51: error: redefinition of 'const char* weather []'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:44:13: note: 'const char* weather [6]' previously defined here
    
    PressureSensorvDM:52: error: multiple definition of 'enum FORECAST'
    
    PressureSensorVDM2:45: error: previous definition here
    
    PressureSensorvDM:62: error: redefinition of 'Adafruit_BMP085 bmp'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:55:17: note: 'Adafruit_BMP085 bmp' previously declared here
    
    PressureSensorvDM:65: error: redefinition of 'float lastPressure'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:57:7: note: 'float lastPressure' previously defined here
    
    PressureSensorvDM:66: error: redefinition of 'float lastTemp'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:58:7: note: 'float lastTemp' previously defined here
    
    PressureSensorvDM:67: error: redefinition of 'int lastForecast'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:59:5: note: 'int lastForecast' previously defined here
    
    PressureSensorvDM:69: error: redefinition of 'const int LAST_SAMPLES_COUNT'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:61:11: note: 'const int LAST_SAMPLES_COUNT' previously defined here
    
    PressureSensorvDM:70: error: redefinition of 'float lastPressureSamples [5]'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:62:7: note: 'float lastPressureSamples [5]' previously declared here
    
    PressureSensorvDM:77: error: redefinition of 'int minuteCount'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:68:5: note: 'int minuteCount' previously defined here
    
    PressureSensorvDM:78: error: redefinition of 'bool firstRound'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:69:6: note: 'bool firstRound' previously defined here
    
    PressureSensorvDM:80: error: redefinition of 'float pressureAvg'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:71:7: note: 'float pressureAvg' previously declared here
    
    PressureSensorvDM:82: error: redefinition of 'float pressureAvg2'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:73:7: note: 'float pressureAvg2' previously declared here
    
    PressureSensorvDM:84: error: redefinition of 'float dP_dt'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:75:7: note: 'float dP_dt' previously declared here
    
    PressureSensorvDM:85: error: redefinition of 'boolean metric'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:76:9: note: 'boolean metric' previously declared here
    
    PressureSensorvDM:86: error: redefinition of 'MyMessage tempMsg'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:77:11: note: 'MyMessage tempMsg' previously declared here
    
    PressureSensorvDM:87: error: redefinition of 'MyMessage pressureMsg'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:78:11: note: 'MyMessage pressureMsg' previously declared here
    
    PressureSensorvDM:88: error: redefinition of 'MyMessage forecastMsg'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:79:11: note: 'MyMessage forecastMsg' previously declared here
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorvDM.ino: In function 'void presentation()':
    
    PressureSensorvDM:91: error: redefinition of 'void presentation()'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:82:6: note: 'void presentation()' previously defined here
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorvDM.ino: In function 'void loop()':
    
    PressureSensorvDM:109: error: redefinition of 'void loop()'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:101:6: note: 'void loop()' previously defined here
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorvDM.ino: In function 'float getLastPressureSamplesAverage()':
    
    PressureSensorvDM:154: error: redefinition of 'float getLastPressureSamplesAverage()'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:145:7: note: 'float getLastPressureSamplesAverage()' previously defined here
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorvDM.ino: In function 'int sample(float)':
    
    PressureSensorvDM:171: error: redefinition of 'int sample(float)'
    
    C:\Users\Frédérique\Downloads\PressureSensorVDM2\PressureSensorVDM2.ino:162:5: note: 'int sample(float)' previously defined here
    
    Utilisation de la bibliothèque MySensors-master version 2.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master 
    Utilisation de la bibliothèque SPI version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI 
    Utilisation de la bibliothèque Wire version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
    Utilisation de la bibliothèque Adafruit_BMP085_Library version 1.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library 
    exit status 1
    'sample' was not declared in this scope
    

    Could you help me ?

    Many thanks for your help.

    Best regards.
    Denis

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

      The example has already been converted:

      https://github.com/mysensors/MySensorsArduinoExamples/blob/master/examples/PressureSensor/PressureSensor.ino

      1 Reply Last reply
      2
      • denis91D Offline
        denis91D Offline
        denis91
        wrote on last edited by
        #3

        Good Morning,

        Many thank for your help but this morning I tried your sketch proposed and I have the same problem :

        C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino: In function 'void loop()':
        
        PressureSensorV2.ino:118: error: 'sample' was not declared in this scope
        
        

        The complet return of compilation :

        Arduino : 1.6.11 (Windows 10), Carte : "Arduino Nano, ATmega328"
        
        C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Frédérique\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10611 -build-path C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp -warnings=all -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino
        C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Frédérique\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10611 -build-path C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp -warnings=all -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino
        Using board 'nano' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
        Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
        Detecting libraries used...
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library\Adafruit_BMP085.cpp" -o "nul"
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
        Generating function prototypes...
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
        "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino10/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
        Compilation du croquis...
        "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp.o"
        C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino: In function 'void loop()':
        
        PressureSensorV2.ino:118: error: 'sample' was not declared in this scope
        
        Utilisation de la bibliothèque SPI version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI 
        Utilisation de la bibliothèque MySensors-master version 2.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master 
        Utilisation de la bibliothèque Wire version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
        Utilisation de la bibliothèque Adafruit_BMP085_Library version 1.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library 
        exit status 1
        'sample' was not declared in this scope
        

        Could you help me ?

        Best regards.
        Denis

        mfalkviddM 1 Reply Last reply
        0
        • denis91D denis91

          Good Morning,

          Many thank for your help but this morning I tried your sketch proposed and I have the same problem :

          C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino: In function 'void loop()':
          
          PressureSensorV2.ino:118: error: 'sample' was not declared in this scope
          
          

          The complet return of compilation :

          Arduino : 1.6.11 (Windows 10), Carte : "Arduino Nano, ATmega328"
          
          C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Frédérique\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10611 -build-path C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp -warnings=all -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino
          C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Frédérique\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10611 -build-path C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp -warnings=all -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino
          Using board 'nano' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
          Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
          Detecting libraries used...
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library\Adafruit_BMP085.cpp" -o "nul"
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "nul"
          Generating function prototypes...
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
          "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino10/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
          Compilation du croquis...
          "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library" "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp" -o "C:\Users\FRDRIQ~1\AppData\Local\Temp\build273ceb3b965055d440d88958ec10e5e6.tmp\sketch\PressureSensorV2.ino.ino.cpp.o"
          C:\Users\Frédérique\Downloads\PressureSensor\PressureSensorV2.ino\PressureSensorV2.ino.ino: In function 'void loop()':
          
          PressureSensorV2.ino:118: error: 'sample' was not declared in this scope
          
          Utilisation de la bibliothèque SPI version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI 
          Utilisation de la bibliothèque MySensors-master version 2.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\MySensors-master 
          Utilisation de la bibliothèque Wire version 1.0 dans le dossier: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
          Utilisation de la bibliothèque Adafruit_BMP085_Library version 1.0.0 dans le dossier: C:\Users\Frédérique\Documents\Arduino\libraries\Adafruit_BMP085_Library 
          exit status 1
          'sample' was not declared in this scope
          

          Could you help me ?

          Best regards.
          Denis

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

          @denis91 the sample function is declared at https://github.com/mysensors/MySensorsArduinoExamples/blob/master/examples/PressureSensor/PressureSensor.ino#L168

          Could you post the full sketch? My guess is that something got damaged between downloading from github and compiling in the Arduino ide.

          1 Reply Last reply
          0
          • denis91D Offline
            denis91D Offline
            denis91
            wrote on last edited by
            #5

            Good Morning,

            The sketch :

            /**
             * The MySensors Arduino library handles the wireless radio link and protocol
             * between your home built sensors/actuators and HA controller of choice.
             * The sensors forms a self healing radio network with optional repeaters. Each
             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
             * network topology allowing messages to be routed to nodes.
             *
             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
             * Copyright (C) 2013-2015 Sensnology AB
             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
             *
             * Documentation: http://www.mysensors.org
             * Support Forum: http://forum.mysensors.org
             *
             * This program is free software; you can redistribute it and/or
             * modify it under the terms of the GNU General Public License
             * version 2 as published by the Free Software Foundation.
             *
             *******************************
             *
             * REVISION HISTORY
             * Version 1.0 - Henrik Ekblad
             * 
             * DESCRIPTION
             * Pressure sensor example using BMP085 module  
             * http://www.mysensors.org/build/pressure
             *
             */
            
            // 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 = getConfig().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.readSealevelPressure(ALTITUDE) / 100.0;
              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;
            }
            

            Many thanks for your help.

            Best regards.
            Denis

            mfalkviddM 1 Reply Last reply
            0
            • denis91D denis91

              Good Morning,

              The sketch :

              /**
               * The MySensors Arduino library handles the wireless radio link and protocol
               * between your home built sensors/actuators and HA controller of choice.
               * The sensors forms a self healing radio network with optional repeaters. Each
               * repeater and gateway builds a routing tables in EEPROM which keeps track of the
               * network topology allowing messages to be routed to nodes.
               *
               * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
               * Copyright (C) 2013-2015 Sensnology AB
               * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
               *
               * Documentation: http://www.mysensors.org
               * Support Forum: http://forum.mysensors.org
               *
               * This program is free software; you can redistribute it and/or
               * modify it under the terms of the GNU General Public License
               * version 2 as published by the Free Software Foundation.
               *
               *******************************
               *
               * REVISION HISTORY
               * Version 1.0 - Henrik Ekblad
               * 
               * DESCRIPTION
               * Pressure sensor example using BMP085 module  
               * http://www.mysensors.org/build/pressure
               *
               */
              
              // 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 = getConfig().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.readSealevelPressure(ALTITUDE) / 100.0;
                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;
              }
              

              Many thanks for your help.

              Best regards.
              Denis

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

              @denis91 the sketch compiles fine for me:

              Using library SPI at version 1.0 in folder: E:\ArduinoIDE\hardware\arduino\avr\libraries\SPI 
              Using library MySensors at version 2.0.0 in folder: C:\Users\Mikael\Documents\Arduino\libraries\MySensors 
              Using library Wire at version 1.0 in folder: E:\ArduinoIDE\hardware\arduino\avr\libraries\Wire 
              Using library Adafruit_BMP085 in folder: C:\Users\Mikael\Documents\Arduino\libraries\Adafruit_BMP085 (legacy)
              
              Sketch uses 22,330 bytes (72%) of program storage space. Maximum is 30,720 bytes.
              Global variables use 955 bytes (46%) of dynamic memory, leaving 1,093 bytes for local variables. Maximum is 2,048 bytes.
              

              So the problem seems to be with your installation of the Arduino IDE. Reinstalling the IDE might be the easiest option.

              1 Reply Last reply
              0
              • denis91D Offline
                denis91D Offline
                denis91
                wrote on last edited by
                #7

                OK. I left my home during this weekend but I will try monday and then I will communicate you the result :-)

                Have a nice weekend.
                Denis

                1 Reply Last reply
                0
                • tlpeterT Offline
                  tlpeterT Offline
                  tlpeter
                  wrote on last edited by
                  #8

                  I just installed my own type of weather station with a BMP180 and the 2.0 sketch works fine.
                  I think you are doing something wrong :smile:

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


                  27

                  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