How to Wire a 3.18 Inch 128x64 COG LCD to a Microcontroller
To wire a 3.18 inch 128x64 cog lcd display to a microcontroller, you need to connect its SPI interface pins—typically CS, MOSI, SCK, DC, RST, and VCC/GND—to the corresponding pins on your MCU, like an Arduino Uno or ESP32. For instance, on an Arduino Uno, connect CS to digital pin 10, MOSI to pin 11, SCK to pin 13, DC to pin 9, RST to pin 8, VCC to 5V, and GND to ground. This specific display, which uses a COG (Chip-on-Glass) design with a SSD1306 or similar controller, operates at 3.3V logic, but many boards can handle 5V power input via an onboard regulator. The display’s resolution is 128x64 pixels, with a 0.96-inch to 3.18-inch diagonal, and the 3.18-inch variant has a pixel pitch of around 0.48mm, giving a clear viewable area of roughly 72mm x 40mm. Always double-check the datasheet for your exact model, as pinouts can vary between manufacturers. For a reliable reference, the 3.18 inch 128x64 cog lcd display typically includes a 8-pin header with SPI, I2C, and parallel options, but SPI is the most common for speed and simplicity.
Let’s break down the hardware specifics. The COG LCD uses a glass substrate with the driver IC bonded directly, reducing thickness to about 2mm and improving contrast. The SPI interface requires four main signals: SCK (serial clock), MOSI (master out slave in), CS (chip select), and DC (data/command). The RST pin resets the display, and VCC powers it. Most 3.18-inch 128x64 COG displays draw about 20-30mA at 5V, with backlight LEDs consuming an additional 40-60mA depending on brightness. The controller, often a SSD1306 or SH1106, supports 4-wire SPI with a maximum clock speed of 10MHz, though 4MHz is safe for most microcontrollers. The display’s contrast ratio is typically 2000:1, and the viewing angle is 120 degrees, making it readable in direct sunlight. The pixel arrangement is monochrome, with white or blue pixels on a dark background, and the driver IC includes 128x64 bits of SRAM for the frame buffer.
For a practical wiring example, use an Arduino Uno. Connect the display’s VCC to the Arduino’s 5V pin, GND to GND, SCK to digital pin 13 (SCK), MOSI to pin 11 (MOSI), CS to pin 10, DC to pin 9, and RST to pin 8. If your display has a BL (backlight) pin, connect it through a 100-ohm resistor to 5V to control brightness. For an ESP32, use 3.3V logic: connect VCC to 3.3V, SCK to GPIO 18, MOSI to GPIO 23, CS to GPIO 5, DC to GPIO 17, RST to GPIO 16, and GND to ground. The ESP32’s 3.3V logic levels are compatible with the display’s 3.3V tolerance, but the 5V Arduino Uno may need level shifters for the SPI lines if the display is not 5V-tolerant. However, many COG LCDs have 5V-tolerant inputs, so check the datasheet. The display’s SPI mode is mode 0 or 3, depending on the controller, but the Adafruit or U8g2 library auto-detects this.
Software setup is straightforward. Use the U8g2 library in Arduino IDE, which supports the SSD1306 controller with the constructor U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI for software SPI, or U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI for hardware SPI. For hardware SPI, you only need to define CS, DC, and RST pins. For example: U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, 10, 9, 8); where 10 is CS, 9 is DC, and 8 is RST. The library handles all initialization, including sending the display’s configuration commands like setting the multiplex ratio to 63 (for 64 rows), display offset to 0, and clock divide ratio to 0x80. The frame buffer is 1024 bytes (128x64/8), and updating the display with u8g2.sendBuffer() takes about 10ms at 4MHz SPI. For text, use fonts like u8g2_font_6x10_tf for 6x10 pixel characters, which fits about 21 characters per line and 6 lines on the display.
Now, let’s talk about power and signal integrity. The display’s internal boost converter generates the necessary voltage for the LCD segments, typically around 12-15V, from the 3.3V or 5V input. This converter draws about 10-15mA during operation. The backlight, if included, is a white LED with a forward voltage of 3.2V at 20mA, so a resistor is needed when running from 5V. For example, a 100-ohm resistor limits current to (5V-3.2V)/100 = 18mA. The SPI signals should have short traces, less than 10cm, to avoid ringing at 4MHz. Use 10k-ohm pull-up resistors on CS and RST if the microcontroller doesn’t have internal pull-ups. The display’s contrast is controlled by a command, typically setContrast(0x7F), where 0x7F is half brightness. The operating temperature range is -20 to 70 degrees Celsius, and the storage range is -30 to 80 degrees Celsius, making it suitable for indoor and some outdoor applications.
For advanced wiring, consider using the I2C interface if your display has it. The I2C pins are SDA and SCL, with a fixed address of 0x3C or 0x3D. Connect SDA to A4 on Arduino Uno, SCL to A5, and use 4.7k-ohm pull-up resistors to 3.3V or 5V. I2C is slower, with a maximum clock of 400kHz, but uses only two wires. The SPI interface, however, is faster for animations or frequent updates. The display’s refresh rate is 60Hz, but with SPI, you can update the entire screen at 100Hz if the MCU is fast enough. The pixel response time is about 10ms, so no ghosting for static images. The display’s duty cycle is 1/64, meaning 64 rows are scanned sequentially, and the frame rate is set by the internal oscillator at 470Hz, divided by the clock divide ratio.
Common issues include incorrect pin mapping, especially with the DC pin, which must be set high for data and low for commands. If the display shows only noise, check the CS pin is pulled low during communication. The RST pin should be held high after initialization, or a hardware reset pulse of 10ms low is needed. The display’s initialization sequence includes setting the display off, setting the charge pump, setting the segment remap, and setting the COM pins hardware configuration. The exact sequence is in the datasheet, but libraries handle it. The display’s memory is organized as 8 pages of 128 bytes each, and you can write to specific pages for partial updates. The COG design means the display is thin and fragile, so handle it by the edges and avoid pressing on the glass.
For a custom PCB, route the SPI traces with a ground plane underneath to reduce noise. The display’s pin pitch is 2.54mm, so standard headers work. The 3.18-inch size has a module outline of 85mm x 45mm, with a viewing area of 72mm x 40mm. The active area has 128 columns and 64 rows, with a pixel size of 0.48mm x 0.48mm and a gap of 0.02mm, giving a fill factor of 96%. The display’s contrast ratio is enhanced by the COG technology, which reduces reflections. The driver IC is bonded to the glass with anisotropic conductive film, so no external components are needed except for the power supply. The display’s logic supply voltage range is 3.0V to 5.5V, but the internal regulator ensures stable operation.
Now, let’s look at a table for common microcontroller pin connections:
| Display Pin | Function | Arduino Uno | ESP32 |
|---|---|---|---|
| VCC | Power (3.3V or 5V) | 5V | 3.3V |
| GND | Ground | GND | GND |
| SCK | SPI Clock | 13 | 18 |
| MOSI | SPI Data | 11 | 23 |
| CS | Chip Select | 10 | 5 |
| DC | Data/Command | 9 | 17 |
| RST | Reset | 8 | 16 |
| BL | Backlight (optional) | Via 100Ω to 5V | Via 100Ω to 3.3V |
This table assumes the display uses a 8-pin header. Some variants have a 14-pin header for parallel interface, but the SPI pins are the same. The backlight pin is often labeled as LEDA or BL, and it’s the anode of the backlight LED. The cathode is connected to GND internally. If you don’t need the backlight, leave it floating. The display’s current consumption without backlight is about 15mA, and with backlight, it’s 60mA at 5V. This is within the Arduino’s 5V regulator capacity, but for battery-powered projects, use a 3.3V supply and a boost converter for the backlight.
For the SPI communication, the display expects the most significant bit first, and the data is latched on the rising edge of SCK. The command byte is sent with DC low, and data bytes with DC high. The first command after reset is to turn off the display, then set the charge pump, then set the display clock divide ratio to 0x80, which sets the oscillator frequency to 470Hz. The multiplex ratio is set to 63 for 64 rows, and the display offset is set to 0. The segment remap is set to 0xA1 for left-to-right mapping, and the COM pins hardware configuration is set to 0x12 for sequential COM pins. The contrast is set to 0x7F, and the display is turned on. This sequence is standard for SSD1306, but for SH1106, the memory layout is different, with 132 columns instead of 128, so the library handles it.
If you’re using a Raspberry Pi Pico, wire the display to SPI0: SCK to GP2, MOSI to GP3, CS to GP5, DC to GP4, RST to GP6, VCC to 3.3V, and GND to ground. Use the MicroPython U8g2 library or the ssd1306.py driver. The Pico’s SPI clock can go up to 20MHz, but 10MHz is safe. The display’s frame buffer is updated with oled.show(), which takes about 5ms. For a STM32 board, use the STM32CubeIDE with the HAL library, and configure SPI1 with pins PA5 (SCK), PA7 (MOSI), PA4 (CS), PA3 (DC), and PA2 (RST). The display’s initialization is similar, and the library is available for STM32.
One important detail: the display’s COG design means the driver IC is on the glass, so the flex cable is delicate. The cable has a pitch of 1.0mm, so use a 1.0mm FPC connector or solder directly to the pads. The pads are tin-plated, so soldering with a fine tip at 300°C works. The display’s thickness is 2.2mm, and the glass is 1.1mm thick, so it’s not flexible. The viewing angle is 120 degrees, but the contrast drops at extreme angles. The display’s operating voltage for the LCD is 12V, generated by the internal charge pump, which uses capacitors. The charge pump efficiency is about 80%, so the input current is higher than the output current. The display’s temperature range is -20 to 70 degrees Celsius, but the contrast varies with temperature, so the library includes temperature compensation commands.
For troubleshooting, if the display remains blank, check the power supply voltage at the display’s VCC pin. Use a multimeter to measure 3.3V or 5V. Then check the SPI signals with an oscilloscope: the SCK should show a square wave, MOSI should show data, and CS should go low during communication. The DC pin should toggle between low and high. The RST pin should be high after the reset pulse. If the display shows vertical lines, the initialization sequence is wrong, or the multiplex ratio is set incorrectly. If the display shows horizontal lines, the COM pins configuration is wrong. The library’s default settings work for most displays, but some Chinese clones need different initialization. The display’s controller can be identified by the driver IC’s markings, like SSD1306 or SH1106, which are on the flex cable.
In terms of performance, the display’s update rate is limited by the SPI speed and the MCU’s processing power. At 4MHz SPI, updating the entire 1024-byte buffer takes 2.6ms, but the library adds overhead for font rendering. For text, the U8g2 library can render 10 characters per millisecond with a small font. For graphics, drawing lines or circles is slower. The display’s internal SRAM is double-buffered, so you can write to the buffer while the display is updating, but the library uses a single buffer. The display’s power consumption is 20mA at 3.3V, which is 66mW, and with backlight, it’s 200mW. This is efficient for a 3.18-inch display, making it suitable for battery-powered devices like thermometers or data loggers.
For a final hardware check, use a breadboard with jumper wires. Keep the wires short, under 10cm, to avoid noise. The display’s backlight can be PWM-controlled by connecting the BL pin to a PWM-capable pin on the MCU, like pin 9 on Arduino Uno, with a 100-ohm resistor. The PWM frequency should be 1kHz to avoid flicker. The display’s contrast can be adjusted in software by sending the setContrast command with a value from 0 to 255. Higher values increase the voltage on the LCD segments, making the pixels darker. The default is 0x7F, which is 127. The display’s sleep mode reduces current to 1µA, and it can be woken up by sending a display on command. The sleep mode is entered by sending the display off command and setting the charge pump to off.
One more thing: the display’s pinout on the 3.18-inch module might have a different order. The common pinout from left to right is: GND, VCC, SCK, MOSI, CS, DC, RST, BL. But some manufacturers swap CS and DC, so check the datasheet. The display’s model number is usually printed on the back of the PCB, and the datasheet is available online. The display’s SPI mode is 0, meaning CPOL=0 and CPHA=0, which is the default for most microcontrollers. The display’s maximum SPI clock is 10MHz, but 4MHz is safe for long wires. The display’s initialization takes about 100ms, including the reset pulse. The display’s memory is organized as 8 pages, each 128 bytes, and you can write to individual pages for partial updates. This is useful for updating only the changed area, reducing power consumption.
To sum up the wiring process: connect power, ground, and the four SPI pins, then initialize the display with the library. The display’s 128