OLED only receiving data when serial monitor started

I've been using the u8g2 library to to send sensor data to a 128x64 OLED. It works great but only after I start the serial monitor.

Is there something I can put in the setup to initiate this when I don't have it plugged into a computer?

I've included some basic Hello World code below. For example, if I go through and modify it to Hello Jupiter, it will upload to the Arduino but it won't be sent to the OLED until after I open the serial monitor. This would be fine but I need the device to work even when it's not plugged into the computer.

Thanks!

#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE);

void setup() {

  Serial.begin(115200);
  while (!Serial)
  delay(100);

  u8g2.begin();  
  delay(50);

}

void loop() {

  u8g2.clearBuffer();          // clear internal memory
  u8g2.setFont(u8g2_font_helvB08_tr );
  
  u8g2.drawStr(0,10,"Hello World");

  u8g2.sendBuffer();          // transfer internal memory to the display

}

Hi,
Please post your code and we can see what is happening?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Forgot all about it haha... Just included it all.

Hi,
What Arduino controller are you using?
Also this;

 while (!Serial)

comment it out and see what happens, its waiting for serial to connect before going on.

// while (!Serial)

Tom.. :smiley: :+1: :coffee: :australia:

Okay that was exactly the problem. I did not realize this.

It's a Teensy.

Thank you! You saved me a lot of time and headache. Great forum and great posters!

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