MQCalibration was not declared in this scope, what`s wrong?



  •  * 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
     * Example sketch showing how to measue light level using a LM393 photo-resistor
     * http://www.mysensors.org/build/light
     */
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_GATEWAY_SERIAL
    //#define MY_RADIO_RFM69
    #include <MySensors.h>
    
    #define CHILD_ID_LIGHT 0
    #define LIGHT_SENSOR_ANALOG_PIN 0
    
    #define CHILD_ID_MQ 1
    #define MQ_SENSOR_ANALOG_PIN 1 //define which analog input channel you are going to use
    
    #define         RL_VALUE                     (5)     //define the load resistance on the board, in kilo ohms
    #define         RO_CLEAN_AIR_FACTOR          (9.83)  //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO,
    //which is derived from the chart in datasheet
    /***********************Software Related Macros************************************/
    #define         CALIBARAION_SAMPLE_TIMES     (50)    //define how many samples you are going to take in the calibration phase
    #define         CALIBRATION_SAMPLE_INTERVAL  (500)   //define the time interal(in milisecond) between each samples in the
    //cablibration phase
    #define         READ_SAMPLE_INTERVAL         (50)    //define how many samples you are going to take in normal operation
    #define         READ_SAMPLE_TIMES            (5)     //define the time interal(in milisecond) between each samples in
    //normal operation
    /**********************Application Related Macros**********************************/
    #define         GAS_LPG                      (0)
    #define         GAS_CO                       (1)
    #define         GAS_SMOKE                    (2)
    /*****************************Globals***********************************************/
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    //VARIABLES
    int lastLightLevel;
    float Ro = 10000.0;    // this has to be tuned 10K Ohm
    int val = 0;           // variable to store the value coming from the sensor
    float valMQ =0.0;
    float lastMQ =0.0;
    float           LPGCurve[3]  =  {2.3,0.21,-0.47};   //two points are taken from the curve.
    //with these two points, a line is formed which is "approximately equivalent"
    //to the original curve.
    //data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59)
    float           COCurve[3]  =  {2.3,0.72,-0.34};    //two points are taken from the curve.
    //with these two points, a line is formed which is "approximately equivalent"
    //to the original curve.
    //data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000,  0.15)
    float           SmokeCurve[3] = {2.3,0.53,-0.44};   //two points are taken from the curve.
    //with these two points, a line is formed which is "approximately equivalent"
    //to the original curve.
    //data format:{ x, y, slope}; point1: (lg200, 0.53), point2:(lg10000,-0.22)
    //unsigned long SLEEP_TIME = 30000; 
    MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    MyMessage msgMQ(CHILD_ID_MQ, V_LEVEL);
    
    
    void setup()
    {
      Ro=MQCalibration(MQ_SENSOR_ANALOG_PIN);         //Calibrating the sensor. Please make sure the sensor is in clean air
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Light Sensor+GaS_Smoke_MQ2", "1.0");
    
    	// Register all sensors to gateway (they will be created as child devices)
    	present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
       //sendSketchInfo("Air Quality Sensor", "1.0");
    
     // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_MQ, S_AIR_QUALITY);
    }
    void loop()
    {
    	int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
    	Serial.println(lightLevel);
    	if (lightLevel != lastLightLevel) {
    		send(msgLight.set(lightLevel));
    		lastLightLevel = lightLevel;
    	}
      uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO);
      Serial.println(val);
    
      Serial.print("LPG:");
      Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_LPG) );
      Serial.print( "ppm" );
      Serial.print("    ");
      Serial.print("CO:");
      Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO) );
      Serial.print( "ppm" );
      Serial.print("    ");
      Serial.print("SMOKE:");
      Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_SMOKE) );
      Serial.print( "ppm" );
      Serial.print("\n");
    
      if (valMQ != lastMQ) {
        send(msgLight.set((int16_t)ceil(valMQ)));
        lastMQ = ceil(valMQ);
      }
    
      sleep(SLEEP_TIME); //sleep for: sleepTime
    }
    

    /home/pi/Desktop/MyScratches/LightSensor/LightSensor.ino: In function 'void setup()':
    LightSensor:84: error: 'MQCalibration' was not declared in this scope
    Ro=MQCalibration(MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air
    ^
    /home/pi/Desktop/MyScratches/LightSensor/LightSensor.ino: In function 'void loop()':
    LightSensor:107: error: 'MQRead' was not declared in this scope
    uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO);
    ^
    LightSensor:107: error: 'MQGetGasPercentage' was not declared in this scope
    uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO);
    ^
    exit status 1
    'MQCalibration' was not declared in this scope

    What wrong?


  • Mod

    @asmman welcome to the MySensors community.

    Looks like you are trying to use this sketch, but only included some parts of the code?

    Side note: Please use the code button when including code in a forum post. This makes the code much easier to read. The code button looks like this: </>



  • Thanks for the tip about inserting the code, sorry! In this example I used two scratch specified and Light Sensor, in order to use the smoke sensor and light sensor in one gateway. Individually, these scratching are working properly and the WTO combine of together does not work, error appears. Thank you for understanding!

    see here: sendSketchInfo("Light Sensor+GaS_Smoke_MQ2", "1.0");


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.