Arduino's OLED screen cycles through the image every so often

By using the Adafruit_SSD1306 and Adafruit_SSD1306 libraries. The code is uploaded correctly but the oled image is sometimes displaced as seen in the image.
animation
Code:

#include <Adafruit_GFX.h> 
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     0 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

/****************************************
*Funciones principales
****************************************/
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay(); 
mlx.begin();  
}
void loop()
{
Oled_mlx(); //Función para la oled y el sensor 
}

void Oled_mlx() {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("T_Ambiente");
display.print("   ");
display.println(mlx.readAmbientTempC()); //mlx.readAmbientTempF()
display.println("T_Objeto");
display.print("   ");
display.println(mlx.readObjectTempC()); //mlx.readObjectTempF()
display.display();
}

That's what display.display() does, if my memory serves me from using an oled with that library some years ago.

I thought display.display() closed out a command, but maybe try this code without display.display()?

To me, it looks like the position of the data is commanded to display at the zeroth pixel in the row.

Actually there's more to it than what I said earlier it seems. I found my old code, and display.display() in setup() with a short delay() shows the splash screen which is in the buffer. But my use of it in loop() does not. I don't see why your one does seem to have the logo in the buffer still.

Can we get a "freeze" frame of the jumpy part? (I can not).

loop( ) runs very very fast.

Only update the display ~500ms (1/2 sec).

1 Like

if I removed the statement: display.display();
it does not show anything on the oled. Thx for the answer

it works fine when the image is displayed every 500 ms, this may be because the I2C communication is not that fast? thx

I'm not sure my answer is 100% correct or perhaps should say not 100% complete. As I said, I have it in setup() of a sketch and it displays the logo but in loop() it does not. And adafruit's examples use display.display() all over; that's what I based my code on.

In one of the examples it says:

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

So it seems that although you have a clear too, it's not actually clearing?

void Oled_mlx() {
display.clearDisplay();

It seems that display.display() is used to actually update the display, so if you took it out is your display actually updating?

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