Guest User

Untitled

a guest
Feb 17th, 2019
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <U8g2lib.h>
  2. #include "src/cactus_io_BME280_I2C.h"
  3. #include <Wire.h>
  4.  
  5. U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ 16);
  6.  
  7. BME280_I2C bme(0x76);
  8.  
  9. TwoWire I2Cone = TwoWire();
  10. TwoWire I2Ctwo = TwoWire();
  11.  
  12. void setup(void) {
  13.   Serial.begin(9600);
  14.   I2Cone.begin(4, 5);
  15.   I2Ctwo.begin(12, 13);
  16.  
  17.   Serial.println("Bosch BME280 Pressure - Humidity - Temp Sensor | cactus.io");
  18.  
  19.   if (!bme.begin()) {
  20.     Serial.println("Could not find a valid BME280 sensor, check wiring!");
  21.     while (1);
  22.  
  23.     Serial.println("Pressure\tHumdity\t\tTemp\ttTemp");
  24.  
  25.   }
  26.  
  27.   u8g2.begin();
  28. }
  29.  
  30. void loop(void) {
  31.  
  32.   bme.readSensor();
  33.  
  34.   Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Pressure in millibars
  35.   Serial.print(bme.getHumidity()); Serial.print(" %\t\t");
  36.   Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
  37.   Serial.print(bme.getTemperature_F()); Serial.println(" *F");
  38.  
  39.   do {
  40.     u8g2.setFont(u8g2_font_logisoso32_tf);
  41.  
  42.     u8g2.drawStr(0, 32, "T:");
  43.  
  44.     u8g2.setCursor(18, 32);
  45.     u8g2.print(bme.getTemperature_C(), 0);
  46.  
  47.     u8g2.drawStr(64, 32, "H:");
  48.  
  49.     u8g2.setCursor(84, 32);
  50.     u8g2.print(bme.getHumidity(), 0);
  51.  
  52.   } while ( u8g2.nextPage() );
  53.   delay(2000);
  54. }
RAW Paste Data