OLED I2C 0.96' + LM35 temperature sensor programming help?

Hello, my main problem is that I don't know how to update my code for correct program work. The problem is that, for example, when OLED display displayed sensor value, if temperature changes between 23-24 (20 - 21, 25-26 and so on) degrees, display show something like in picture.


I don't now how to code to read value, save it and than display it. I tried change delay time, before and after reading, but that did't help.

I use 0.96" I2C 128X64 white OLED display module for Arduino with SSD1306 driver, LM35 temperature sensor and an Arduino Nano. And u8g library.
Here are conections in picture.



And here are my code:

#include "U8glib.h" // U8glib library //https://code.google.com/p/u8glib/
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // library of supported displays // https://code.google.com/p/u8glib/wiki/device
// I2C display legs connected to VCC=3.3V, GND=GND, SLC=A5 (analog pin 5), SDA=A4 (analog pin 4)

int tempPin = 0; // LM35 temperature sensor signal (middle) leg connected to A0 (analog pin 0) pin, Left leg=5V, Right leg=GND, for better understanding find LM35 datasheet

const uint8_t logo_bitmap[] PROGMEM = { // thermometer logo converted with LCDAssistant //http://en.radzio.dxp.pl/bitmap_converter/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
0x00, 0x41, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00, 0x9C, 0x80, 0x00,
0x01, 0xBE, 0x40, 0x00, 0x03, 0x7F, 0x60, 0x00, 0x06, 0x7F, 0x30, 0x00, 0x0E, 0xFF, 0xB8, 0x00,
0x0C, 0xFF, 0x98, 0x00, 0x0D, 0xFF, 0xD8, 0x00, 0x0D, 0xFF, 0xD8, 0x00, 0x05, 0xFF, 0xD0, 0x00,
0x02, 0xFF, 0xA0, 0x00, 0x01, 0x7F, 0x40, 0x00, 0x00, 0xBE, 0x80, 0x00, 0x00, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};


void draw(void) {

  u8g.drawBitmapP(0, 0, 4, 64, logo_bitmap); // draw logo on display (X=0 (diplay horizontal start point, max 128) , Y=0 (display vertical start point, max 64), logo width=16, diplay vertical width=64)
  u8g.setFont(u8g_font_fub35n);  // select font from u8glibrary //https://code.google.com/p/u8glib/wiki/fontsize
  u8g.setPrintPos(25, 53);  // set position on display at position X, Y
  int temp = analogRead(tempPin); //read LM35 sensor value
  temp = (500 * temp) / 1023; // convert LM35 sensor value to real °C temperature
  u8g.print(temp);  // display temperature from LM35
  u8g.setFont(u8g_font_fub30); // select font from u8glibrary
  u8g.drawStr(80, 53, " C "); // set position on display at position X, Y
  u8g.setFont(u8g_font_ncenB12); // select font from u8glibrary
  u8g.drawStr(83, 32, "o"); // set position on display at position X, Y
}

void setup(void) {
}

void loop(void) {

  u8g.firstPage();
  do {
    draw();
  } while ( u8g.nextPage() );

  delay(3000);  // Delay of 3sec before display next result from LM35

} [code]

First off, you should find the Documentation e.g. https://code.google.com/p/u8glib/wiki/userreference#drawStr

Some libraries give you the choice of drawing a fresh background when it draws a new letter.
It seems that u8glib just draws the new letter over the top of whatever was originally on the screen.

So all you need to do is wipe out the old text with a drawBox() of suitable size.
Then your value is drawn on a fresh background.

Or you simply re-draw the whole screen every time.

The drawBox of a small area will give you a snappier response. And of course you only need to re-draw when a value has changed.

David.

Thanks, David. When I will be at home, I will try it. But I think it's didn't help.

I know u8glibrary homepage.
My problem is that, display refresh himself after every 3 sec. I changed time from 1ms up to 5 sec, but didn't help.
Analog signal come in faster than display can displayed. For example display start showing 23 degrees (analog signal 23.3 degrees), than analog input signal change up to 23.7 (display show 24 degrees) and than back. All its happen so fast in milliseconds. And display show 2. 343. degrees(watch my second picture in first post).

There is no point in reading a Sensor faster than a human can read it.
In practice, it is worth calculating a running average. And displaying this "smoothed" result.

I doubt if any temperature sensor is going to change every millisecond. Checking every few seconds would be plenty good enough.

Note that you probably want to use u8g.print(temperature, 1)
Your Sensor is not accurate enough for 2 decimal places.

David.

Okey, I added video where you can see my problem. There temperature changes between 24 and 25 degrees.

I have SPI 1.3" OLED display too, the same problem. I can't solve this problem for seven weeks.

One more question. How i can turn display off after some time? I tried to write code, but get nothing. From library page "Available with v1.11. Supported for ST7565 and SSD13xx controller. " I have I2C with SSD1306 driver.

About the overlap reading, try to change the u8g font.