Serial.print & oled.print

Been attempting to write a function that takes Serial.print and also push it to the OLED (standard 0.96", 128x64, 4-pin). I've tried about everything, but can not get things working for some reason. Can someone point me in the right direction?

It will print "inside void setup" to the oled, so the connection works, but calling the serialOLED function doesn't seem to do anything. The serial will print "Serial test print", but ends there.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#define OLED_RESET -1 // no reset button
Adafruit_SSD1306 oledDisplay(OLED_RESET);

void oledStart() {
  oledDisplay.fillScreen(SSD1306_BLACK);
  oledDisplay.setTextSize(1);
  oledDisplay.setTextColor(WHITE);
  oledDisplay.setCursor(0, 0);
}
void oledEnd() {
  oledDisplay.display();
  delay(2000);
  oledDisplay.clearDisplay();
}
void serialOLED(const char* string) {
  if (!Serial) {
    while (!Serial) {
      ;
    }
  }
  if (Serial.available() > 0) {
    oledStart();
    char data = Serial.read();
    Serial.println(data);
    oledDisplay.println(data);
    oledEnd(); 
  }
}
void setup() {
  Serial.begin(115200);
  delay(1000);
  oledDisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oledStart();
  oledDisplay.print("inside void setup");
  oledEnd();
}
void loop() {
  delay(2000);  // allows serialOLED to catch up
  serialOLED("oled test print");
  Serial.print(F("Serial test print"));
  serialOLED("Many other calls");
}

I don't understand this.
Why not simply

while (! Serial );

?
Some debug prints might help you...

I've read a few places that recommended to use an if instead of a while loop. I honestly can't remember the reason, but figured this should skirt the issue.

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