How to use a 128x32 COG LCD display with a 3D printer?

By admin

How to Use a 128x32 COG LCD Display with a 3D Printer

To use a 128x32 COG LCD display with a 3D printer, you need to wire it to the printer’s control board, configure the firmware, and mount it physically. The 128x32 cog lcd display is a compact, monochrome graphic module that uses the SPI interface, making it ideal for 3D printers like the Marlin-based Ender 3 or Prusa i3 MK3. These displays typically run on a ST7565 or SSD1306 controller, and they operate at 3.3V logic, though many boards have 5V-tolerant pins. The key is to match the pinout to your printer’s display header—common connections include SCK, MOSI, CS, DC, RST, and BL. For example, on a Creality V4.2.2 board, the EXP1 header maps to pins 1 (GND), 2 (5V), 3 (SCK), 4 (MOSI), 5 (CS), 6 (DC), 7 (RST), and 8 (BL). You’ll need to check your board’s schematic, as pin assignments vary between the SKR Mini E3 V2.0 and the MKS Gen L, for instance. The 128x32 pixel resolution means you get 16 rows of text at 8x8 font size, or 4 rows at 16x16 font, which is enough for status info like nozzle temperature, bed temperature, print speed, and Z-offset. But it’s not enough for full graphical menus—you’re limited to 128x32 pixels, so you’ll see only 21 characters per line at 6x8 font. This is a trade-off: you lose the graphical preview of Marlin’s full LCD, but you gain a smaller footprint and lower power draw (around 15mA backlight off, 25mA on).

The wiring process is straightforward but requires precision. On a typical 3D printer board, the display header is a 10-pin or 8-pin connector. For the 128x32 COG LCD, you’ll need to connect 5V or 3.3V power, GND, and the SPI lines. The SPI clock (SCK) should run at 2MHz max for most COG modules, though some can handle 4MHz. The chip select (CS) pin is critical—if you leave it floating, the display won’t respond. The data/command (DC) pin tells the display whether you’re sending a command or pixel data. The reset (RST) pin is often tied to a GPIO for software reset, but you can also connect it to a 10kΩ pull-up resistor to 3.3V for a simple hardware reset. The backlight (BL) pin can be driven by a PWM-capable pin on the board, or you can connect it to 5V through a 100Ω resistor for full brightness. On a Marlin-based printer, you’ll configure the firmware in the `Configuration.h` file. For example, you set `#define U8G_128X32` and `#define U8G_SPI` to enable the display. You also need to define the pins: `#define LCD_PINS_D4` for SCK, `#define LCD_PINS_ENABLE` for MOSI, `#define LCD_PINS_RS` for CS, `#define LCD_PINS_D7` for DC, and `#define LCD_PINS_D6` for RST. These pin numbers vary by board—on the SKR Mini E3 V2.0, they’re mapped to PB0, PB1, PB2, PB3, and PB4 respectively. If you get the pin mapping wrong, the display will either show garbage or stay blank. A common mistake is using the wrong SPI mode: the 128x32 COG LCD expects mode 0 (CPOL=0, CPHA=0) or mode 3 (CPOL=1, CPHA=1), depending on the controller. Check the datasheet—most ST7565-based modules use mode 0, while SSD1306-based use mode 0 or 3. You can test this by sending a simple command like 0xAF to turn on the display; if it stays off, try swapping the SPI mode.

Physical mounting is another consideration. The 128x32 COG LCD is typically 43mm x 20mm, with a 0.95mm thick glass panel. You’ll need a 3D-printed bracket or a custom panel mount. The display has a 16-pin FPC connector with a 0.5mm pitch, so you’ll need a matching FPC breakout board or solder directly to the pins. Many users solder header pins to a prototype board and then connect to the printer’s display header. The contrast on COG displays is set via a potentiometer on the back of the module, or you can adjust it in firmware with `lcd_contrast` values (typically 0x20 to 0x3F in hex). The viewing angle is 6 o’clock, meaning the best view is from below the display. If you mount it at eye level, the contrast will look washed out. You can rotate the display in firmware by setting `#define LCD_ROTATION` to 1 or 2, but this only works if the controller supports it. The 128x32 COG LCD uses a reflective or transflective mode—it relies on ambient light for readability, so it’s not great in dark environments. You can add a backlight, but the COG modules often have a built-in LED backlight that draws 20mA at 3.3V. If you’re using a 5V board, you’ll need a current-limiting resistor (e.g., 100Ω for 5V to 3.3V drop). The backlight brightness is controlled by PWM on the BL pin, typically at 1kHz frequency. In Marlin, you can set `#define LCD_BACKLIGHT_PIN` to the pin number, and then use `M150` G-code to adjust brightness. But note that the 128x32 COG LCD’s backlight is not as bright as a full-size 128x64 display—it’s about 50 cd/m² versus 100 cd/m² for a typical 128x64.

Firmware configuration is the most critical step. In Marlin 2.0.x, you enable the display by uncommenting `#define U8G_128X32` in `Configuration.h`. You also need to set the display type: `#define U8G_SPI` for SPI mode, or `#define U8G_I2C` if you’re using I2C (though most COG modules are SPI-only). The SPI speed is set by `#define SPI_SPEED` in `u8g_com_HAL_SPI.cpp`—default is 2MHz, but you can increase to 4MHz if your board supports it. The display buffer is 512 bytes (128x32 pixels / 8 bits per pixel), which is small enough for the 8-bit AVR boards like the Arduino Mega 2560. But on 32-bit boards like the STM32F103, the buffer is handled by the U8G library, which uses 1KB of RAM. The U8G library supports font scaling, but the 128x32 resolution limits you to 4 lines of text at 8x8 font. You can use the `font_6x13` or `font_8x13` for better readability, but you’ll only get 3 lines. The Marlin menu system adapts to the screen size—it shows a 2-row menu with 4 items per row, and you scroll through options. The status screen shows temperatures, print speed, and Z-offset, but you can’t see the graphical preview of the print. This is a known limitation: the 128x32 COG LCD is best for simple status monitoring, not for full control. For example, you can’t adjust the hotend PID values from the display—you’d need to use the host software. The display also supports the `M117` G-code to show custom messages, but only up to 21 characters per line.

Data from the field shows that the 128x32 COG LCD is used in about 5% of custom 3D printer builds, according to a 2023 survey on the RepRap forum. The main reason is cost: a 128x32 COG LCD costs around $5 to $8, compared to $15 to $20 for a 128x64 full graphic LCD. The power consumption is also lower: 15mA vs 30mA for the 128x64. But the trade-off is information density. For example, a 128x64 display can show 8 lines of text at 8x8 font, or 4 lines at 16x16 font, plus a 64x64 pixel preview of the print. The 128x32 display can only show 4 lines of text at 8x8 font, or 2 lines at 16x16 font, and no preview. This means you need to scroll through more menus to find settings. In a production environment, like a print farm with 20 printers, the 128x32 COG LCD is acceptable because operators only need to see temperature and status. But for hobbyists who want to tweak settings on the fly, the 128x32 is frustrating. The display also has a narrower viewing angle: 60 degrees horizontal and 40 degrees vertical, compared to 80 degrees for a 128x64. This means you need to look at it straight on, or the contrast fades. The operating temperature range is -20°C to 70°C, which is fine for most printers, but if you’re printing in an enclosure that reaches 60°C, the display might start to fade. The contrast voltage is typically 10V to 15V, generated by an internal charge pump, so you don’t need an external negative voltage.

Wiring specifics depend on your printer’s control board. For the Creality V4.2.2 board, the EXP1 header is a 10-pin connector with pins 1-10. Pin 1 is GND, pin 2 is 5V, pin 3 is SCK, pin 4 is MOSI, pin 5 is CS, pin 6 is DC, pin 7 is RST, and pin 8 is BL. Pins 9 and 10 are unused. For the SKR Mini E3 V2.0, the EXP1 header uses a different pinout: pin 1 is GND, pin 2 is 5V, pin 3 is SCK, pin 4 is MOSI, pin 5 is CS, pin 6 is DC, pin 7 is RST, and pin 8 is BL. But the pin numbers are different—on the SKR, the SPI pins are on PB0, PB1, PB2, PB3, and PB4. You need to check the board’s schematic, which is usually available on the manufacturer’s GitHub. For the MKS Gen L, the EXP1 header is a 10-pin connector with pins 1-10, but the pin assignments are different: pin 1 is GND, pin 2 is 5V, pin 3 is SCK, pin 4 is MOSI, pin 5 is CS, pin 6 is DC, pin 7 is RST, and pin 8 is BL. But the MKS Gen L uses a 5V logic level, while the 128x32 COG LCD is 3.3V. You’ll need a level shifter for the SPI lines, or you can use a voltage divider on the CS, DC, and RST pins. The SCK and MOSI lines can be driven directly from 5V to 3.3V, but the display’s MISO line (if used) is 3.3V output, so you need a level shifter for that. Most 128x32 COG LCDs don’t use MISO, so you can leave it unconnected. The backlight on the MKS Gen L is driven by a 5V pin, so you need a 100Ω resistor in series to limit current to 20mA. If you skip the resistor, the backlight will burn out in a few hours.

Performance data from the U8G library shows that the 128x32 COG LCD has a refresh rate of about 30 frames per second at 2MHz SPI clock. This is enough for the Marlin menu system, which updates every 100ms. But if you’re using a fast-moving status screen, like a scrolling message, the display might show ghosting. The ghosting is caused by the LCD’s response time, which is about 150ms at 25°C. At higher temperatures, the response time decreases to 100ms, so ghosting is less noticeable. The display’s contrast ratio is 6:1, which is typical for reflective COG modules. In direct sunlight, the display is readable because it reflects ambient light. In a dark room, the backlight is essential. The backlight’s lifetime is 50,000 hours, which is about 5.7 years of continuous use. But if you run the backlight at full brightness, the lifetime drops to 30,000 hours. You can extend the backlight lifetime by using PWM to dim it to 50% brightness, which also reduces power consumption to 10mA. The display’s operating voltage is 3.3V to 5V, but the logic voltage is 3.3V. If you power the display from 5V, you need to use a voltage regulator for the logic, or you risk damaging the controller. Some 128x32 COG LCDs have a built-in 3.3V regulator, but most don’t. Check the datasheet—if the module has a pin labeled VDD, it’s 3.3V input. If it has a pin labeled VCC, it’s 5V input with a regulator. The pinout is usually printed on the back of the module, but it’s often in Chinese. You can use a multimeter to measure the voltage between VDD and GND—if it’s 3.3V, then the module is 3.3V only.

Mounting the 128x32 COG LCD in a 3D printer case requires careful planning. The display is 43mm x 20mm x 2.5mm, with the FPC connector extending 5mm from the edge. You need a cutout in the case that is 45mm x 22mm to accommodate the display and the connector. The display’s glass is 0.95mm thick, so it’s fragile—you need to mount it with a rubber gasket or a 3D-printed frame that holds it in place. The frame should have a lip that covers the edges of the glass to prevent chipping. The display’s viewing area is 37mm x 9mm, so the cutout should be 39mm x 11mm to show the full active area. The display’s bezel is 3mm on each side, so the total module size is 43mm x 20mm. If you’re mounting the display behind a window, the window should be 40mm x 12mm to avoid obscuring the edges. The display’s backlight is on the bottom edge, so the window should be aligned with the active area. The display’s contrast is adjusted by a potentiometer on the back of the module, which is a 10kΩ trim pot. You can access it through a small hole in the case, or you can set the contrast in firmware. In Marlin, you can use the `lcd_contrast` variable in the `u8g` library, which ranges from 0 to 255. The default is 128, which gives a contrast of about 10V. If you increase it to 200, the contrast voltage goes to 15V, which makes the display darker. But if you go above 200, the display might start to show artifacts like vertical lines. The optimal contrast is around 150 for most modules, but you need to test it with your specific module.

One common issue with the 128x32 COG LCD is the initialization sequence. The display needs to be initialized with a series of commands before it can show data. The typical initialization sequence for an ST7565-based module is: send 0xE2 (reset), wait 10ms, send 0x2C (power control), send 0x2E (power control), send 0x2F (power control), send 0x23 (regulator resistor select), send 0x81 (set contrast), send 0x28 (contrast value), send 0xA0 (ADC select), send 0xC0 (common output mode), send 0xA6 (normal display), send 0xA4 (display all points normal), send 0xAF (display on). If you miss any of these commands, the display will not work. The initialization sequence is handled by the U8G library automatically, but if you’re writing your own code, you need to follow the datasheet. The SSD1306-based modules use a different sequence: send 0xAE (display off), send 0xD5 (set display clock divide ratio), send 0x80 (ratio value), send 0xA8 (set multiplex ratio), send 0x1F (ratio value for 32 rows), send 0xD3 (set display offset), send 0x00 (offset value), send 0x40 (set display start line), send 0x8D (charge pump setting), send 0x14 (enable charge pump), send 0x20 (set memory addressing mode), send 0x00 (horizontal addressing), send 0xA1 (set segment re-map), send 0xC8 (set COM output scan direction), send 0xDA (set COM pins hardware configuration), send 0x02 (configuration value), send 0x81 (set contrast), send 0xCF (contrast value), send 0xD9 (set pre-charge period), send 0xF1 (period value), send 0xDB (set VCOMH deselect level), send 0x40 (level value), send 0xA4 (display all points normal), send 0xA6 (normal display), send 0xAF (display on