On this topic I wrote an article [1] in 2015,
where I modified the KS0108 library to apply it to the Teensy 3.1 board.
Now a simpler solution can be realized using
the latest versions of the u8g2 library by Olikraus.
This article refers to the Teensy 3.1 MCU but
it can be adapted to other MCUs, such as STM32 or others, simply by inserting
the available pins in the library declaration, this graphic display requires 8 bits
for the data bus and 5 for control.
The GLCD display I used is the ‘J’ version of
the Winstar WG12864A, which only two more pins to obtain an RGB backlight with
two more LEDs. This display has NT7108- NT7107 graphic controllers completely
similar to the KS0108- KS0107. They have 64 channels: for a 128x64 pixel
display you need two NT7108 chips for the 128 columns and an NT7107 for the 64
rows. Usually these chips are soldered on the pcb without a case and are
covered with black resin, so we cannot read any sigle.
The advantages of using these displays are that
they can be read even under the sun, excellent readability, good speed and
relatively low consumption, the main disadvantage is that they require many output
pins having an 8-bit parallel bus.
Although it is powered by 5 volts, it can also
be connected to an MCU with 3.3 V levels, in fact all the signals are output
and the R/W is always set to zero, as is done with alphanumeric LCDs.
The following table shows the connections with
Teensy 3.1.
Pin |
name |
description |
Teensy |
1 |
VSS |
Ground |
Gnd |
2 |
VDD |
Supply voltage for logic |
5V |
3 |
Vo |
LCD contrast
(Pot. Cursor) |
- |
4 |
D/I |
H: Data
, L : Instruction (=DC) |
9 |
5 |
R/W |
Read/Write |
4 |
6 |
E |
Enable signal |
17 |
7 |
DB0 |
Data bus line |
2 |
8 |
DB1 |
Data bus line |
14 /A0 |
9 |
DB2 |
Data bus line |
7 |
10 |
DB3 |
Data bus line |
8 |
11 |
DB4 |
Data bus line |
6 |
12 |
DB5 |
Data bus line |
20 /A6 |
13 |
DB6 |
Data bus line |
21 /A7 |
14 |
DB7 |
Data bus line |
5 |
15 |
CS1 |
Select Column 1~ Column 64 |
19 |
16 |
CS2 |
Select Column 65~ Column 128 |
18 |
17 |
/RES |
Reset signal |
23 |
18 |
Vout |
Negative Voltage output |
- |
19 |
A |
Anode LED
backlight ( + ) |
- |
20 |
KR |
Cathode Red
led |
- |
21 |
KG |
Cathode Green led |
- |
22 |
KB |
Cathode Blue led |
- |
Now I use the u8g2 library with the ability to
use pins arbitrarily, in my case I configured:
U8G2_KS0108_128X64_F u8g2(U8G2_R0,2,14,7,8,6,20,21,5, /*E=*/17, /*dc=*/9, /*cs0=*/ 19, /*cs1=*/18, /*cs2=*/ U8X8_PIN_NONE, /*Res=*/23);
I chose the ‘Full buffer’ mode because it is
faster and there are no memory problems with this MCU.
The parameters passed are: D0 - D7, E, D/I,
CS1,CS2,none,Reset.
From tests I have done I understood that: cs0,
is CS1 and cs1 = CS2 while cs2 does not exist for this display as each CS
enables a chip that drives 64 channels and that, together with an NT7107 chip,
creates a 64x64 pixel matrix that requires a memory of 512 bytes.
The library, after having configured it
correctly, worked well. Of course, if you could transfer one byte at a time it
would be faster, but the MCU is much faster than Arduino Uno and this is not a
problem.
In the introductory photo you can see the
example program “GraphicsTest.ino”.
To test the system I wrote this simple program:
/* TeensyGLCD program - I/O
Teensy 3.1
uses a Winstar WG12864A Rev.J
GLCD display
G. Carrrera 05/04/25*/
#include <U8g2lib.h>
U8G2_KS0108_128X64_F
u8g2(U8G2_R0,2,14,7,8,6,20,21,5, /*E=*/17, /*dc=*/9, /*cs0=*/ 19, /*cs1=*/18, /*cs2=*/
U8X8_PIN_NONE, /*Res=*/23);
#define LCD_RW 4
void setup() {
pinMode(LCD_RW, OUTPUT);
digitalWrite(LCD_RW, LOW); // Set R/W to low
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
//u8g2.setFont(u8g2_font_t0_11_tr);
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0,10,"Teensy ADC
to GLCD");
u8g2.drawStr(0,20,"G.Carrrera
05/04/25");
u8g2.sendBuffer();// transfer internal memory to
the display
delay(3000);
}
void loop() {
uint16_t ain = analogRead(22);// read analog input A8
u8g2.clearBuffer();
u8g2.setCursor(40, 40);
u8g2.print("AD8=
" + String(ain));
u8g2.sendBuffer();
delay(1000);
}
As you can see, the R/W signal must always be
put on write, i.e. to ground. But in the circuit I made it was connected to pin
4, so I did it via software.
The diagram of my system can be found in the
article cited.
References
1. “A
128x64 GLCD for Teensy 3.x”, Giovanni Carrera, ArduPicLab 21/08/2015.
2. https://github.com/olikraus/u8g2/wiki/u8g2reference