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.
#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]