Development

» Ga v30 01: BME280 sensor

This example read the temperature, humidity and pressure values from BME280 sensor

Required Materials

1 x Waspmote
1 x Battery
1 x MiniUSB wire
1 x Gases Board v30
1 x BME sensor

Notes

- This example is valid only for Waspmote v15

Code

/*
 *   ------------  [Ga_v30_01] - Temperature, Humidty and Pressure  --------------
 *
 *   Explanation: This example read the temperature, humidity and
 *   pressure values from BME280 sensor
 *
 *   Copyright (C) 2016 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.0
 *   Design:            David Gascón
 *   Implementation:    Ahmad Saad
*/

// Library include
#include <WaspSensorGas_v30.h>
#include <WaspFrame.h>

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

char node_ID[] = "BME280_example";

void setup()
{
  USB.ON();
  USB.println(F("Temperature, Humidity an Pressure example"));
  // Set the Waspmote ID
  frame.setID(node_ID);  
  
  ///////////////////////////////////////////
  // 1. Turn on the board
  /////////////////////////////////////////// 
  
  // Switch ON and configure the Gases Board
  Gases.ON();
  delay(100);   
}

void loop()
{
  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////  

  // Read enviromental variables
  temperature = Gases.getTemperature();
  humidity = Gases.getHumidity();
  pressure = Gases.getPressure();

  // Print of the results
  USB.print(F("Temperature: "));
  USB.print(temperature);
  USB.print(F(" Celsius Degrees |"));
  
  USB.print(F(" Humidity : "));
  USB.print(humidity);
  USB.print(F(" %RH"));

  USB.print(F(" Pressure : "));
  USB.print(pressure);
  USB.print(F(" Pa"));

  USB.println();
  
  ///////////////////////////////////////////
  // 3. Create ASCII frame
  ///////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII, node_ID);
  // Add temperature
  frame.addSensor(SENSOR_GASES_TC, temperature);
  // Add humidity
  frame.addSensor(SENSOR_GASES_HUM, humidity);
  // Add pressure
  frame.addSensor(SENSOR_GASES_PRES, pressure);	
  // Show the frame
  frame.showFrame();
  
  delay(3000);
}

Output

H#
Temperature, Humidity an Pressure example
Temperature: 25.27 Celsius Degrees | Humidity : 41.25 %RH Pressure : 99621.85 Pa
===============================
Current ASCII Frame:
Length: 78
Frame Type: 134
frame (HEX): 3C3D3E8603233431313837303633443933373432463423424D453238305F6578616D706C6523302354433A32352E32372348554D3A34312E323523505245533A39393632312E383523
frame (STR): <=>�#41187063D93742F4#BME280_example#0#TC:25.27#HUM:41.25#PRES:99621.85#
===============================
Temperature: 25.36 Celsius Degrees | Humidity : 43.64 %RH Pressure : 99621.14 Pa
===============================
Current ASCII Frame:
Length: 78
Frame Type: 134
frame (HEX): 3C3D3E8603233431313837303633443933373432463423424D453238305F6578616D706C6523302354433A32352E33362348554D3A34332E363423505245533A39393632312E313423
frame (STR): <=>�#41187063D93742F4#BME280_example#0#TC:25.36#HUM:43.64#PRES:99621.14#
===============================
Temperature: 25.59 Celsius Degrees | Humidity : 42.58 %RH Pressure : 99622.13 Pa
===============================
Current ASCII Frame:
Length: 78
Frame Type: 134
frame (HEX): 3C3D3E8603233431313837303633443933373432463423424D453238305F6578616D706C6523302354433A32352E35392348554D3A34322E353823505245533A39393632322E313323
frame (STR): <=>�#41187063D93742F4#BME280_example#0#TC:25.59#HUM:42.58#PRES:99622.13#
===============================
...

Quick Publish: