добавил ещё несколько примеров для I2C
This commit is contained in:
1 parent
996e316403
commit
045e4c6c78
5 files changed
+157
-3
No files matched your search
@@ -0,0 +1,50 @@
|
||||
|
||||
/*
|
||||
The BMP280 temperature and pressure sensor connected to I2C is used for this test.
|
||||
The example uses the Adafruit_BMP280 library, it must be installed first.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
Adafruit_BMP280 bmp;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while( ! Serial )
|
||||
;
|
||||
Serial.println("BMP280 run test in terminal");
|
||||
|
||||
unsigned status;
|
||||
status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
|
||||
|
||||
if (!status) {
|
||||
Serial.println("Could not find a valid BMP280 sensor!");
|
||||
while(1)
|
||||
;
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(bmp.readTemperature());
|
||||
Serial.println(" *C");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(bmp.readPressure());
|
||||
Serial.println(" Pa");
|
||||
|
||||
Serial.print(F("Approx altitude = "));
|
||||
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
|
||||
Serial.println(" m");
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
||||
Reference in new issue
Block a user