Ag xtr 16: BME280 sensor reading
Basic example that turns on, reads and turn off the sensor. Measured parameters are stored in the corresponding class variables and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 BME280 sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_16] - BME280 sensor reading --------------------
3
4
Explanation: Basic example that turns on, reads and turn off the
5
sensor. Measured parameters are stored in the corresponding class
6
variables and printed by the serial monitor.
7
8
Measured parameters:
9
- Air temperature
10
- Relative humidity
11
- Air pressure
12
13
14
Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
15
http://www.libelium.com
16
17
This program is free software: you can redistribute it and/or modify
18
it under the terms of the GNU General Public License as published by
19
the Free Software Foundation, either version 3 of the License, or
20
(at your option) any later version.
21
22
This program is distributed in the hope that it will be useful,
23
but WITHOUT ANY WARRANTY; without even the implied warranty of
24
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
GNU General Public License for more details.
26
27
You should have received a copy of the GNU General Public License
28
along with this program. If not, see .
29
30
Version: 3.1
31
Design: David Gascón
32
Implementation: J.Siscart, V.Boria
33
*/
34
35
#include <WaspSensorXtr.h>
36
37
/*
38
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
39
40
Possible sockets for this sensor are:
41
- XTR_SOCKET_A _________
42
- XTR_SOCKET_D |---------|
43
| A B C |
44
|_D__E__F_|
45
46
47
Example: a 5TM sensor on socket A will be
48
[Sensor Class] [Sensor Name] [Selected socket]
49
Decagon_5TM mySensor (XTR_SOCKET_A);
50
51
Refer to the technical guide for information about possible combinations.
52
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
53
*/
54
55
// [Sensor Class] [Sensor Name] [Selected socket]
56
bme mySensor(XTR_SOCKET_A);
57
58
void setup()
59
{
60
USB.println(F("BME280 example"));
61
62
63
}
64
65
void loop()
66
{
67
// 1. Turn ON the sensor
68
mySensor.ON();
69
70
// 2. Read the sensor. Store parameters in local variables
71
float temperature = mySensor.getTemperature();
72
float humidity = mySensor.getHumidity();
73
float pressure = mySensor.getPressure();
74
75
// 3. Turn off the sensor
76
mySensor.OFF();
77
78
// 4. Print information
79
USB.println(F("---------------------------"));
80
USB.println(F("BME280"));
81
USB.print(F("Air temperature: "));
82
USB.printFloat(temperature, 2);
83
USB.println(F(" degrees Celsius"));
84
USB.print(F("Relative Humidity: "));
85
USB.printFloat(humidity, 1);
86
USB.println(F(" %RH"));
87
USB.print(F("Air pressure: "));
88
USB.printFloat(pressure, 2);
89
USB.println(F(" Pa"));
90
USB.println(F("---------------------------\n"));
91
92
delay(5000);
93
94
}
Copied!

Output

1
H#
2
BME280 example
3
---------------------------
4
BME280
5
Air temperature: 26.02 degrees Celsius
6
Relative Humidity: 45.1 %RH
7
Air pressure: 98940.89 Pa
8
---------------------------
9
---------------------------
10
BME280
11
Air temperature: 26.02 degrees Celsius
12
Relative Humidity: 44.6 %RH
13
Air pressure: 98942.52 Pa
14
---------------------------
Copied!
Last modified 1yr ago