U8glib: Graphics Lib for LCDs and OLEDs

After some late-night tinkering, I managed to get it to scan. I guess it just took me some time to get acquainted with the Do While structure of execution. It renders a tad slow, but it's still pretty good. I might have an idea on how to speed things up...

I'm using an LCD I bought off of Ebay, similarly found here: http://tinyurl.com/cxujsag which works perfectly under NHD_C12864.

I can definitely understand the memory oriented design of this library. A lot of display libraries don't fare well on the ATMega168. I know Adafruit's library for the Nokia 5110 display will only work on a 328 and up.

I've attached a photo of it plotting a .4Hz signal from a function generator. I've also attached the program for whoever may be interested in it. Ideas on optimization would be much appreciated :slight_smile:

I really appreciate the work you've put into this library!

  • Muhammad.

SPI_Scan_Test.ino (1.64 KB)

Hi Muhammad
Thanks for sharing your project, however, the code is not readable (downloadable) at least for me.

Oliver

Oops. Sorry about that. Here it is:

#include "U8glib.h"

U8GLIB_NHD_C12864 u8g(13, 11, 10, 9);

int val; // Y value (Read from the Analog input)
int xPos = 0; // X position
int prevXPos = 0; // Previous x position
int scanVal[128]; // Array to hold the graphs values as it scans.
int xDraw; // Used to 

//--------------------------------------------

void drawText(void) {
  val = analogRead(A0);// Poll ADC
  val = map(val,0,1023,63,0);// Scale things down to fit the vertical pixel count of the LCD. 

  scanVal[xPos] = val;// Write the Y value to the appropriate element (X value). 

  u8g.setPrintPos(50, 63);// Set Cursor.
  u8g.print("Y");
  u8g.print(val);// Print out the Y value.

  u8g.setPrintPos(20, 63);// Set Cursor.
  u8g.print("X");
  u8g.print(xPos);// Print out the X value.
}

//--------------------------------------------

void drawScan(void) {// This function cycles 128 times per update to draw the full scan of the line. 
  val = scanVal[xDraw];// Pull the Y value from the appropriate element. 
  u8g.drawPixel(xDraw,val);// Set a pixel.
  xDraw++;// Increment the column position (X value).
}// End of scan

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void setup(void) {
  u8g.setRot180();// Flip screen
  u8g.setFont(u8g_font_6x10r);// Set Font
  pinMode(7,OUTPUT);
}

void loop(void) {

  u8g.firstPage();  
  do {
    drawText();
    xDraw = 0;
    do
    {
      drawScan();
    }
    while(xDraw <= 127); // Loop to draw every column of the array. 
  } 
  while( u8g.nextPage() );


  if(xPos == 127) xPos = 0; // Reset X to 0 when it reaches the last column on the screen. 
  else xPos++; // Increment X position 

}// End Void Loop()

I couldn't get it to draw lines instead of points. It would visibly buffer the pages.

I'm actually running my display in parallel mode with a different library to see if I can get it to work right. It works well, but I have to figure out how to set the contrast since it is not set up to be externally controlled like KS0108 driven displays. I think I've found out how to adjust it in the datasheet, though.

  • Muhammad.

Does this library work with the ST7735S driven 128x160 TFT displays?

@Muhammad
Thanks for the code. The only little optimization, could be to poll the ADC outside of the picture loop.

@tack
U8glib has been optimized for monochrome displays. It is possible to support full color displays and some work has been done already, but probably u8glib is too slow to support these kind of displays. Another issue is the init sequence of the display. It is already complicated for some graylevel displays, but becomes a nightmare with full color displays.

Have a look at the ILI9325d code for the 320x240 TFT
http://code.google.com/p/u8glib/source/browse/csrc/u8g_dev_ili9325d_320x240.c

Results from u8glib perspective are:

  • only 256 colors
  • slow
  • complex init sequence, needs to be derived from many sources and verified with the display.

I think the ILI9325 code could be a good starting point, but the programmer needs physical access to the display and a reliably start up sequence.

Oliver

Oliver, thanks a lot for your explanation. I will read more about it.
I really do like your U8glib and will use it in my curent project. Especially the fonts are great!
I should have enough memory to draw a graph.

Best regards Roman

Oliver, hi, and sorry for my english in advance.
Just bought a 12864B (st7920) lcd from dx.com, and wired it to my arduino (compatible) nano v3.0. When connecting it thru SPI and using your 1.09 library I can use all the demos you provide, but (as you explain) it's a little slow (fps wise). So I tried to wire it thru 8bit parallel, but I get a corrupted screen (some or most of the image it's supposed to show is there, but the rest is... random.). I've checked and rechecked the wiring and just can't find the error.
The two are connected like this:
Arduino --> LCD function --> LCD naming
d5, d6, d7, d8, d9, d10, d11, d12 --> d0, d1, d2, d3, d4, d5, d6, d7 --> db0, db1, db2, db3, db4, db5, db6, db7
d4 --> clock --> E
d3 --> RW --> R/W
d2 --> CS --> RS
GND --> Ground logic, PSB, ground backlight --> GND, PSB, BLK
5v --> vcc logic, vcc backlight --> VCC, BLA

and the constructor used for parallel is
U8GLIB_ST7920_128X64 u8g(5, 6, 7, 8, 9, 10, 11, 12, 4, U8G_PIN_NONE, U8G_PIN_NONE, 2, 3);
in SPI is
U8GLIB_ST7920_128X64 u8g(4, 3, 2, U8G_PIN_NONE);

The only wire I change when testing from SPI (working) to 8bit parallel (garbage) is the PSB from gnd to 5v, and reupload the sketch with the other constructor

And here is a video of what it looks like when running the "graphics" example in parallel:

What am I doing wrong?

I have uploaded a beta release 1.10pre1. Could you please check this version also. I think i also added some delays to the strobe signal.

Thanks,
Oliver

Perfect! That's it. Though looks slower now (fps).
Does anyone have a fps benchmark sketch with this library?
Thanks Oliver.

U8glib is not fast. This has been discussed some weeks ago in this thread.
But there is a pending issue, to improve speed for your controller.

Oliver

I read that discussion, and understand why. What I meant is that from the garbage displaying 1.09 to the working 1.10pre1, the garbage looked like it was drawn faster.
Would be great if at some point you could implement the low level functions that take advantage of the "read" capabilities of 8bit parallel conection, while maintaining the flexibilities it has now for the rest.
Great library!

Hello All

A new release of U8glib is available for download (v1.10).

  • Support for SSD1309 and NHD-C12832
  • Bugfixes for parallel-mode (reset pin) and ST7920 controller

@DukeR
Except for checking the "busy" flag, adding read capabilities to U8glib would require a huge rework of the lib. I currently do not have the time to do this.

Oliver

http://code.google.com/p/u8glib/

I've got a problem in my mind,needing for help:how to control LCD12864,by only using SPI .Can you give me some picture about it? Thank's a lot. I am learnning to display the data play in the 12864 using mega 2560.Thanks!!!!! :slight_smile: :slight_smile:

Hi

Can you provide a link to the display? This would help a lot.

In general displays with SPI interface are usually connected like this:

Oliver

I have finished release v1.11:

  • Support for T6963
  • Support for Arduino Due
  • Sleep Mode
  • 4x mode for ST7920
  • New C++ interface for ST7920

http://code.google.com/p/u8glib/

Oliver

I got a specific ST7565 board to work on the DUE, but i did not know this thread yet,
it is posted here : U8glib works with some effort on GLCD - Arduino Due - Arduino Forum

including details on wiring it up (and a few tweaks).

Hi

U8glib Version v1.13 is available for download:

Updates include:

  • Support for SSD1351 (true color OLED) and HT1632 (LED Matrix)
  • Performance improvements for the ST7920
  • Double buffer option for ST7565 controller
  • HW SPI support for Arduino Due

Oliver

Hi everyone !

I am new to the arduino.

and i have an GLCD type of wdg0151-tmi and i dont know to wire it and also how to program it with arduino mega .

please please help and thank you and sorry for my bad language :slight_smile:

Hi

It seems to be this display: http://www.mikroe.com/download/eng/documents/development-tools/components/glcd_128x64_spec.pdf
It is a KS0108 based display. With U8glib, you can use

U8GLIB_KS0108_128(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw [, reset])

but Bill's GLCDv3 will also work: GLCD library version 3 (end of life - no longer supported) - Displays - Arduino Forum

Oliver

Thank you very much :*

but still need more information please :blush: