Go Down

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

#105
##### Jan 12, 2013, 01:43 am
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!

#### olikraus

#106

Oliver

#107
##### Jan 12, 2013, 05:52 pmLast 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 positionint prevXPos = 0; // Previous x positionint 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.

#### tack

#108
##### Jan 12, 2013, 09:41 pm
Does this library work with the ST7735S driven 128x160 TFT displays?

#### olikraus

#109
##### Jan 13, 2013, 09:59 am
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

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

#### rgroener

#110
##### Jan 13, 2013, 10:04 am
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

#### DukeR

#111
##### Jan 27, 2013, 05:53 pm
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?

#### olikraus

#112
##### Jan 27, 2013, 07:40 pm
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

#### DukeR

#113
##### Jan 27, 2013, 07:54 pm
Perfect! That's it. Though looks slower now (fps).
Does anyone have a fps benchmark sketch with this library?
Thanks Oliver.

#### olikraus

#114
##### Jan 27, 2013, 08:47 pm
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

#### DukeR

#115
##### Jan 27, 2013, 08:55 pm
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!

#### olikraus

#116
##### Feb 02, 2013, 06:56 pm
Hello All

* 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

#### ibh4

#117
##### Mar 02, 2013, 03:43 pm
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!!!!!

#### olikraus

#118
##### Mar 02, 2013, 05:18 pm
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

#### olikraus

#119
##### Mar 02, 2013, 10:33 pm
I have finished release v1.11:
* Support for T6963
* Support for Arduino Due
* Sleep Mode
* 4x mode for ST7920
* New C++ interface for ST7920

Oliver

Go Up

Please enter a valid email to subscribe