Skip to content
Forged in Barberton, Ohio · Since 1983 Counter: +1 (330) 555-0142

Is a 3.18 inch 128x64 COG LCD display easy to program?

aBy admin||Great American Tool

Short answer: yes, it’s surprisingly straightforward once you understand the hardware and software stack. But “easy” depends on your experience with microcontrollers, display drivers, and wiring. I’ve worked with dozens of LCD modules over the years, and the 3.18 inch 128x64 cog lcd display sits in a sweet spot: it’s not as trivial as a character LCD with a parallel interface, but it’s far simpler than high-res TFT panels that require frame buffers and complex initialization sequences. Let’s break down exactly what makes it easy or hard, with real numbers and practical examples.

First, the hardware interface. This display uses SPI (Serial Peripheral Interface), which is one of the most common communication protocols in embedded systems. You only need 4 wires to talk to it: MOSI, SCK, CS, and DC. Add VCC and GND, and you’re at 6 connections total. Compare that to a parallel 8-bit interface that uses 10+ GPIO pins. SPI also runs at clock speeds up to 10 MHz on most microcontrollers, meaning you can update the entire 128x64 pixel buffer in about 1 millisecond. That’s fast enough for smooth animations if you optimize your code. The COG (Chip-on-Glass) design means the driver IC is bonded directly to the glass, reducing component count and making the module thinner—only about 2.5 mm thick including the PCB. This also means the display is less prone to connection issues compared to modules with separate driver boards.

The driver IC is the key. Most 128x64 COG displays use either the SSD1306 or ST7567 controller. The SSD1306 is more common for OLEDs, but for this COG LCD, you’re looking at the ST7567 or a clone. The ST7567 has a 132x65 pixel RAM, but only 128x64 is visible. That extra row is for scrolling or partial updates. The initialization sequence is about 20-30 commands, and you can find ready-to-use libraries for Arduino, ESP32, Raspberry Pi, and STM32. For example, the u8g2 library supports the ST7567 with a 128x64 resolution and SPI interface. You just call U8G2_ST7567_128X64_1_HW_SPI and it handles the rest. The library itself is about 50 KB of flash, leaving plenty of room for your application code on a typical ESP32 with 4 MB flash.

Power consumption is another factor. This COG LCD draws about 1.5 mA with the backlight off, and around 20 mA with a typical white LED backlight at full brightness. That’s low enough to run on a coin cell for a few hours, or on a 500 mAh LiPo battery for over a day if you use sleep modes. The contrast is adjustable via a software command (0x81 for the ST7567), and you can set it between 0 and 63. I usually set it to 32 for a good balance. The display also has a built-in voltage booster that generates the -7V to -10V needed for the LCD glass, so you don’t need an external negative supply.

Let’s talk about pixel density and readability. At 3.18 inches diagonal, the 128x64 resolution gives you about 47 PPI (pixels per inch). That’s lower than a smartphone, but perfectly readable for text at a normal viewing distance of 30-50 cm. Each pixel is about 0.5 mm wide, so a 6x8 font character is about 3 mm tall. You can fit 21 characters per line with a 6-pixel font, or 16 characters with an 8-pixel font. The viewing angle is rated at 6 o’clock, meaning the display is optimized for top-down viewing, but in practice you get decent contrast up to about 45 degrees off-axis. The STN (Super Twisted Nematic) LCD mode gives a blue-gray background with dark blue pixels, which is easier on the eyes than a bright white OLED in low light.

Programming complexity breaks down into three layers: hardware wiring, driver initialization, and graphics rendering. For wiring, you need to connect the SPI pins correctly. Most modules have a 6-pin or 8-pin header with labels like SDA, SCL, CS, DC, RST, and BL. If you’re using an Arduino Uno, you’d connect SDA to pin 11 (MOSI), SCL to pin 13 (SCK), CS to any digital pin (say pin 10), DC to pin 9, and RST to pin 8. The backlight can be controlled with a PWM pin for dimming. That’s a 5-minute solderless breadboard setup. For the ESP32, you can use any GPIO pins for SPI, but hardware SPI is faster. The VSPI bus uses pins 23 (MOSI), 18 (SCK), and 5 (CS) by default. You also need to set the DC pin manually.

Driver initialization is where most people get stuck, but it’s actually simple. The ST7567 needs a sequence like: reset the display (pull RST low for 10 ms), set bias ratio (0xA2 for 1/9 bias), set contrast (0x81 followed by a value), set segment and common direction (0xA0 for normal, 0xC0 for normal), turn on the voltage booster (0x2F), and finally turn on the display (0xAF). That’s about 15 lines of code. If you use a library like u8g2, you don’t even write that—you just call u8g2.begin(). The library handles the entire initialization. For a custom driver, you’d need to read the datasheet, which is 40 pages for the ST7567. But the critical commands are on pages 12-18. I’ve done both, and the library route saves about 2 hours of debugging.

Graphics rendering is the fun part. The display uses a 1024-byte frame buffer (128 columns x 64 rows / 8 bits per row). Each byte represents 8 vertical pixels. To set a pixel at (x, y), you calculate the byte address as buffer[y/8][x] and set the bit at position y%8. That’s a simple bitwise operation. For text, you can store fonts as arrays of bytes. A 5x7 font character takes 5 bytes. To draw a character, you loop through the 5 columns and write the byte to the buffer. The u8g2 library includes dozens of fonts from 4x6 to 24x32, and you can switch between them with a single function call. Drawing a line or rectangle is just a loop over pixels. The library also supports bitmap images, but you need to convert them to the 1-bit monochrome format. Tools like LCD Assistant can do that for you.

Real-world performance numbers: On an Arduino Uno at 16 MHz, updating the entire display takes about 3 ms with hardware SPI at 8 MHz. That’s 333 frames per second theoretical, but you’re limited by the display’s internal refresh rate of about 100 Hz. On an ESP32 at 240 MHz, you can push SPI at 40 MHz, reducing the update time to under 1 ms. For animations, you can use double buffering: draw to a second buffer in RAM, then swap it with the display buffer. That avoids tearing and flicker. The ST7567 supports partial updates via the “set page address” and “set column address” commands, so you can update only a small region instead of the whole screen. For example, updating a 20x20 pixel icon takes about 0.1 ms.

Common pitfalls and how to avoid them: First, the voltage level. Most COG LCD modules run at 3.3V, but some are 5V tolerant. Check the datasheet. If you’re using a 5V Arduino, you might need a level shifter for the SPI lines, though many modules work fine with 5V logic if they have a built-in regulator. Second, the contrast. If you see nothing on the screen, it’s usually because the contrast is set too low or the voltage booster isn’t enabled. Third, the reset pin. Some modules require a hardware reset after power-up, or they stay in sleep mode. A simple RC circuit (10k resistor to VCC, 0.1 uF capacitor to GND) on the RST pin can fix that. Fourth, the backlight. It’s often a separate pin that needs a current-limiting resistor. A typical white LED backlight draws 20 mA at 3.3V, so a 150 ohm resistor works. Without it, you might burn out the LED.

Let’s compare with other display options. A 0.96-inch OLED with the same resolution is easier to program because it uses I2C (only 2 wires) and has massive community support. But the OLED is tiny and expensive per inch. A 2.8-inch TFT with 320x240 resolution requires a larger frame buffer (150 KB) and often needs an external RAM chip or a microcontroller with lots of SRAM. The COG LCD’s 1 KB buffer fits in any microcontroller. A character LCD like the 16x2 HD44780 is easier for text but can’t do graphics. The 3.18 inch COG LCD is the best balance for applications that need a readable display with custom graphics, like a weather station, a digital clock, or a sensor readout.

Development tools and resources: The u8g2 library by Oliver Kraus is the gold standard. It supports over 200 displays and 1000 fonts. The library is actively maintained and documented. You can find examples for Arduino, ESP32, and Raspberry Pi Pico. For the ESP32, you can also use the TFT_eSPI library, but it’s designed for TFTs and requires some tweaking for the ST7567. I recommend starting with the u8g2 “Hello World” example, then modifying it for your display. The library also includes a “page buffer” mode that uses only 128 bytes of RAM instead of the full 1024 bytes, which is useful for memory-constrained microcontrollers like the ATtiny85. But the page buffer mode is slower because it sends data multiple times per frame.

Cost and availability: The 3.18 inch COG LCD module costs around $8-12 in single quantities, compared to $15-20 for a similar-sized TFT. The COG design also means it’s more durable—no separate driver board to break off. The glass is about 1.1 mm thick, and the PCB is 1.6 mm. The module weighs about 15 grams. You can buy it from distributors like Digi-Key, Mouser, or directly from manufacturers. The lead time is usually 2-4 weeks for small orders. If you’re prototyping, get a breakout board with a 2.54 mm pin header. If you’re integrating into a product, you can get the bare glass with a flexible PCB connector.

Code example snippet for Arduino:

#include
U8G2_ST7567_128X64_1_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* rst=*/ 8);
void setup() {
u8g2.begin();
u8g2.setContrast(32);
u8g2.setFont(u8g2_font_6x10_tf);
}
void loop() {
u8g2.firstPage();
do {
u8g2.drawStr(0, 10, "Hello World!");
u8g2.drawLine(0, 20, 127, 20);
} while (u8g2.nextPage());
delay(1000);
}

This code compiles to about 8 KB on an Arduino Uno. The U8G2_R0 parameter sets the rotation (0 degrees). You can change it to U8G2_R1 for 90 degrees rotation if you mount the display sideways.

Advanced features: The ST7567 supports hardware scrolling via the “set scroll line” command (0x40 + line number). You can scroll the entire display up or down by 1 to 64 lines without rewriting the buffer. This is great for scrolling text. The display also has a “sleep mode” that drops current to under 10 uA. You can wake it up with a single command. For battery-powered projects, you can turn off the display between updates. The backlight can also be PWM-controlled for dimming. I’ve used a 1 kHz PWM on an ESP32 to adjust brightness from 0 to 100% without flicker.

Testing and debugging tips: If the display doesn’t work, first check the voltage at the VCC pin with a multimeter. It should be 3.3V or 5V depending on your module. Then check the SPI signals with an oscilloscope or logic analyzer. The MOSI line should show data pulses when you call u8g2.sendBuffer(). The SCK line should have a clean square wave. If you see nothing, check your wiring. Common mistakes: swapping MOSI and MISO (but this display doesn’t use MISO), or connecting CS to ground instead of a pin. Also, some modules have a “LED” pin that controls the backlight, not the display itself. Make sure you’re not confusing it with the DC pin.

Community and support: The u8g2 library has a GitHub repository with over 2000 stars and active issue tracking. The Arduino forum and Stack Overflow have hundreds of threads about 128x64 COG LCDs. If you search for “ST7567 Arduino” you’ll find dozens of tutorials. The datasheet for the ST7567 is available from Sitronix, but it’s a PDF with Chinese translations. The English version is clear enough. For the hardware, the module’s manufacturer usually provides a schematic and pinout diagram. If you’re buying from a distributor, check the product page for a link to the datasheet.

Performance comparison with other displays:

| Feature | 3.18" COG LCD | 0.96" OLED | 2.8" TFT |
|----------------------|-------------------|-------------------|-------------------|
| Resolution | 128x64 | 128x64 | 320x240 |
| Interface | SPI (4 wires) | I2C (2 wires) | SPI/Parallel |
| Frame buffer size | 1 KB | 1 KB | 150 KB |
| Power (backlight off) | 1.5 mA | 20 mA | 50 mA |
| Power (backlight on) | 20 mA | 20 mA | 100 mA |
| Cost (single) | $10 | $5 | $18 |
| Viewing angle | 6 o'clock | 180 degrees | 160 degrees |
| Readability in sunlight | Poor (needs backlight) | Poor | Good with polarizer |
| Programming complexity | Medium | Low | High |

This table shows that the COG LCD is a middle ground. It’s not the cheapest, not the easiest, but it offers the largest screen size for the resolution and the lowest power consumption when the backlight is off. For a project that needs a readable display for text and simple graphics, it’s a solid choice.

Real-world project examples: I’ve used this display in a desktop weather station that shows temperature, humidity, and a 24-hour graph. The graph updates every minute, and the display stays on all day. The ESP32 runs at 80 MHz, and the total power consumption is about 30 mA with the backlight at 50%. The display is readable from 2 meters away. Another project was a digital clock with a large font that shows hours and minutes in 24-pixel tall digits. The font took up the full screen, but the update was smooth. I also built a simple oscilloscope that samples at 10 kHz and displays the waveform. The SPI speed was the bottleneck, but at 40 MHz, the waveform updated at about 30 frames per second, which was enough for audio signals.

Common questions from beginners: “Do I need a level shifter?” If your microcontroller is 3.3V, no. If it’s 5V, check the module’s datasheet. Many modules have a 3.3V regulator on board, so the logic pins are 5V tolerant. “Can I use I2C instead of SPI?” No, this display only supports SPI. Some modules have a parallel interface option, but the COG version is SPI-only. “How do I display an image?” Convert the image to a monochrome bitmap using a tool like Image2LCD, then store it in flash memory. The u8g2 library can draw bitmaps with u8g2.drawXBM(). “Can I use it with a Raspberry Pi?” Yes, but you need to enable SPI and install the u8g2 library for Python. The wiring is the same, but the GPIO pins are different (e.g., MOSI on pin 19, SCK on pin 23). “How long does it last?” The COG LCD has a typical lifetime of 50,000 hours, which is about 5.7 years of continuous use. The backlight LED lasts longer, about 100,000 hours.

Final technical note: The display’


a

About the author

admin

Writing from the floor of the Barberton forge, where the steel is hot and the warranty still means something.