Development

» GP v30 05 – Temperature, humidity and pressure sensor

This is the basic code to manage and read the temperature, humidity and pressure sensor.

Required Materials

1 x Waspmote
1 x Battery
1 x Gases PRO board v30
1 x Temperature, Humidity and Pressure sensor BME280

Notes

- Remember to connect the battery to Waspmote for proper operation.
- The connection of the sensor is described in the Gases PRO v30 technical guide.
- Cycle time: 3 minutes

Code

/*
    -------  [GP_v30_05] - Temperature, humidity and pressure sensor  ---------

    Explanation: This is the basic code to manage and read the temperature,
    humidity and pressure sensor. Cycle time: 3 minutes

    Copyright (C) 2017 Libelium Comunicaciones Distribuidas S.L.
    http://www.libelium.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Version:           3.1
    Design:            David Gascón
    Implementation:    Alejandro Gállego
*/

#include <WaspSensorGas_Pro.h>
#include <BME280.h>

float temperature;	// Stores the temperature in ºC
float humidity;		// Stores the realitve humidity in %RH
float pressure;		// Stores the pressure in Pa


void setup()
{
  USB.println(F("Temperature, humidity and pressure sensor example"));
  // Configures the I2C isolator
  pinMode(GP_I2C_MAIN_EN, OUTPUT);
}


void loop()
{
  ///////////////////////////////////////////
  // 1. Turn on the sensor
  ///////////////////////////////////////////

  // Enable the communication with the board
  digitalWrite(GP_I2C_MAIN_EN, HIGH);
  // Power on the temperature, humidity and pressure sensor.
  BME.ON();


  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////

  // Read enviromental variables
  temperature = BME.getTemperature(BME280_OVERSAMP_16X, BME280_FILTER_COEFF_OFF);
  humidity = BME.getHumidity(BME280_OVERSAMP_16X);
  pressure = BME.getPressure(BME280_OVERSAMP_16X, BME280_FILTER_COEFF_OFF);

  // Disaable the communication with the board
  digitalWrite(GP_I2C_MAIN_EN, LOW);

  // And print the values via USB
  USB.println(F("***************************************"));
  USB.print(F("Temperature: "));
  USB.print(temperature);
  USB.println(F(" Celsius degrees"));
  USB.print(F("RH: "));
  USB.print(humidity);
  USB.println(F(" %"));
  USB.print(F("Pressure: "));
  USB.print(pressure);
  USB.println(F(" Pa"));


  ///////////////////////////////////////////
  // 3. Sleep
  ///////////////////////////////////////////

  // Go to deepsleep
  // After 3 minutes, Waspmote wakes up thanks to the RTC Alarm
  PWR.deepSleep("00:00:03:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

}

Output

H#
Temperature, humidity and pressure sensor example
***************************************
Temperature: 24.2600002288 Celsius degrees
RH: 43.1982421875 %
Pressure: 99752.3593750000 Pa
***************************************
Temperature: 24.3199996948 Celsius degrees
RH: 43.1914062500 %
Pressure: 99750.8281250000 Pa
***************************************
Temperature: 24.3400001525 Celsius degrees
RH: 43.1826171875 %
Pressure: 99748.4531250000 Pa
***************************************
Temperature: 24.3500003814 Celsius degrees
RH: 43.1728515625 %
Pressure: 99751.2343750000 Pa

Quick Publish: