ST7565 GLCD Library Functions

I've looked all over but I have yet to find a good repository of just how to use the ST7565 library. I'm using a ST7565 in a project and am having to do a lot of trial-and-error to figure out how to display what I want. Is there a guide similar to the one for the GLCD library, found here: [/Arduino Playground - HomePage

Sorry if my original post was short on details. I have a lot of questions, some of which include:

-Is there a list of functions and their arguments?

-Why is glcd.**** used to call those functions?

-What do the glcd.display and glcd.clear functions do? The glcd.clear function doesn't seem to actually clear the display.

-How do I draw a bitmap?

-What can I read to better answer these questions myself in the future?

dr,
I'm not the author of that library (I'm the author of the GLCD library).
It takes an immense amount of time and effort to document stuff like this. Most folks simply don't bother
much with this part of a project as many people don't seem to treat documentation as being equally
if not more important than the actual code.

I took a quick look at LadyAda's tutorial:
http://www.ladyada.net/learn/lcd/st7565.html
and Paul's Teensy site:
http://www.pjrc.com/teensy/td_libs_ST7565.html

From what I've seen, in order to see the functions and their arguments, you will have to actually
look at the source code.
Take a look at the library header file: ST7565.h
All the functions under the "public:" down to "private:"
are the API functions.

As to why you use "glcd.***" that is controlled by the
object name you select.

For example, if you look in the example code you will
see a few lines that look like:

// The setup() method runs once, when the sketch starts

ST7565 glcd(9, 8, 7, 6, 5);

You see that "glcd" there?
That is the name of the ST7565 library object.
Whatever name you use there is the object name and will be the prefix
to any function you call.
So if you were to change the name to "drrock"
by using this constructor:

ST7565 drrock(9, 8, 7, 6, 5);

Then all your functions would be
drrock.***
or something like drrock.clear(), drrock.display(), etc...

I had a brief look at the code and part of why you are not seeing results
is because of how they wrote their code. They use a local frame buffer that does
not automatically flush to the physical display.

What this means is that nothing you do will affect the way display looks until you
call display() to flush the local frame buffer to the physical display.

So when you call functions like clear(), setpixel(), drawcircle(), etc...
the local frame buffer is updated but you will not see any of those updates on the lcd
screen until you call display().

So have to call display() whenever you want to update the actual lcd display.

While having to manually do the framebuffer flushes by calling display() may seem awkward,
it can actually boost performance because the processor can do several updates to the local
the memory before having to push the frame buffer to the lcd.

Hope that helps get you started.

--- bill

Hi

What I see at the moment: There are several vendors for displays which fit into the Arduino World. All come with some software for the Arduino IDE. However the documentation for this "vendor software" often is, hmm, not so good. Sometimes I think that the hardware is sold with some software just to prove that the hardware is working.

Luckily there is this forum, where people not only try to give good answers, but also try to create a good documentation for their software (thinking of Bill's GLCD documentation for the KS0108 devices).

I try to do the same for the ST7565 devices. The first version of this ST7565 lib is here:

There is also a reference manual and examples here:

I am currently working on a new, more general lib for ST7565 (and similar) devices:
http://code.google.com/p/u8glib/
While still beta, the ST7565 support should be fine. Additionally to the reference manual (Google Code Archive - Long-term storage for Google Code Project Hosting.) I started to write tutorials to discuss special parts of the library (Google Code Archive - Long-term storage for Google Code Project Hosting.).

Oliver

bperrybap, thanks for the help. I've got a better handle on how to work with this display after scrounging through the source code and making copious notes. I still have a lot of questions, but I can at least see a way forward.

olikraus, I tried the dogm128 library before without success. I changed the display type in dogm128.h to the ST7565 and the example programs compiled fine, but nothing was shown on the display. In fact, if I ran a program that used the ST7565 library, then uploaded a program that used the dogm128 library, whatever was last on the display when running the ST7565-based program was frozen after uploading a dogm123-based program. I gave up and switched back to using the ST7565 library, even though it lacks good documentation, because it at least worked without any fuss. If you have any suggestions for what might get the dogm128 library to work, I'd love to hear them. If it matters, I'm using an Arduino Uno with this ATMEGA328 chip and Arduino v1.0. I downloaded dogm v1.13, which is Arduino 1.0-compatible.

I'll give the u8glib library a shot later this evening and post how it goes.

Thanks for your help everyone, I'm moving forward slowly but surely.

Maybe you can give a more precise information which display you have.

Oliver

Ok, so I figured out part of my problem with the libraries was improper wiring of the display. If it's relevant, I'm using a CD4050BC to convert to 3.3V.

So, the ST7565 library uses the following pin assignments from the Arduino:

9 - SID (Serial Input Data)
8- SCLK (Serial Clock)
7 - RS/A0 (Data/Command Select)
6 - RST (Reset)
5 - CS (Chip Select)

The dogm library uses the following pin assignments:

13 - SCK (Serial Clock)
11 - MOSI (I'm not sure what this is--is the same as SID?)
10 - CS (Chip Select)
9 - A0 (Data/Command Select)

The u8glib library uses the following pin assignments:

13 - SCK (Serial Clock)
11 - SI(MOSI) (What made me assume that SID is the same as MOSI)
10 - CS (Chip Select)
? - A0 (I found some references to A0 in the code, but it wasn't clear what pin it should be, exactly)

I know I could change the pin assignments in the code, but I've just been rewiring the display to whatever each library requires.

So I've already established that the GLCD works properly and I can get it working with the ST7565 library. I'd like to get it working with the other libraries since they have more functions that are relevant to what I want to do, but the display isn't doing anything when I connect it up and use those libraries. The example programs for each library compiles properly, but nothing is displayed. So I have a few questions:

What is MOSI? I know it's master in/slave out, but what does it actually do?

Is MOSI the same as the "Serial Input Data"? If not, what display connector should I be connecting to the expected MOSI pin on the Arduino?

Why don't the u8glib and dogm libraries require a reset pin?

Why doesn't the u8glib library explicitly state what pin is A0?

Any help is greatly appreciated. I'm sure I'm doing something wrong in setting this display up for use with the dogm and u8glib libraries, I'm just not sure exactly where it is.

Sorry Oliver, I was writing a reply as you were posting your question.

I'm using this ST7565 from Adafruit. It differs slightly from the one on the page in that it has a 3-color LCD backlight, but otherwise appears identical. The model on the back of the circuit board identifies it as TG12864H3-05A V1.0. There's also a sticker identifying it as TG12864H3-04MA0 AD000294 2011.08.18. I suspect the sticker was placed on it by Adafruit.

Hi

There had been one person who contributed the Adafruit code for the dogm128 lib. I know that it once worked, but I do not own this device, so I am not able to maintain it. I only know, that it was different to the other displays with same controller.

The U8glib does not include the specific code for the Adafruit device. Maybe I can port the code from dogm128 to u8glib. But then I would need someone else to test it.

A0 pin:
It is always there, but often named different. Identical are:
RS: Register Select
DI: Data / Instruction

So A0, RS, DI are all the same.

Oliver

Thanks for the advice Oliver. I'd be glad to test code on the ST7565, if that's of any help. Obviously I'm not of as much use as someone more experienced, but I'm willing to put for the the effort and learn as much as I can in the process.

It seems that the Adafruit display is a TOPWAY LM6059 display.
I have added an experimental device to the u8glib: Google Code Archive - Long-term storage for Google Code Project Hosting.
So you could try the U8GLIB_LM6059() constructor with the Adafruit display. Please let me know if this works.

Thanks for testing!

Oliver

Hi Oliver,

I got the ST7565 working using the dogm library, but still haven't had success with the u8glib library.

I've done a lot of troubleshooting to try to recreate the same configuration in which my display didn't work with the dogm library, including going back to other pin configurations and deleting/reinstalling the library, but haven't had any luck. I think it's fair to say I hadn't configured something properly, but I just wish I could track down exactly what it was for others who may make the same mistakes in the future. I know the hardware was configured properly since the display would work with the ST7565 library, but then wouldn't work with the dogm library. Similarly, the uncommenting in the dogm128.h file is very straightforward, so I can't see how that would have contributed to the problem.

Realtime edit: I think my problem may have been with the A0 pin definition. It's not clear (to me, anyway) in the example code just what the A0 pin should be from a hardware standpoint. Why is A0 shown as "read value" in the comments?

Ok, moving on...

Currently, my pin assignments are: 11-SID (MOSI), 13-SCK, 9-A0/RS, 6-RST, 10-CS

I uncommented line 54 (U8GLIB_LM6059) in the HelloWorld example program for the u8glib library. When I upload the HelloWorld program with this modification, nothing is displayed. If I then upload the dogm128 example program GraphicTest, it works as expected.

I'm not sure what I'm doing wrong, but would appreciate any guidance.

Also, would you like help in writing documentation for these libraries? I'd like to do what I can so that noobs such as myself can better use them. I may not be able to contribute a lot to debugging, but I think I can help out with this and will probably learn a lot in the process.

Currently, my pin assignments are: 11-SID (MOSI), 13-SCK, 9-A0/RS, 6-RST, 10-CS

I uncommented line 54 (U8GLIB_LM6059) in the HelloWorld example program for the u8glib library. When I upload the HelloWorld program with this modification, nothing is displayed. If I then upload the dogm128 example program GraphicTest, it works as expected.

Did you also added the reset pin? Instead of

//U8GLIB_LM6059 u8g(13, 11, 10, 9);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9

use

U8GLIB_LM6059 u8g(13, 11, 10, 9, 6);                    // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9

If the LM6059 device does not work, it might be also interesting to see if the LM6063 will show something on the display:

U8GLIB_LM6063 u8g(13, 11, 10, 9, 6);

I am glad that the dogm128 lib works.

Documentation: Will sent PM.

Oliver

I hadn't added the reset pin, but it still is not working with the reset pin added. Is there a reason the commented constructor calls don't include a reset pin assignment?

So to be clear, I have my display setup and working with the dogm128 library. If I then switch to the examples using the u8glib library without changing any of the hardware, the u8glib example doesn't display anything. This is the case for the U8GLIB_LM6059, U8GLIB_LM6063, and U8GLIB_DOGM128 constructors, all of which I tried with the (13, 11, 10, 9, 6) pin assignments.

Hi

The Dogm128 lib remaps the pins to:

#define PIN_RST   6     // This is for the default Adafruit wiring scheme
#define PIN_SCK   8     // described in:
#define PIN_MOSI  9     // http://www.ladyada.net/learn/lcd/st7565.html
#define PIN_SS    5     // change these numbers to reflect your wiring.
#define PIN_A0_DEFAULT  7

This means, the constructor should be:
U8GLIB_LM6059(8, 9, 5, 7, 6)

As described in
http://code.google.com/p/u8glib/wiki/device
the reset pin is optional. For most of my displays, there is either no reset pin, or I constucted the reset via a cap and a resistor.

Hope, this helps

Oliver

I still didn't have any luck with the u8glib, unfortunately.

Here's what I did:

  1. Uncommented line 54 in HelloWorld.pde and changed the constructor to: U8GLIB_LM6059 u8g(8, 9, 5, 7, 6);

  2. Changed my Arduino pinouts accordingly

  3. Uploaded the HelloWorld u8glib example program--nothing was displayed

  4. Opened up the dogm128.h, changed lines 195-199 to:

#define PIN_RST   6 
#define PIN_SCK   8
#define PIN_MOSI  9   
#define PIN_SS    5 
#define PIN_A0_DEFAULT 7
  1. Uploaded the GraphicTest dogm example program, which worked as expected.

Is this what you wanted me to test? If not, just let me know what changes I should make and I'll give it another shot.

Also, I gather that the reset pin is simpler than I had originally thought--it just resets the display, and isn't a high-speed input or anything. I did a bit of reading and it seems that you just have to make sure it's held at +3.3V and doesn't float. Then, if grounded, it resets the display. Is that correct? I know it's a really simple question, but I hadn't looked it up.

I am now thinking that still the init sequence is wrong --> PM

Reset: Yes, thats true. However, sometimes it is required to holde reset line low for some time.
This means: The power is already up at 3.3 Volt, but the reset line must still be at 0 Volt. So it can not be simply connected to the 3.3 Volt line. This may work only for some circuits.

Oliver

I'm having problems with the same display using an arduino mega 2560, also with a pic 16f88,
in both cases i'm assuming i have a error with my init sequence. I'm running the dogm128, screen which has the st7565 onboard. at 3.3v. I'll concentrate on the arduino here so ignore my pic comment.

i created a simple test sketch following the example init sequence on the data sheet provided with the gLCD.

#include <SPI.h>
//rs line is tied high to no need for pin assignment of rs.

const int A_Line = 49;
const int MISO   = 50;
const int MOSI   = 51;
const int SCK    = 52;
const int SS     = 53;

void setup()
    {
    pinMode(22,         INPUT);      //switch to decide if test command
    pinMode(A_Line,  	OUTPUT);     //A0 line
    pinMode(MISO,  	INPUT);      //not used
    pinMode(MOSI,  	OUTPUT);     //connected to serial input of gLCD
    pinMode(SCK,   	OUTPUT);     //clock
    pinMode(SS,    	OUTPUT);    //chip select
    
    SPI.begin();                    //start spi protocol
    SPI.setDataMode(SPI_MODE0);      //set mode 0, L_to_h, no phase shift
    SPI.setBitOrder(MSBFIRST);      // send byte MSB to LSB
    SPI.setClockDivider(SPI_CLOCK_DIV64);    //divide system clock by 64 to give spi clock
    }
    
void loop()
    {
    long column= 0x0101;        // column address, 16 bit word
    screen_init();              // call init routine
    delay(2000);
    while(true)
        {
        if(digitalRead(22)==HIGH)  
            {
            screen_test();    //st7565 test case
            delay(1000);
            }
        else
            {
            screen_NOP();    // refresh
            delay(500);
            screen_write(0x44, 0xD0, column);    // write data, row, column
            delay(500);
            column++;                            //stop overwrites by incrementing address
            }
        }
    }
    
void screen_NOP(void)                            // NOP routine
    {
    digitalWrite(A_Line,  LOW);
    digitalWrite(SS,  LOW);
    SPI.transfer(0xE3);
    delay(1);
    digitalWrite(SS,  HIGH);
    digitalWrite(A_Line,  HIGH);
    }    
    
void screen_write(int letter, int page, long column)//write routine
    {
    int col_LSB, col_MSB;
    digitalWrite(A_Line,  LOW);
    digitalWrite(SS,  LOW);
    page=(page && 0x0F);
    page=(page || 0xB0);
    col_LSB = column;
    column = column >>8;
    col_MSB = column;
    SPI.transfer(page);
    delay(1);
    SPI.transfer(col_MSB);
    delay(1);
    SPI.transfer(col_LSB);
    delay(1);
    digitalWrite(SS,  HIGH);
    digitalWrite(A_Line,  HIGH);
    digitalWrite(SS,  LOW);
    SPI.transfer(letter);
    delay(1);
    digitalWrite(SS,  HIGH);
    }
    
void screen_init(void)
    {
    digitalWrite(A_Line, LOW);
    digitalWrite(SS,  LOW);        
    SPI.transfer(0x40);	        //set display start address
    delay(1);
    SPI.transfer(0xA1);        //set view to 6oclock mode
    delay(1);
    SPI.transfer(0xC0);        //Common output mode
    delay(1);
    SPI.transfer(0xA6);        //Display normal
    delay(1);
    SPI.transfer(0xA2);        //gLCD bias
    delay(1);
    SPI.transfer(0x2F);        //Power conditioning
    delay(1);
    SPI.transfer(0xF8);        //Boost ratio MSB
    delay(1);
    SPI.transfer(0x00);        //Boost ratio LSB
    delay(1);
    SPI.transfer(0x27);        //Vreg set
    delay(1);
    SPI.transfer(0x81);        //contrast MSB
    delay(1);
    SPI.transfer(0x16);        //contrast LSB
    delay(1);
    SPI.transfer(0xAD);        //indicator on
    delay(1);
    SPI.transfer(0x01);        //indicator flash
    delay(500);
    SPI.transfer(0xAF);        //power on gLCD
    delay(1);
    digitalWrite(SS,  	HIGH);
    digitalWrite(A_Line, HIGH);
    }

void screen_test(void)
  {
  digitalWrite(SS,     LOW);
  digitalWrite(A_Line, LOW);
  delay(1);
  SPI.transfer(0xF0);        //test script, not to be used in reg programme.
  delay(1);
  digitalWrite(SS,    HIGH);
  digitalWrite(A_Line,  HIGH);
  }

my gut tells me the screen_init(); isn't doing all its supposed to.
when i power the screen up nothing appears before the init seq or after yet if i connect the chip select line before power a Scottish tartan type pattern appears on the un-powered screen.

i'm hoping to use these screens for my final year project in uni but so far they have boogled my brains.

At least for u8glib there is a fixed version for download.
See the init sequence for the there, which has been reported to be ok.
Not that the Adafruit ST7565 needs a different setup than the ST7565 inside the DOGM128.

Oliver

following adafruits init sequence, i've re-written the power controller commands and included a 50ms
delay between each step,

void screen_init(void)
    {
    digitalWrite(A_Line, LOW);
    digitalWrite(SS,  LOW);        
    SPI.transfer(0x40);	        //set display start address
    delay(1);
    SPI.transfer(0xA1);        //set view to 6oclock mode
    delay(1);
    SPI.transfer(0xC0);        //Common output mode
    delay(1);
    SPI.transfer(0xA6);        //Display normal
    delay(1);
    SPI.transfer(0xA2);        //gLCD bias
    delay(1);
	
    SPI.transfer(0x2C);			// Power condition
    delay(50);
    SPI.transfer(0x2E);			//power condition
    delay(50);
    SPI.transfer(0x2F);        //Power conditioning
    delay(50);
	
    SPI.transfer(0xF8);        //Boost ratio MSB
    delay(1);
    SPI.transfer(0x00);        //Boost ratio LSB
    delay(1);
    SPI.transfer(0x27);        //Vreg set
    delay(1);
    SPI.transfer(0x81);        //contrast MSB
    delay(1);
    SPI.transfer(0x16);        //contrast LSB
    delay(1);
    SPI.transfer(0xAD);        //indicator on
    delay(1);
    SPI.transfer(0x01);        //indicator flash
    delay(50);
    SPI.transfer(0xAF);        //power on gLCD
    delay(1);
    digitalWrite(SS,  	HIGH);
    digitalWrite(A_Line, HIGH);
    }

still no joy, i also noticed that the arduino seems to be floating the outputs, i'm using a resisitor devidor to step from 5v to 3.3v logic, but it seems to float at 2v. i know I2C uses external pull ups on the SDA and SCL lines but i have never seen it on SPI?

The spi doesnt seem to be doing the trick either as the v0 to v4 legs on the screen dont change their voltages after the boost and reg and control commands. I'm wondering is it a dead screen. the scotch tartan i mentioned previously makes me think it's alive but this is my first time working with a gLCD.

Without configuring the screen, did it display anything when you applied power to it? a cursor or test screen?

Thanks for the adafruit tip, their pdf was informative.