Go Down

Topic: U8glib: Graphics Lib for LCDs and OLEDs (Read 147508 times) previous topic - next topic


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 :)

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

- Muhammad.


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



Jan 12, 2013, 05:52 pm Last Edit: Jan 12, 2013, 05:57 pm by Muhammad Reason: 1
Oops. Sorry about that. Here it is:

Code: [Select]
#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(val);// Print out the Y value.

  u8g.setPrintPos(20, 63);// Set Cursor.
  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

void loop(void) {

  do {
    xDraw = 0;
    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?


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

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

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, 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.



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.



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

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.




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!!!!! :) :)



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

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



I have finished release v1.11:
  * Support for T6963
  * Support for Arduino Due
  * Sleep Mode
  * 4x mode for ST7920
  * New C++ interface for ST7920



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131