128x64 Parallel/Serial GLCD using ST7920 Controller - Sketch & Mega2560 Pinout

Dear All,
Can anyone please provide links for:

  1. Complete sketch (from start to end) using ST7920 Controller for this Parallel/serial selectable GLCD (128x64) according to this GLCD's specific pinouts (see below) and
  2. The full Pinout for the Mega2560 Board connecting this GLCD;

There are numerous sketches and very different 128x64 GCLD's Controllers out there BUT none seem to be for the above combination. Or the information that is available is only discernable by one who is fully conversant with the programming languages.

I have located the Datasheet, (DS) for the ST7920 controller - and readers looking for this information need to be aware there are various publication dates for this specific DS ranging from Oct 2002 to Aug 2008 and possibly later as well, and they can be substantially different or don't include the same pin assignments - which adds to both the difficulty in trying to nut this out yourself and creates even more confusion since almost all these "other" GLCD's use two pins, CS1 & CS2 instead of a single pin, E?

The correct pinout for my 128x64 GLCD which carries the only identifying feature of J12864 followed by two chinese characters is:
Pin 1 - GND; Pin 2 - Vcc; Pin 3 - Vo; Pin 4 - RS; Pin 5 - R/W; Pin 6 - E; Pin 7 to Pin 14 - DB0 to DB7; Pin 15 - PSB (Parallel-H/serial-L select); Pin 16 - NC; Pin - 17 RST; Pin 18 - Vout; (from internal voltage doubler); BLA (Backlight annode); Pin 20 - BLK (Cathode).

I hope someone can please put me out of my misery and point me in the right direction. I have, I believe thoroughly chceked(??) both the Arduino and Adafruit sites but to no avail???

Cheers, Ian

Hi

U8glib should work for this display controller (see also my picture below)

For serial setup, connect PSB with GND. Then connect E, RW, RS and RST with some GPIO ports of your board and remember the Arduino pin numbers. Once you installed U8glib, use the following constructor:

U8GLIB_ST7920_128X64_1X(E, RW, RS, RST)

with E, RW, RS and RST must be the pin numbers of your Arduino board.
Similar to a KS0108 setup, V0 has to go to the wiper of a variable resistor, which is connected between GND and Vout for contrast adjustment. On the picture below, i placed the var port directly on the display module.

Oliver

Oliver

Hi Oliver,
Thank you again for your quick reply.
I am however a tad confused with some of what you have said, eg,; "..... connect E, RW, RS and RST with some GPIO ports of your board ...". I understand the GPIO [Serial??] ports on the Mega2560 to be TX/RX pairs - pins 14 to 19?

Are you suggesting that 'E' should connect to (say) TX3 (Pin 14); 'RW' connects to RX3 (Pin 15); 'RS' to TX2 (Pin 16); 'RST' to RX2 (Pin 17)???

I also presume that pins DB0 - DB7 on the GLCD will be connected to Mega2560 digital pins (say) 21 - 27???

I have looked at the U8glib and have located the appropriate line to "uncomment" but need the above to be clarified first.
There is also much confusion with a great many of the available sketches (not necessarily the ST7920 controller) on whether a resistor should also be put in series with BLA (220 ohm is suggested when using +5V) in addition to including the variable pot (10K??) to control contrast on Vo?

Appreciate your clarification please.

Also is there a completed sketch available for both the serial and parallel operation of the same GLCD - if so this would go a long way to seeing what the actual code differences are for both serial and parallel code - and therfore this too would help eliminate confusion arrising from the different codes (serial/parallel) for these different modes of driving the same GLCD?

Regards, Ian

Hi

GPIO = means "General Purpose Input/Output". You can use any four pins of your board. It does not matter which you use. The good thing about serial mode is, that you do not need to connect DB0 to DB7.
See my picture. I have only connected four lines (white wire) with my Arduino board.

Uncommenting a line in u8glib might not need to be enough.You might need to modify the arguments (=pin numbers) of the constructor call.

BLA and BLK usually is the power supply for the BackLight LED. It will require an additional (fixed) resistor. 10K should be fine for the variable pot. Without the datasheet of your display it is difficult to say something reliable, but in general the wiper should be connected to v0. One end to GND and the other end to some negative voltage.

Oliver

Thanks once again Oliver,
Re GPIO's - do you mean you can use 4 x digital or 4 x analog pins for these connections or any combination of either, and not the use the TX/RX pins at all?

Re Uncommenting the U8glib line might not be enough - I was wondering about this as I could not see anywhere in U8glib code where 'E, RW, RS and RST' were being defined with respect to which pin numbers were connected to Mega2560 pins???

Do you have an example code line for this specific process of "telling the code which Mega2560 pins are being used"? I could not see any other similar example in any of the various U8glib code statements that I could see here, either?

By the way, I uncommented the code which still only showed the parameters 'E, RW, RS and RST' as these alpha characters but had not substituted any Mega2560 pin numbers and then compiled the code - which compiled OK showing no errors! Not yet sure what will happen once I substitute the pin numbers, though?

I have attached the Controller (ST7920 DS) which I believe is in my GLCD but I have not yet located a GLCD DS - I have been chasing the seller of the GLCD to provide both - and we all should hound any seller who doesn't provide this basic info for our purchases, or go to another seller that does provide all the required data although these can be few and far between - and he has just sent me an hour ago the ST7920 DS - BUT WAIT - IT IS ALL IN CHINESE, OF COURSE - and therefore NBG, which I have just let them know!!! So I am still only guessing that my GLCD has the ST7920 in it and as yet have no idea whether or not a BL resistor or its size, is required?

Cheers, Ian

ST7920GLCD_DS_Aug2008 .pdf (676 KB)

Re GPIO's - do you mean you can use 4 x digital or 4 x analog pins for these connections or any combination of either, and not the use the TX/RX pins at all?

Yes, you can use any analog or digital pin.

Re Uncommenting the U8glib line might not be enough - I was wondering about this as I could not see anywhere in U8glib code where 'E, RW, RS and RST' were being defined with respect to which pin numbers were connected to Mega2560 pins???

I tried to address this i my first replay:

U8GLIB_ST7920_128X64_1X(E, RW, RS, RST)

The first argument must be the pin number of your board, where you have connected E, second pin is for RW and so on.

The attached datasheed is the datasheet of the controller, not the datasheet of your display module.

Oliver

Thanks once again Oliver – and this time SUCCESS using your U8glib code!

I have attached 3 pictures showing the GLCD working, the Arduino Uno wiring and have included the description of what I did to achieve this for anyone who might be interested in using the 128x64 GLCD! This monochrome display is an excellent GLCD and shows very crisp alpha-numeric characters. The graphics capability is also quite good. It was very cheap at Aus. $10!

The Code:
I used U8GLIB_ST7920_128X64_1X u8g(E, RW, RS, RST); and using the Arduino Uno pins as shown here; U8GLIB_ST7920_128X64_1X u8g(13, 11, 10); RST GLCD pin 17 was not used as the GLCD worked whether or not RST was connected. I am not sure whether not connecting the RST has any adverse consequences. The one adverse observation noted with this particular code is that it takes a very long time for this code to compile and to upload! Could not connecting the RST be causing this slowness?

Uno Wiring:
Parallel/serial select PSB GLCD pin 15 was connected to GND bus, which sets the display in serial mode.
Arduino Uno +5V connected to breadboard bus; GND connected to breadboard –ve bus.
In my case I used a single 220 ohm resistor connected from +5 bus through the resistor to GLCD pin 19, BLA just to be safe and protect the GLCD backlights, and –ve bus to BLK.
I also used a 10K pot as follows; one leg of the pot connected to +5V and the other to GND while the wiper was connected to GLCD Vo pin 3 – the GLCD contrast control. (See below for additional comments on display contrast control).
GLCD GND pin 1 was connected to –ve (GND) bus and GLCD Vcc pin 2 was connected to +5V.
And that’s it!!!

Back of the GLCD:
The third picture shows the components on the rear of the display. Of special interest is VR1; a 7.2K variable pot shown as the “screw” beneath the R1-R5 header. I believe this pot is a built in display contrast control but as stated in my previous post I have not been able to obtain the Datasheet for this GLCD and have only thus far obtained the ST7920 Controller DS. Below VR1 is jumper pad JP3 which itself is not bridged across this jumper pad. Jumper pad 3 connects with VR1 and is, I believe, the means of switching VR1 into or out of the circuit.
Since I have not obtained the GLCD datasheet I am not sure whether VR1 is presently activated so if anyone knows how VR1 (and I am not game enough to just try it without knowing what it does) and JP3 are operated I would be very grateful to know this. I would be equally interested to learn what R1-R7, R10 and JP1, JP2 and JP4 are controlling?
I hope the above description helps anyone who is struggling to get their head around this GLCD!
Cheers, Ian

Thanks for the nice report on this GLCD. It will for sure help others to setup similar displays.

Oliver

Dear all,
I have the same display (128x64, st7920) and with the u8g library, in SPI mode works fine,
My problem is, if i connect the Adafruit UV sensor (1145), that works
in I2C mode, the display does't show any data (totally empty).

The sensor with their example, works fine via serial monitor of PC.

(so, the sensor is OK)

I have this setting for display:
U8GLIB_ST7920_128X64_1X u8g(13, 11, 10, 9); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, Reset = 9)

this is the original code:

#include <Wire.h>
#include "Adafruit_SI1145.h"

Adafruit_SI1145 uv = Adafruit_SI1145();

void setup() {
  Serial.begin(9600);
  
  Serial.println("Adafruit SI1145 test");
  
  if (! uv.begin()) {
    Serial.println("Didn't find Si1145");
    while (1);
  }

  Serial.println("OK!");
}

void loop() {
  Serial.println("===================");
  Serial.print("Vis: "); Serial.println(uv.readVisible());
  Serial.print("IR: "); Serial.println(uv.readIR());
  
  // Uncomment if you have an IR LED attached to LED pin!
  //Serial.print("Prox: "); Serial.println(uv.readProx());

  float UVindex = uv.readUV();
  // the index is multiplied by 100 so to get the
  // integer index, divide by 100!
  UVindex /= 100.0;  
  Serial.print("UV: ");  Serial.println(UVindex);

  delay(1000);
}

I hve modified this line

"Serial.println(uv.readIR());"

with

u8g.print(uv.readIR());

but does not work.
If I try for example, " X=10; u8g.print(x);"
this work fine, the display show the x value (10).

May be there is a problem working with both I2c and SPI protocol
on Arduino UNO?

Many thanks for your help.

Cross-posting NOT ALLOWED:
http://forum.arduino.cc/index.php?topic=307982.msg2137706#msg2137706