Advertisement
sspence65

ESP8266 BME280

Jun 24th, 2017
6,969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.96 KB | None | 0 0
  1. /***************************************************************************
  2.   This is a library for the BME280 humidity, temperature & pressure sensor
  3.  
  4.   Designed specifically to work with the Adafruit BME280 Breakout
  5.   ----> http://www.adafruit.com/products/2650
  6.  
  7.   These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  8.   to interface. The device's I2C address is either 0x76 or 0x77.
  9.  
  10.   Adafruit invests time and resources providing this open source code,
  11.   please support Adafruit andopen-source hardware by purchasing products
  12.   from Adafruit!
  13.  
  14.   Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  15.   BSD license, all text above must be included in any redistribution
  16.  ***************************************************************************/
  17.  
  18.  
  19. // Sketch modified by Steve Spence - http://arduinotronics.blogspot.com
  20. // converted to American units and added Dew Point and Heat Index calculations
  21.  
  22.  
  23. #include <Wire.h>
  24. #include <SPI.h>
  25. #include <Adafruit_Sensor.h>
  26. #include <Adafruit_BME280.h>
  27.  
  28. #define BME_SCK 13
  29. #define BME_MISO 12
  30. #define BME_MOSI 11
  31. #define BME_CS 10
  32.  
  33. //#define BME_SDA D3
  34. //#define BME_SDL D4
  35.  
  36. #define SEALEVELPRESSURE_HPA (1013.25)
  37.  
  38. Adafruit_BME280 bme; // I2C
  39. //Adafruit_BME280 bme(BME_CS); // hardware SPI
  40. //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
  41.  
  42. unsigned long delayTime;
  43.  
  44. void setup() {
  45.     Serial.begin(9600);
  46.     Serial.println("BME280 test");
  47.  
  48.     bool status;
  49.    
  50.     // default settings
  51.     status = bme.begin();
  52.     if (!status) {
  53.         Serial.println("Could not find a valid BME280 sensor, check wiring!");
  54.         while (1);
  55.     }
  56.    
  57.     Serial.println("-- Default Test --");
  58.     delayTime = 1000;
  59.  
  60.     Serial.println();
  61.  
  62.     delay(100); // let sensor boot up
  63. }
  64.  
  65.  
  66. void loop() {
  67.     printValues();
  68.     delay(delayTime);
  69. }
  70.  
  71.  
  72. void printValues() {
  73.     Serial.print("Temperature = ");
  74.     //Serial.print(bme.readTemperature());
  75.     //Serial.println(" *C");
  76.     float fTemp = bme.readTemperature()*9.0/5.0+32;
  77.     Serial.print(fTemp);
  78.     Serial.println(" *F");
  79.    
  80.  
  81.     Serial.print("Pressure = ");
  82.  
  83.     //Serial.print(bme.readPressure() / 100.0F);
  84.     //Serial.println(" hPa");
  85.     float bPress = bme.readPressure() / 100.0F / 33.8638866667;
  86.     Serial.print(bPress);
  87.     Serial.println(" inHg");
  88.  
  89.     //Serial.print("Approx. Altitude = ");
  90.     //Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  91.     //Serial.println(" m");
  92.  
  93.     Serial.print("Humidity = ");
  94.     //Serial.print(bme.readHumidity());
  95.     float rH = bme.readHumidity();
  96.     Serial.print(rH);
  97.     Serial.println(" %");
  98.    
  99.  
  100.     Serial.print("Dew Point = ");
  101.     float dPoint = fTemp - ((100-rH)/5);
  102.     Serial.print(dPoint);
  103.     Serial.println(" *F");
  104.  
  105.  
  106.     Serial.print("Heat Index = ");
  107.     float hIndex = 0.5 * (fTemp + 61.0 + ((fTemp-68.0)*1.2) + (rH*0.094));
  108.     Serial.print(hIndex);
  109.     Serial.println(" *F");
  110.    
  111.     Serial.println();
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement