Skip to content
Flapierre Flapierre
Atelier Journal

How to connect a 3.18 inch 128x64 COG LCD to a breadboard?

Filed under
Journal
Published
Author
admin

To connect a 3.18 inch 128x64 COG LCD to a breadboard, you need to identify the pinout of the display module, which typically includes power, ground, SPI interface lines (CS, DC, MOSI, SCK, and optionally RESET), and backlight control. The specific module I’m referencing is the 3.18 inch 128x64 cog lcd display from DisplayModule, which uses a COG (Chip-on-Glass) design with a built-in SSD1306 or compatible controller. This display operates at 3.3V logic, but can handle 5V power for the backlight if you use a current-limiting resistor. The breadboard connection requires careful wiring because the module has a 2.54mm pitch pin header, but it’s not always pre-soldered. You’ll need to solder a male header strip to the module’s pads, then insert it into the breadboard. The pinout is usually labeled on the back of the PCB: VCC (3.3V), GND, SCL (SCK), SDA (MOSI), CS (chip select), DC (data/command), and RST (reset). Some versions also have a BL (backlight) pin. Use jumper wires to connect these to your microcontroller or development board, like an Arduino Uno or ESP32. For a stable connection, add a 10µF capacitor between VCC and GND on the breadboard to filter noise. The SPI clock speed should be limited to 10 MHz max to avoid signal integrity issues on long breadboard wires. The display’s resolution is 128x64 pixels, monochrome, and the COG design reduces thickness to about 1.5mm, making it fragile—handle with care during breadboard insertion.

Power Requirements and Voltage Levels
The 3.18 inch 128x64 COG LCD requires a 3.3V supply for the logic and display driver, drawing about 20mA during normal operation with the backlight off. The backlight LED typically needs 3.0V to 3.3V at 20-30mA, so you can power it from the same 3.3V rail if your microcontroller can supply enough current. However, many breadboard setups use a 5V Arduino, so you’ll need a 3.3V regulator (like the AMS1117-3.3) to drop the voltage. The module’s absolute maximum ratings: VCC 3.6V, logic input pins 3.6V, and backlight pin 3.6V. Never connect 5V directly to any pin except the backlight if you use a series resistor (e.g., 100Ω for 5V to limit current to 20mA). The breadboard power rails should be split: one rail for 5V (for the microcontroller) and one for 3.3V (for the display). Use a multimeter to verify the voltage before connecting. The display’s current consumption jumps to 80mA with the backlight on full, so a 3.3V regulator with at least 500mA capacity is recommended, like the LM1117-3.3. If you’re using an ESP32, its 3.3V output can handle the display directly, but avoid running long wires (over 20cm) to prevent voltage drop.

SPI Interface Wiring Details
The SPI interface uses four main lines: SCK (serial clock), MOSI (master out slave in), CS (chip select), and DC (data/command). The RST (reset) pin is optional but recommended—connect it to a GPIO pin for software reset. On the breadboard, use separate rows for each signal to avoid shorts. The typical wiring for an Arduino Uno: connect display VCC to 3.3V, GND to GND, SCK to pin 13, MOSI to pin 11, CS to pin 10, DC to pin 9, and RST to pin 8. For the backlight, connect BL to 3.3V through a 100Ω resistor (or directly if using a 3.3V supply). The SPI mode is mode 0 (CPOL=0, CPHA=0) with the data clocked on the rising edge. The display’s controller accepts 8-bit commands and data, with the DC pin high for data and low for commands. The CS pin must be pulled low before each transaction. The maximum SPI clock speed is 10 MHz, but breadboard parasitic capacitance (about 2-5 pF per inch of wire) can cause signal ringing at higher speeds—stick to 4 MHz or lower for reliable operation. Use a logic analyzer or oscilloscope to check the signals if you see glitches. The display’s initialization sequence requires sending a series of commands, like setting the display on, contrast, and memory addressing mode. The typical initialization takes about 100ms, and you must wait 10ms after power-up before sending commands.

Breadboard Layout and Physical Considerations
The 3.18 inch 128x64 COG LCD has a PCB size of about 84mm x 44mm, with a 2.54mm pitch pin header on one edge. The COG design means the driver IC is bonded directly to the glass, so the module is thin but the glass is exposed—avoid bending or pressing on the display area. When inserting into a breadboard, use a 8-pin male header (2x4 or 1x8) soldered to the module’s pads. The pads are typically 0.1-inch apart, so a standard breadboard row works. Insert the header so the module sits above the breadboard, leaving clearance for the glass. If the breadboard is on a bench, use standoffs or a piece of foam under the display to prevent it from touching the table. The breadboard’s power rails should be near the module to keep wires short. Use M-M jumper wires of 10cm or less to reduce inductance. For the backlight, if you’re using a separate 5V supply, add a 100Ω resistor in series with the BL pin—this limits current to 20mA, extending LED life. The resistor can be inserted directly into the breadboard. Avoid using long wires for the SPI lines; twist them with ground wires to reduce noise. The display’s contrast is set via software, but the hardware contrast pin (if present) is usually not used in COG modules. The viewing angle is 6 o’clock, meaning the display is designed to be viewed from below—mount it upright on the breadboard.

Microcontroller Compatibility and Code Examples
Most microcontrollers with SPI hardware can drive this display. For the Arduino Uno, use the Adafruit SSD1306 library or the U8g2 library. The initialization code sets the display to 128x64, SPI mode, with the correct pins. Here’s a typical setup: U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);. For ESP32, use hardware SPI with pins: VSPI (MOSI=23, SCK=18, CS=5, DC=4, RST=2). The breadboard wiring for ESP32 is similar but use 3.3V logic directly. The display’s buffer is 1024 bytes (128x64/8), so you can update the entire screen in about 10ms at 4 MHz SPI. For Raspberry Pi, use the spidev library and connect to GPIO pins (MOSI=19, SCK=23, CS=24, DC=25, RST=18). The Pi’s 3.3V logic is compatible, but the backlight may need a transistor if you want PWM control—use a 2N2222 NPN transistor with base resistor to GPIO, collector to display BL, emitter to GND. The breadboard setup for Pi requires level shifters only if you’re using 5V logic, but the display is 3.3V tolerant. The maximum SPI clock on Pi is 32 MHz, but start at 1 MHz for breadboard stability. The display’s controller supports hardware scrolling and page addressing, but the library handles that. Test the connection with a simple “Hello World” sketch before complex graphics. The display’s power-on reset circuit is internal, but you can also toggle the RST pin low for 10µs to reset.

Troubleshooting Common Breadboard Issues
If the display doesn’t light up or shows garbage, check these in order: 1) Measure VCC at the display pin—should be 3.3V ±0.1V. 2) Verify GND continuity with a multimeter. 3) Check SPI pin connections: SCK should have a clock signal when sending data, MOSI should show data pulses, CS should go low during transactions. 4) Ensure the DC pin is toggling between high and low for commands vs data. 5) The RST pin must be high after power-up—if floating, it can cause a reset loop. 6) If the backlight is on but no pixels, the contrast register might be zero—send a command for contrast 0x7F (128). 7) Breadboard wires can cause intermittent connections—push them firmly into the board. 8) Avoid using the same SPI bus for multiple devices without proper CS handling—the display’s CS must be unique. 9) The display’s operating temperature range is -20°C to 70°C, so if your breadboard is near a heat source, it may fail. 10) If using a 5V Arduino, the 3.3V regulator on the board may not supply enough current for the display plus backlight—use an external 3.3V regulator. The display’s typical failure modes: no display (check power), partial display (check SPI clock polarity), or flickering (check CS and reset timing). Use a 10kΩ pull-up resistor on the RST pin if your microcontroller doesn’t drive it high. The breadboard’s parasitic capacitance can cause the SPI clock to have slow edges—add a 100pF capacitor from SCK to GND to filter noise if needed. The display’s contrast is temperature-dependent, so you may need to adjust the contrast register in code.

Advanced Wiring for Backlight Control
The backlight LED on the 3.18 inch 128x64 COG LCD can be controlled via PWM for brightness adjustment. On a breadboard, connect the BL pin to a NPN transistor (e.g., 2N2222) with collector to BL, emitter to GND, and base to a GPIO pin through a 1kΩ resistor. The transistor acts as a switch, allowing up to 30mA. For PWM, use a frequency of 1 kHz to avoid flicker. The backlight forward voltage is 3.2V typical, so if you’re powering from 5V, the transistor drops 0.2V, leaving 4.8V across the LED and resistor. Use a 100Ω resistor in series with the BL pin to limit current to 20mA. If you’re using a 3.3V supply, the resistor can be 10Ω or omitted if the supply is stable. The breadboard layout for this: place the transistor in a separate row, with the base resistor connected to the GPIO jumper. The display’s backlife consumes 60mA at full brightness, so ensure your 3.3V regulator can handle the total load (display 20mA + backlight 60mA = 80mA). The PWM duty cycle should be 0-100% in software, but start at 50% to test. The display’s lifetime is rated at 50,000 hours for the backlight at 20mA, so avoid overdriving. The COG design has no backlight diffuser, so the brightness is uniform across the 128x64 area. For breadboard testing, you can also just connect BL to VCC through a resistor for constant on. The display’s datasheet specifies the backlight pin as 3.3V max, so never connect it to 5V directly.

Signal Integrity and Noise Reduction
Breadboard wires act as antennas for electromagnetic interference, especially at SPI clock frequencies above 1 MHz. The 3.18 inch 128x64 COG LCD’s SPI lines are sensitive to noise because the display controller is on the glass, which has longer traces. To reduce noise, keep all wires under 15cm, and use twisted pairs for SCK and MOSI with ground wires. Add a 0.1µF ceramic capacitor between VCC and GND at the display’s power pins on the breadboard. For longer runs, use a 100Ω series resistor on each SPI line to dampen reflections. The display’s input capacitance is about 10pF per pin, so the RC time constant with a 100Ω resistor is 1ns, which is fine for 4 MHz. If you see ghosting or missing pixels, the SPI clock may be too fast—reduce to 1 MHz. The breadboard’s internal capacitance between rows is about 2pF, so cross-talk between adjacent wires is minimal if you keep a ground wire between signal lines. Use a dedicated ground plane on the breadboard by connecting all GND pins to a common rail. The display’s reset pin can be triggered by noise—add a 10kΩ pull-up resistor to 3.3V on the RST pin if your microcontroller doesn’t drive it. The display’s controller also has a built-in power-on reset, but it’s triggered by a voltage threshold of 2.5V, so if your 3.3V rail ramps slowly, the reset may not work—add a 0.1µF capacitor from RST to GND to delay the reset. The display’s SPI mode is 0, but some libraries default to mode 3—check your code. The display’s maximum data rate is 10 MHz, but at 4 MHz, the pixel update time for a full screen is 8ms, which is fast enough for animations.

Power Supply Decoupling and Stability
The 3.18 inch 128x64 COG LCD draws peak current during SPI transactions, especially when updating the display buffer. The breadboard’s power rails have inductance, causing voltage dips. Use a 10µF electrolytic capacitor and a 0.1µF ceramic capacitor in parallel at the display’s VCC pin on the breadboard. The electrolytic handles low-frequency dips, the ceramic handles high-frequency noise. If your 3.3V regulator is far from the display (over 20cm), add another 10µF cap at the regulator output. The display’s backlight current can cause a 50mV drop on a 3.3V rail with 100mA load—ensure the regulator has good load regulation (e.g., LM1117 has 0.1% typical). For battery-powered breadboard setups, use a low-dropout regulator like the MCP1700-3.3 with a 100µF capacitor at the input. The display’s current consumption is stable, but the SPI bus can cause 10mA transients. The display’s controller has an internal voltage doubler for the display drive, which generates up to 15V—this is isolated from the logic supply, so no extra noise. The breadboard’s power rail should be rated for at least 1A if you’re using multiple modules. The display’s absolute maximum VCC is 3.6V, so a 3.3V regulator with 1% tolerance is fine. If you’re using a 5V Arduino, the onboard 3.3V regulator can supply 150mA, which is enough for the display alone but not with backlight—use an external regulator. The display’s ground plane on the PCB is minimal, so a good breadboard ground connection is critical—use a thick wire for GND.

Testing and Verification Steps
After wiring the 3.18 inch 128x64 COG LCD on the breadboard, power up the system and measure the voltage at the display’s VCC pin with a multimeter—should be 3.3V ±0.1V. Then, check the backlight by applying 3.3V to the BL pin through a 100Ω resistor—the display should glow uniformly. If not, the backlight LED may be reversed polarity (check datasheet). Next, upload a simple test sketch that initializes the display and draws a pixel at (0,0). If the pixel doesn’t appear, use a logic analyzer to check SPI signals: SCK should have pulses, MOSI should show data, CS should go low for 8 clock cycles, and DC should be low for commands. The display’s initialization sequence should send 0xAE (display off), 0xD5 (set display clock divide), 0x80, 0xA8 (set multiplex ratio), 0x3F, 0xD3 (set display offset), 0x00, 0x40 (set start line), 0x8D (enable charge pump), 0x14, 0x20 (set memory mode), 0x00, 0xA1 (set segment remap), 0xC8 (set COM scan direction), 0xDA (set COM pins), 0x12, 0x81 (set contrast), 0xCF, 0xD9 (set pre-charge), 0xF1, 0xDB (set VCOMH), 0x40, 0xA4 (display on resume), 0xA6 (set normal display), 0xAF (display on). If the display still shows nothing, the contrast may be too low—set it to 0x7F (128). The display’s buffer