128x32 oled ssd1306 pixels

Here is a really short video describing my problem:

The display only works when the serial monitor is started.

Video has sound.

Code is attached:

Any help would be greatly appreciated

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define SSD1306_I2C_ADDRESS 0x3C

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     3 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme; // I2C

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

 //TempOffset = -15.1
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.setTextColor(WHITE);
 display.clearDisplay();
 //display.display();

 while (!Serial);
 Serial.println(F("BME680 async test"));

 if (!bme.begin()) {
   Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
   while (1);
 }

 // Set up oversampling and filter initialization
 bme.setTemperatureOversampling(BME680_OS_8X);
 bme.setHumidityOversampling(BME680_OS_2X);
 bme.setPressureOversampling(BME680_OS_4X);
 bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
 bme.setGasHeater(320, 150); // 320*C for 150 ms
}

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

 
  // Tell BME680 to begin measurement.
 unsigned long endTime = bme.beginReading();
 if (endTime == 0) {
   Serial.println(F("Failed to begin reading :("));
   return;
 }
 //Serial.print(F("Reading started at "));
 //Serial.print(millis());
 //Serial.print(F(" and will finish at "));
 //Serial.println(endTime);

 //Serial.println(F("You can do other work during BME680 measurement."));
 delay(50); // This represents parallel work.
 // There's no need to delay() until millis() >= endTime: bme.endReading()
 // takes care of that. It's okay for parallel work to take longer than
 // BME680's measurement time.

 // Obtain measurement results from BME680. Note that this operation isn't
 // instantaneous even if milli() >= endTime due to I2C/SPI latency.
 if (!bme.endReading()) {
   Serial.println(F("Failed to complete reading :("));
   return;
 }
 //Serial.print(F("Reading completed at "));
 //Serial.println(millis());
 //display.setTextSize(4);
 //display.setCursor(6, 5);  // column and row position
 
 Serial.print(F("Temperature = "));
 Serial.print(bme.temperature);
 Serial.println(F(" *C"));
 Serial.print((bme.temperature * 1.8) + 32);
 Serial.println(F(" *F"));

 Serial.print(F("Pressure = "));
 Serial.print(bme.pressure / 100.0);
 Serial.println(F(" hPa"));

 Serial.print(F("Humidity = "));
 Serial.print(bme.humidity);
 Serial.println(F(" %"));

 Serial.print(F("Gas = "));
 Serial.print(bme.gas_resistance / 1000.0);
 Serial.println(F(" KOhms"));

 Serial.print(F("Approx. Altitude = "));
 Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)* 3.2808);
 Serial.println(F(" feet"));

 Serial.println();

   display.display();
 
 float TempOffSet = 7.39;
 float temp = (bme.temperature - TempOffSet);
 display.clearDisplay();
 display.setTextSize(1);w
 display.setCursor(0,0);
 display.print(F("Temp "));
 display.print(((temp * 1.8) + 32), 1);
 display.print(F(" F  "));
 display.print(temp, 1);
 display.print(F(" C"));
 
 display.setCursor(0,8);
 display.print(F("Hum  "));
 display.print(bme.humidity, 1);
 display.print(F(" % "));
 display.print(F("Gas "));
 display.print((bme.gas_resistance / 1000.0), 0);
 display.print(F("K"));

 display.setCursor(0,16);
 display.print(F("Baro "));
 display.print((bme.pressure / 100.0)*.02953);
 display.print(F(" inHg "));
 display.print((bme.pressure / 100.0), 1);

 display.setCursor(0,25);
 display.print(F("Alt  "));
 display.print((bme.readAltitude(SEALEVELPRESSURE_HPA)* 3.2808), 0);
 display.print(F(" ft"));
 

 display.display();
 
}

Well, it is pretty obvious. You have not put the code inside a Code Window e.g. with the </> icon.

Actually, the problem is that you have commented out several lines e.g.

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.clearDisplay();
  //display.display();  //.kbv you have not sent the buffer to the OLED

David.

I put that there just for testing. If I un comment it it doesn’t work at all

Go on. Start with the library examples. Modify to suit your project.

There are several other “unwise” statements:

#define OLED_RESET     0 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

digital #0 is the Serial RXD pin.

Please edit your Original Post. Select the code statements. Click the </> icon.

David.

so i changed the pin # and it didn't do anything im not using the reset currently. should i be?

i got it figured out a discord member pointed out, it was stuck at the line below:

i commented this out and it worked as should, thank you for the input.

 while (!Serial);

Thanks for editing.

I still recommend starting with example. Make small changes.

Follow the usual plan i.e. initialise in setup(). main repeated flow sequence in loop()

No one wants to pick holes in every bit of your posted code. Follow the conventional style and I guarantee you will have a happier life.

Regarding RESET. If there is no Reset pin, follow the advice. i.e. use -1 for the argument.

Regarding !Serial. Some Arduino boards will ignore e.g. with external USB-UART chips. Arduinos with USB Serial like Due Native port will wait for you to open a Serial Terminal.

Regarding Serial.begin(). This should only be in setup()

David.