mirror of
https://github.com/adafruit/Adafruit_Sensor.git
synced 2025-08-03 09:04:26 +02:00
add mock example from bmp280
This commit is contained in:
61
examples/bmp280_sensortest/bmp280_sensortest.ino
Normal file
61
examples/bmp280_sensortest/bmp280_sensortest.ino
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
This is a library for the BMP280 humidity, temperature & pressure sensor
|
||||||
|
This example shows how to take Sensor Events instead of direct readings
|
||||||
|
|
||||||
|
Designed specifically to work with the Adafruit BMP280 Breakout
|
||||||
|
----> http://www.adafruit.com/products/2651
|
||||||
|
|
||||||
|
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
|
||||||
|
to interface.
|
||||||
|
|
||||||
|
Adafruit invests time and resources providing this open source code,
|
||||||
|
please support Adafruit andopen-source hardware by purchasing products
|
||||||
|
from Adafruit!
|
||||||
|
|
||||||
|
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
|
||||||
|
BSD license, all text above must be included in any redistribution
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
|
Adafruit_BMP280 bmp; // use I2C interface
|
||||||
|
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
||||||
|
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println(F("BMP280 Sensor event test"));
|
||||||
|
|
||||||
|
if (!bmp.begin()) {
|
||||||
|
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
|
||||||
|
while (1) delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Default settings from datasheet. */
|
||||||
|
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||||
|
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||||
|
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||||
|
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||||
|
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||||
|
|
||||||
|
bmp_temp->printSensorDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
sensors_event_t temp_event, pressure_event;
|
||||||
|
bmp_temp->getEvent(&temp_event);
|
||||||
|
bmp_pressure->getEvent(&pressure_event);
|
||||||
|
|
||||||
|
Serial.print(F("Temperature = "));
|
||||||
|
Serial.print(temp_event.temperature);
|
||||||
|
Serial.println(" *C");
|
||||||
|
|
||||||
|
Serial.print(F("Pressure = "));
|
||||||
|
Serial.print(pressure_event.pressure);
|
||||||
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
delay(2000);
|
||||||
|
}
|
Reference in New Issue
Block a user