Help with OLED not working as intended

Basically, when I start-up the Arduino my OLED shows "Welcome" as intended and also shows 'Temperature' as intended but then after a few seconds it loops. Something even stranger is it only loops once and then goes back to normal.
This is my code so far, ignore the incomplete loop part as that is for later:

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int tempPin = A0;
int rawValue = 0;

void setup() {
  // put your setup code here, to run once:
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(10,16);
  display.println("Welcome");
  display.display();
  delay(1000);
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setCursor(16, 0);
  display.println("Temperature:");
  display.display();

}

void loop() {
  // put your main code here, to run repeatedly:
  rawValue = analogRead(tempPin);
  float voltage = rawValue * (5 / 1023.0);
  float tempC = (voltage - 0.5) * 100;

}

What do you mean by "it loops" ? reboots ?

I mean the display just shows the thing again.

Are the pins for your OLED and Arduino (?Uno R3?) soldered? If so, show a picture of the soldering and wiring. If not, solder them.

Use descriptive words.

the headers are pre soldered, by the way it is i2c

Your code is solid. The issue is not the code.

(but no update in temperature is coded to be displayed)

ok, it must be the code though because the unit is brand new and this is the first project I will use it for

So is the code (new). The problem is not the code you posted.

I don't know what "the thing" means.

What, exactly, is displayed. What words, what timings.

The thing displayed is 'Welcome' then it waits 1 second and then clears the screen and writes 'Temperature:'

Which is exactly what the code has been asked to do. Display "Welcome" for 1 second, then display "Temperature".

It's like pulling teeth here...

  // add these lines at the end of loop()
  display.setCursor(16, 0);
  display.print("Temperature:");
  display.setCursor(16, 10);
  display.print(tempC);
  display.display();
  delay(500);
  display.clearDisplay();
1 Like

What do you think should happen next vis-a-vis the display?

Which arduino are you using?
How is it powered ?

It seems to reboot, so that's likely a power or some sort of hardware issue.

@xfpd your code worked

1 Like

Do you understand why the original code did not work as you expected, and why the additional code sort-of did what you wanted?

Now to explore... to find all the fun stuff you can do with your OLED, search for the library you are using Adafruit_SSD1306.h

which will give you this link: GitHub - adafruit/Adafruit_SSD1306: Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs

then, click on the Adafruit_SSD1306.cpp file, which will give you this link: Adafruit_SSD1306/Adafruit_SSD1306.cpp at master · adafruit/Adafruit_SSD1306 · GitHub

On the right-hand side of the screen is a list of functions you can use from that library.

Do the same for Adafruit_GFX.h to get this: Adafruit-GFX-Library/Adafruit_GFX.cpp at master · adafruit/Adafruit-GFX-Library · GitHub (this is the graphics library for your OLED)

1 Like