WeMos (b4) I2C (BMP180+OLED)

先日OLEDの文字表示できたが、今度 I2Cに (BMP180+OLED)両方を繋いで、センサーデータの表示を試み

プログラム

/*
 * 
 */
#include <Wire.h> 
#include <Adafruit_BMP085.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define OLED_RESET 0  // GPIO0
Adafruit_SSD1306 OLED(OLED_RESET);

Adafruit_BMP085 bmp;

void setup()
{
  OLED.begin();
  OLED.clearDisplay();
 
  //Add stuff into the 'display buffer'
  OLED.setTextWrap(false);
  OLED.setTextSize(1);
  OLED.setTextColor(WHITE);
  OLED.setCursor(0,0);
  OLED.println("automatedhome.party");
 
  OLED.display(); //output 'display buffer' to screen  
  // OLED.startscrollleft(0x00, 0x0F); //make display scroll 

  if (!bmp.begin()) 
  {
    Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
    while (1) {}
  }
}

void loop()
{

  OLED.clearDisplay();
  OLED.setCursor(0,0);
  OLED.print("Temp = ");
  OLED.print(bmp.readTemperature());
  OLED.println(" Celsius");
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  OLED.setCursor(0,8);
  OLED.print("Pres = ");
  OLED.print(bmp.readPressure());
  OLED.println(" Pascal ");
  // print the number of seconds since reset:
  OLED.setCursor(0,16);
  OLED.print(millis() / 1000);
  OLED.display(); //output 'display buffer' to screen  
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *