Created
June 9, 2017 15:28
-
-
Save jdieg0/f297627497c1f151df4fe3ad8f9e2966 to your computer and use it in GitHub Desktop.
Codebeispiel für die Luftdruckbestimmung mit dem BMP180-Shield für den Wemos D1 Mini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BMP085_U.h> | |
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); | |
void setup() { | |
// Serielle Kommunikation initialisieren | |
Serial.begin(9600); | |
Serial.println("\r\n\r\nDrucksensor BMP180\r\n"); | |
// Sensor initialisieren | |
if(!bmp.begin()) { | |
Serial.println("BMP180 nicht gefunden"); | |
while(1) { | |
delay(1000); | |
} | |
} | |
} | |
void loop() { | |
// Neues Sensor-Event | |
sensors_event_t event; | |
bmp.getEvent(&event); | |
// Messdaten anzeigen | |
if (event.pressure) { | |
// Druck in hPa anzeigen | |
Serial.print("Druck: "); | |
Serial.print(event.pressure); | |
Serial.print(" hPa"); | |
// Temperatur in °C anzeigen | |
float temperature; | |
bmp.getTemperature(&temperature); | |
Serial.print(", Temperatur: "); | |
Serial.print(temperature); | |
Serial.println(" *C"); | |
// Höhe in m anzeigen | |
// Für bessere Resultate sollte SENSORS_PRESSURE_SEALEVELHPA mit dem aktuellen Druck auf Meereshöhe der nächstgelegenen Wetterstation ersetzt werden | |
/* | |
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; | |
Serial.print("Höhe: "); | |
Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure, temperature)); | |
Serial.println(" m"); | |
*/ | |
} | |
else { | |
Serial.println("Sensor-Fehler"); | |
} | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment