basic code for reading pressure and temperatre sensor
This commit is contained in:
parent
7c3eaeffc4
commit
ad8b07167b
4 changed files with 40 additions and 4 deletions
1
.idea/.name
generated
1
.idea/.name
generated
|
|
@ -1 +0,0 @@
|
|||
untitled
|
||||
|
|
@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_NAME Generic)
|
|||
set(CMAKE_C_COMPILER_WORKS 1)
|
||||
set(CMAKE_CXX_COMPILER_WORKS 1)
|
||||
|
||||
project("untitled" C CXX)
|
||||
project("new_climte_go" C CXX)
|
||||
|
||||
include(CMakeListsPrivate.txt)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,3 +12,4 @@
|
|||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
lib_deps = adafruit/Adafruit BMP280 Library@^2.6.1
|
||||
|
|
|
|||
40
src/main.cpp
40
src/main.cpp
|
|
@ -1,8 +1,44 @@
|
|||
#include <Arduino.h>
|
||||
#include <Wire.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() {
|
||||
// write your initialization code here
|
||||
Serial.begin(112500);
|
||||
while ( !Serial ) delay(100); // wait for native usb
|
||||
|
||||
unsigned status;
|
||||
status = bmp.begin(0x76); //set the correct I2C port
|
||||
|
||||
//query status and reboot the board if no sensor is detected
|
||||
if (!status) {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
/* 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() {
|
||||
// write your code here
|
||||
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.print(" *C | ");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(pressure_event.pressure);
|
||||
Serial.println(" hPa");
|
||||
delay(100);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue