How to connect a 3.18 inch 128x64 COG LCD to a PC?
How to Connect a 3.18 Inch 128x64 COG LCD to a PC
To connect a 3.18 inch 128x64 cog lcd display to a PC, you need a microcontroller or a USB-to-SPI bridge, because most PCs don’t have native SPI or parallel interfaces. The simplest route is using an Arduino board (like Uno or Nano) as an intermediary. The LCD connects to the Arduino via SPI pins, and the Arduino talks to the PC over USB. You then run a Python script or Arduino IDE sketch to send data. For a direct PC connection without Arduino, you can use a USB-to-SPI adapter like the FTDI FT232H, which emulates SPI over USB. This lets you control the display directly from Python or C++ on your PC. The display itself uses a controller like the ST7565 or SSD1306 (check your specific model). The 3.18 inch 128x64 COG LCD typically operates at 3.3V logic, but many versions are 5V tolerant on the SPI lines. Always verify the datasheet for your exact unit. The pinout usually includes CS (chip select), DC (data/command), RST (reset), SCK (clock), and MOSI (data). Some modules also have a backlight pin (LED+ and LED-). The screen’s resolution is 128x64 pixels, monochrome, with a 3.18 inch diagonal. The pixel pitch is about 0.49 mm, giving a visible area of roughly 62.7 mm x 31.4 mm. The COG (Chip-on-Glass) design means the driver IC is bonded directly to the glass, reducing thickness to about 1.5 mm. This display uses a 12-pin or 8-pin FPC connector, depending on the variant. The SPI clock speed can go up to 10 MHz, but for long wires, keep it under 4 MHz to avoid signal degradation. The power consumption is around 1.5 mA typical for the LCD, plus 20-30 mA for the backlight if using an LED. The contrast ratio is rated at 1000:1, and the viewing angle is 6 o’clock, meaning best visibility from the bottom. The display is often used in industrial panels, medical devices, and handheld instruments because of its low power and thin profile. For a PC connection, the most practical setup is this: PC (USB) -> Arduino (SPI) -> 3.18 inch 128x64 cog lcd display. The Arduino acts as a USB-to-SPI bridge. You can also use a Raspberry Pi, but that’s overkill for just driving a display. If you want a direct USB connection, the FT232H breakout board from Adafruit is a solid choice. It costs around $15 and provides a USB 2.0 full-speed interface. You wire it to the LCD’s SPI pins, then use the libftdi or pyftdi library in Python to send commands. The FT232H can generate SPI clock up to 30 MHz, but the LCD’s max is 10 MHz, so you’ll cap it there. The Python script will need to handle the initialization sequence: reset the display, set the bias, set the contrast (usually register 0x81), and set the segment and common output direction. The ST7565 controller, for example, requires a specific sequence of commands: 0xE2 (reset), 0x2C (boost on), 0x2E (regulator on), 0x2F (follower on), 0x81 (contrast set), 0x27 (contrast value), 0xA0 (segment direction), 0xC8 (common direction), 0xA2 (bias set), 0xAF (display on). The whole initialization takes about 50 ms. After that, you can write pixel data by setting the column and page addresses. The 128x64 display is organized into 8 pages (each page is 8 pixels tall, 128 columns wide). To write a full frame, you send 128 x 8 = 1024 bytes of data. At 10 MHz SPI, that’s about 0.1 ms per frame, but the LCD’s internal update rate is slower, around 1-2 ms. So you can achieve 60 fps easily. The display’s refresh rate is typically 60 Hz, but you can lower it to save power. The COG LCD’s glass is about 0.7 mm thick, and the total module thickness is 1.5 mm including the FPC. The FPC has a pitch of 0.5 mm or 1.0 mm, depending on the manufacturer. The connector on the PC side (if using a breakout) needs to match. Most hobbyists use a ZIF connector or solder wires directly. The backlight is usually a single white LED, with a forward voltage of 3.0-3.2V and current of 20 mA. You can power it from the Arduino’s 3.3V pin through a 10-ohm resistor. The LCD’s logic supply is also 3.3V, but the SPI lines can be 5V if the controller is 5V tolerant. The ST7565 is 5V tolerant on the digital inputs, but the SSD1306 (if used) is strictly 3.3V. So check the datasheet. The 3.18 inch size is unusual; most 128x64 displays are 2.4 or 2.8 inches. The 3.18 inch version has a larger pixel size, making it easier to read from a distance. The pixel pitch is 0.49 mm, compared to 0.38 mm for a 2.4 inch. The viewing area is 62.7 mm x 31.4 mm, which is about 2.47 inches x 1.24 inches. The overall module dimensions are typically 70 mm x 40 mm x 1.5 mm. The weight is about 10 grams. The display uses a reflective or transflective polarizer, so it works without backlight in bright ambient light. The contrast ratio without backlight is about 8:1, and with backlight it’s 1000:1. The operating temperature range is -20°C to +70°C, and storage is -30°C to +80°C. The SPI interface uses 4 wires: CS, DC, SCK, MOSI. Some modules also have a MISO pin, but it’s not used for writes. The display is write-only, so you don’t read back data. The CS pin is active low. The DC pin selects command (low) or data (high). The RST pin is active low, and you need to hold it low for at least 1 µs during reset. The initialization sequence must be sent after power-up. The typical power-up sequence: apply VDD (3.3V), wait 10 ms, then apply RST low for 1 µs, then high. Then send the commands. The display’s internal oscillator runs at about 200 kHz, and it generates the necessary voltages for the LCD drive. The boost circuit uses a charge pump to generate VOUT (typically 10-12V) for the LCD bias. The bias is set by command 0xA2 for 1/9 bias (common for 64 rows). The contrast register (0x81) sets the voltage level. The default contrast value is 0x1F, but you can adjust it from 0x00 to 0x3F. Higher values increase contrast but also increase power consumption. The display’s power consumption at 3.3V is about 1.5 mA for the LCD, plus 0.5 mA for the charge pump. The backlight adds 20 mA at 3.3V. So total is about 22 mA. That’s low enough to run from a PC’s USB port (500 mA max). The Arduino’s 3.3V regulator can supply up to 150 mA, so it’s fine. If you use the FT232H, it also has a 3.3V output at 50 mA, which is enough for the LCD but not the backlight. You’ll need an external 3.3V supply for the backlight or use a resistor to limit current from the USB. The FT232H’s 3.3V output is limited to 50 mA, so the backlight (20 mA) plus LCD (1.5 mA) is fine, but you’re close to the limit. Better to use the USB 5V with a 100-ohm resistor for the backlight. The resistor value: R = (5V - 3.2V) / 0.02A = 90 ohms, so use 100 ohms. That gives 18 mA, which is fine. The LCD’s logic supply should be 3.3V, so you need a voltage regulator if using 5V. The Arduino’s 3.3V pin is fine. The FT232H has a 3.3V output. The wiring is straightforward: connect SCK to SCK, MOSI to MOSI, CS to a GPIO pin, DC to a GPIO pin, RST to a GPIO pin. On the Arduino, you can use pins 13 (SCK), 11 (MOSI), 10 (CS), 9 (DC), 8 (RST). On the FT232H, you use the SPI pins: D0 (SCK), D1 (MOSI), D2 (CS), D3 (DC), D4 (RST). The library for Arduino is the U8g2 library, which supports many controllers. For the FT232H, you can use the Adafruit CircuitPython library for ST7565 or SSD1306. The Python code is simple: import board, busio, adafruit_st7565. Then create the SPI object, and the display object. Then use display.image() to send a bitmap. The display’s frame buffer is 128x64 pixels, which is 1024 bytes. You can create a bitmap using PIL or a simple list. The U8g2 library for Arduino supports fonts, graphics, and text. You can draw text at any size. The display’s resolution is enough for 8 lines of 8-pixel tall text, or 4 lines of 16-pixel tall text. The font size is limited by the pixel grid. The display’s controller supports hardware scrolling, but it’s rarely used. The ST7565 has a built-in character generator, but it’s for 5x7 fonts. Most people use the U8g2 library for more flexibility. The library handles the initialization and data transfer. You just call u8g2.begin() and then u8g2.sendBuffer(). The library uses the SPI hardware on the Arduino, which is fast. The maximum SPI speed is 8 MHz on the Uno, but the display can handle 10 MHz. So it’s fine. The display’s response time is about 100 µs per command, but the SPI transfer is faster. The total time to update the full screen is about 1 ms at 8 MHz. That’s 1000 fps, but the display’s internal update rate is 60 Hz, so you won’t see flicker. The display’s contrast is adjustable via software. You can set it to a value that works best for your viewing angle. The 6 o’clock viewing angle means the display is designed to be viewed from the bottom. If you need a different viewing angle, you can flip the display using the segment and common direction commands. The command 0xA0 sets the segment direction (normal or reversed), and 0xC0 sets the common direction (normal or reversed). You can also mirror the display using these commands. The display’s pinout is usually labeled on the FPC. The 12-pin version has pins: 1 (VDD), 2 (GND), 3 (CS), 4 (RST), 5 (DC), 6 (SCK), 7 (MOSI), 8 (MISO), 9 (LED+), 10 (LED-), 11 (NC), 12 (NC). The 8-pin version omits the MISO and NC pins. The MISO pin is not used for write-only displays. The CS pin must be pulled low to select the display. If you have multiple SPI devices, you can share the SCK and MOSI lines, but each device needs its own CS pin. The display’s input logic is CMOS, with thresholds at 0.3xVDD and 0.7xVDD. At 3.3V, the low threshold is 1.0V, high is 2.3V. So 3.3V logic works fine. 5V logic will also work if the controller is 5V tolerant. The ST7565 is 5V tolerant, but the SSD1306 is not. So check the controller. The 3.18 inch display often uses the ST7565 because it’s a common controller for larger COG displays. The SSD1306 is more common for smaller OLEDs. The COG LCD is not OLED; it’s a monochrome STN LCD with a yellow-green or white background. The backlight color is usually white, but you can get blue or green. The display’s polarizer is reflective, so it works without backlight. The contrast is best in ambient light. The backlight is just for low-light conditions. The display’s lifetime is typically 50,000 hours for the backlight, and the LCD itself has a lifetime of 100,000 hours. The storage temperature range is wider than the operating range. The display’s glass is sensitive to mechanical stress, so handle it carefully. The FPC is flexible but can be damaged if bent sharply. The connector on the LCD side is a ZIF socket, so you need to insert the FPC straight and lock it. The pitch is 0.5 mm, so a standard 0.5 mm FPC connector works. The breakout board should have a matching connector. If you solder wires directly, use a fine tip and low temperature (300°C). The FPC pads are gold-plated, so they solder easily. The display’s power consumption is low enough that you can run it from a USB port without external power. The Arduino’s USB port provides 5V, and the Arduino’s 3.3V regulator supplies the LCD. The FT232H also gets power from USB. The total current draw is under 100 mA, so any USB port works. The software side is the main challenge. For Arduino, you install the U8g2 library via the Library Manager. Then you write a sketch that includes U8G2_ST7565_128X64_1_HW_SPI u8g2(U8G2_R0, CS, DC, RST); The U8G2_R0 is the rotation (0 degrees). You can also use U8G2_R1, R2, R3 for 90, 180, 270 degrees. Then in setup(), you call u8g2.begin(); and set the contrast with u8g2.setContrast(0x20); Then in loop(), you clear the buffer, draw text, and send the buffer. The library supports many fonts, including proportional fonts. You can also draw bitmaps. For Python on the PC, you use the Adafruit CircuitPython library. Install it with pip install adafruit-circuitpython-st7565. Then you need the Blinka library for the FT232H. The code is: import board, busio, digitalio, adafruit_st7565. Then spi = busio.SPI(board.SCK, board.MOSI); cs = digitalio.DigitalInOut(board.D2); dc = digitalio.DigitalInOut(board.D3); rst = digitalio.DigitalInOut(board.D4); display = adafruit_st7565.ST7565(spi, cs, dc, rst); Then display.show() to display the buffer. You can create a bitmap using the adafruit_imageload library. The display’s pixel format is 1-bit per pixel, so you need a monochrome image. The image should be 128x64 pixels. You can load a PNG or BMP file. The display’s refresh rate is limited by the USB transfer speed. The FT232H’s USB 2.0 full-speed is 12 Mbps, but the SPI speed is 10 MHz, so the bottleneck is the USB. The Python script will send data at about 1 MB/s, which is enough for 1000 frames per second, but the display’s internal update is 60 Hz. So you can update at 60 fps easily. The display’s response time is about 10 ms, so you won’t see ghosting. The contrast is adjustable, and you can set it to a value that works best for your room lighting. The display’s viewing angle is 6 o’clock, meaning the best view is from the bottom edge. If you mount the display vertically, you need to rotate the image. The U8g2 library handles rotation. The Python library also handles rotation with the rotation parameter. The display’s pinout is standard, but always double-check with the datasheet. The 3.18 inch 128x64 COG LCD is a robust, low-power display for PC-based projects. The connection method depends on your preference for a microcontroller or a direct USB bridge. The Arduino route is easier for beginners, while the FT232H route is more direct for software developers. The display’s SPI interface is simple, and the libraries are mature. The cost of the display is around $10-15, the Arduino is $20, and the FT232H is $15. So total is under $35. The display’s size is larger than typical 128x64 screens, making it suitable for reading text from a distance. The pixel size is 0.49 mm, which is comfortable for reading. The display’s contrast is high, and the backlight is bright enough for indoor use. The display’s power consumption is low, so it can run on battery power if needed. The PC connection via USB is straightforward. The software libraries handle all the low-level details. You just need to wire the pins correctly and set the contrast. The display’s initialization is automatic in the libraries. The only manual step is setting the contrast if you want a different value. The default contrast is usually 0x20, which is fine for most cases. The display’s temperature range is wide, so it works in most environments. The display’s glass is thin, so it’s fragile. Mount it in a case or use a bezel. The FPC is flexible, but don’t
Next from the studio
Begin a conversation about your residence.