|
[mw_shl_code=arduino,true]/*
【Arduino】37种传感器模块系列实验(27)
实验二十七:GY-BMP280-3.3 高精度大气压强传感器模块(高度与温度计)
*/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 测试"));
if (!bmp.begin()) {
Serial.println(F("找不到对应的传感器"));
while (1);
}
}
void loop() {
Serial.print(F("温度 = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("气压 = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("海拔 = "));
Serial.print(bmp.readAltitude(1013.25));
Serial.println(" m");
Serial.println();
delay(2000);
}
[/mw_shl_code]
|
|