Go Down

Topic: U8glib: Graphics Lib for LCDs and OLEDs (Read 54 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.


Go Up