Uno with BME280 and OLED 1106: Loop stops when using bme.readPressure

Hello,
for a portable wheather station i use UNO + BME280 + OLED 1106 compatible.
Everything works fine when Pressure is not read. When reading Pressure, Display is off or loop stops after first read.

Message from Upload:
Der Sketch verwendet 17498 Bytes (54%) des Programmspeicherplatzes. Das Maximum sind 32256 Bytes.
Globale Variablen verwenden 831 Bytes (40%) des dynamischen Speichers, 1217 Bytes für lokale Variablen verbleiben. Das Maximum sind 2048 Bytes.

Sketch uploaded

Any Suggestion ? Thanks.
gs_adafruit1106_bme280.ino (4,0 KB)

Your attached file is down loaded but is not opened in my IDE 2.0.0. Please, post the codes online in this thread. Are you the following 5V-I2C BME280 Breakout Board?
BME280I2CPic

Hi Mostafa, thanks for your quick reply.
Yes, i am using this breakout board.

Testing with Serial.println alone works fine.

Here my sketch:

/*********************************************************************
  This is an example for our Monochrome OLEDs based on SH110X drivers

  This example is for a 128x64 size display using I2C to communicate
  3 pins are required to interface (2 I2C and one reset)

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada  for Adafruit Industries.
  BSD license, check license.txt for more information
  All text above, and the splash screen must be included in any redistribution

  i2c SH1106 modified by Rupert Hirst  12/09/21
*********************************************************************/

//#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
//#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

Adafruit_BME280 bme; // I2C

/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's

#define SCREEN_WIDTH 128 // OLED width in pixels
#define SCREEN_HEIGHT 64 // OLED height in pixels
#define OLED_RESET -1    // QT-PY / XIAO ??

Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup()   {
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  
  // Ausblenden Splashscreen ( Adafruit-Logo )
  // SH110X_NO_SPLASH gesetzt in Adafruit_SH110X.h

  delay(250); // wait for the OLED to power up
  display.begin(i2c_Address, true); // Address 0x3C default
  //display.setContrast (0); // dim display
 
  display.display();

  // Clear the buffer.
  display.clearDisplay();

  display.display();
  Serial.begin(9600);

  bool communication = bme.begin(0x76);
  if (!communication) {
      Serial.println("Could not find a valid BME280 sensor");
      Serial.println("check wiring, address, sensor ID!");
      Serial.print("SensorID was: 0x");
      Serial.println(bme.sensorID(), 16);
      Serial.println("ID of 0xFF probably means a bad address\n");
      while (true) { };
      delay(10);
  } else {
      Serial.println("Communication established!\n");
  }
}


void loop() {
    display.clearDisplay();
  // Variables for Temp and Humidity
  float         Temp       = 0;    // Temperature
  float         Humid      = 0;    // Humidity
  float         Druck      = 0;    // Pressure
  
 
  // MEASURE Temp, Humid, Druck
  //Druck = bme.readPressure();
  //Druck = Druck / 100.0F;
  // ABOVE NOT WORKING 
  
  Temp = bme.readTemperature();
  Humid = bme.readHumidity();
  
  Serial.println(Temp);
  Serial.println(Humid);
  Serial.println(Druck);
  //delay(250);
  //display.clearDisplay();

  // Rahmen
  display.drawRect(0, 0, display.width(), display.height(), SH110X_WHITE);
  display.drawRect(0, 0, display.width(), 12, SH110X_WHITE);
  display.setTextSize(0);
  display.setTextColor(SH110X_WHITE);

  // Überschrift
  display.setCursor(5, 2);
  display.print(F("Barometer @ G.Schmid"));
  
  // Display Temp
  display.setCursor(5, 14);
  display.print(F("Temperatur       C"));
  display.setCursor(75, 14);
  display.print(Temp, 2);

  // Display Humidity
  display.setCursor(5, 24);
  display.print(F("Luftfeuchte      %"));
  display.setCursor(75, 24);
  display.print(Humid, 2);
  
  // Display Pressure
  display.setCursor(5, 34);
  display.print(F("Luftdruck        hPa"));
  display.setCursor(65, 34);
  display.print(Druck, 1);
  
  // Display Trend ( TODO rising / falling
  display.setCursor(5, 44);
  display.print(F("Tendenz"));
  display.setCursor(67, 44);
  display.print("steigend");

  // Update screen
  display.display();
  delay(1000);
}

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

The following sketch works well for my 128x32 OLED and I2CBME280 setup. Try it in your setup and report the result.

#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>//#include <Adafruit_SSD130X.h>

Adafruit_BME280 bme; // I2C

#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define SCREEN_WIDTH 128 // OLED width in pixels
#define SCREEN_HEIGHT 32 // OLED height in pixels
#define OLED_RESET -1    // 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

float         Temp       = 0;    // Temperature
float         Humid      = 0;    // Humidity

void setup()
{
  Serial.begin(9600);

  bool communication = bme.begin(0x76);
  if (communication)
  {
    Serial.println("BME280 is found.");
  }
  else
  {
        while(1);  //wait for ever
  }
  //----------------------------------

  if (display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
  {
    Serial.println("SSD1306 is found.");
  }
  else
  {
        while(1);  //wait for ever
  }

  display.display();
  delay(2000); // Pause for 2 seconds

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
}


void loop()
{
  Temp = bme.readTemperature();
  Humid = bme.readHumidity();

  Serial.print("Temperature: ");
  Serial.print(Temp); Serial.println(" degC");

  Serial.print("Humidity: ");
  Serial.print(Humid); Serial.println(" %");
  Serial.println("=========================================");
  /-----------------------------------------------------
  display.clearDisplay();
  display.display();
  //--------------------------
  display.setCursor(5, 8);
  display.print("Temp: ");
  display.print(Temp, 2); display.println(" degC");
  //-------------------------
  display.setCursor(5, 20);  //x, y
  display.print("Humi: ");
  display.print(Humid, 2); display.println(" %");
  //---------------------------
  display.display();
  delay(2000);//2-sec refreshing is ok to avoid ghost characters
}

hi Mostafa,

i found a hint in the forum: you must not use serial.print within I2C configurations,
because I2c and serial both use interrupts and so get in conflict.

Thanks for your Efforts !

I deleted all "serial"-Commands and now my Sketch works perfect !
Your sketch falied also when reading pressure ...

Problem solved.

My sketch of post #5 does not measure pressure; then how can it fail?

Hi, Mostafa,

thats right, I added bme.readPressure , and got the same behavior.

Is it possible, to search members in the arduino forum ?.

I think, you are quite experienced and I would like to look at your other contribs.

BTW:
Today I found a nice and best documented solution for „Trending“ barometric pressure.
I will try to integrate it ( without LEDs, Switches etc, just indicate „rising“ or „falling".

https://forum.arduino.cc/t/barometer-project/935657

About me:
I am a retired ( aged 69 ) software developer for xtcommerce online shops ( but still working a little in this context )
and interested in electronics since my childhood :slight_smile:

Yours sincerely,

It:logistik Günther Schmid
Am Steinbruch 1
85131 Pollenfeld / Wachenzell

Tel.: +49 8423 985461
Mobil: +49 151 15797719‬
info@gs-hp.de
www.gs-hp.de

Click Golam's name and then his name again. Or right click and open in new tab.

THX, this forum is fantastic !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.