128x64 OLED monochrome + u8glib with text output => missing pixels

Hi,

first of all a big THANK YOU to Olli Kraus for this wonderful library! :)

I am at the beginning of experimenting with the Arduino world.

The OLED I am using has a TWI connection and GNG and Vcc. I connected SDA of the OLED to A4 and SCK to A5, GND to GND and Vdd of the OLED to Vdd of the Arduino Pro Mini (3.3V Wattuino Pro Mini). There three different contructors for that kind of OLED in the u8glib I tried all.

The program does nothing more then reading micros() and printing that value with a "C:" in front of it onto the screen.

Unfortunately the string containing the digits is somehow corrupted. It looks either like pixels are missing or the digits are cutted by invisible limitation.

The display seems to be ok since the graphics demo runs witnout problems.

The according code fragment is:

unsigned long tmicros=0;
void draw(void) {
  u8g_uint_t len;
  u8g_uint_t hig;
  u8g.setFont(u8g_font_unifont);
  // u8g.setFont(u8g_font_osb21);
  tmicros=micros();
  u8g.drawStr( 0, 22, F("C:"));
  len=u8g.getStrWidth(F("C:"));
  // hig=u8g.getFOntAscent
  u8g.setPrintPos( len, 22 );
  u8g.print( tmicros);
}
void setup(void) {
  // flip screen, if required
  // u8g.setRot180();
  
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }

  u8g.setContrast( 50 );

}

void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(1000);
}

How can I display the digits correctly?

Thank you very much in advance for any help ! :)

Best regards, mcc

PS: Some more informations: I had used this constructors, which no difference regarding the problem: U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC The graphicsdemo of the u8glib shows no problems, the text output is somehow distorted as described above. The display is directly connected to the Wattuino.

The problem is that your draw() function is called multiple times to print the string, i.e top half of characters then bottom half. Of course subsequent calls occur at a different time...

Change you code to something like this:

unsigned long tmicros=0;
void draw(unsigned long tm) {
  u8g_uint_t len;
  u8g_uint_t hig;
  u8g.setFont(u8g_font_unifont);
  // u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 22, F("C:"));
  len=u8g.getStrWidth(F("C:"));
  // hig=u8g.getFOntAscent
  u8g.setPrintPos( len, 22 );
  u8g.print( tm );
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();

  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }

  u8g.setContrast( 50 );

}

void loop(void) {
  // picture loop
  tmicros=micros();

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

  // rebuild the picture after some delay
  delay(1000);
}

Yes, correct, the time value must not change during the first/next loop.

Oliver

Hi,

OH YEAH! :) Thanks a lot bodmer and olikraus -- beside being happy that my first steps with this wonderful library are now successful I am especially happy that no hardware is involved in the problem!

A great THANK YOU! to you!

Best regards and have a nice weekend! mcc