How to multiplex a 1.3 inch 240x240 display?
How to multiplex a 1.3 inch 240x240 display
You multiplex a 1.3 inch 240x240 display by using a driver IC that supports a matrix-addressed pixel array, typically the ST7789V or GC9A01, which are designed for SPI-based communication. These displays have a resolution of 240 pixels per row and 240 pixels per column, totaling 57,600 individual pixels. Multiplexing here refers to the row-column scanning technique where the driver IC activates one row at a time while applying data to all columns, then quickly moves to the next row. This happens at a refresh rate of 60 Hz to 80 Hz, meaning each row gets updated every 1/60th of a second, but the actual row scan time is about 0.000069 seconds per row (1/60 divided by 240 rows). The ST7789V driver handles this internally with a 240x240 RAM buffer, so you don't manually sequence rows in code—you just send pixel data via SPI at a clock rate of 10 MHz to 30 MHz. For example, at 20 MHz SPI clock, transferring one byte takes 0.4 microseconds, and a full frame of 57,600 pixels (each 16-bit color) requires 115,200 bytes, so a complete frame upload takes roughly 46 milliseconds (115,200 bytes * 8 bits/byte / 20,000,000 bits/second). That's fast enough for smooth animations, but you need to account for the display's internal timing: the ST7789V requires a vertical back porch of 8 lines and a horizontal back porch of 10 pixels per line to stabilize the signal. If you're using a microcontroller like an ESP32 or STM32, you can optimize by using DMA (Direct Memory Access) to send SPI data without CPU intervention, which reduces overhead. For a practical setup, connect the display's CS (chip select) to a GPIO pin, DC (data/command) to another pin, RESET to a third, and SCLK/MOSI to the SPI bus. The power supply must deliver 3.3V at 20 mA to 40 mA for the backlight and 2.8V to 3.3V for the logic, depending on the module. The 1.3 inch 240x240 ips display uses a 4-wire SPI interface, which is the standard for multiplexing because it reduces pin count compared to parallel interfaces. The multiplexing gain comes from the fact that you only need 6 wires (including power) to control 57,600 pixels, versus a parallel interface that would require at least 18 wires for 8-bit data plus control lines. The trade-off is bandwidth: SPI at 20 MHz gives you a theoretical maximum frame rate of 21.7 FPS if you send full frames continuously, but in practice, you can achieve 30 FPS to 60 FPS by using partial updates or by reducing color depth to 12-bit (RGB444) which cuts data per pixel from 2 bytes to 1.5 bytes. The ST7789V also supports window addressing, where you define a rectangular region to update, which is critical for multiplexing efficiently—for instance, updating only a 100x100 pixel area reduces data transfer to 20,000 bytes, taking 8 milliseconds at 20 MHz. This is how you achieve smooth UI updates on low-power microcontrollers. The display's internal row driver uses a charge-sharing technique to reduce power: each row capacitor is pre-charged to half the voltage before switching, which cuts dynamic power by 50% compared to direct drive. The pixel array itself uses a thin-film transistor (TFT) structure with a storage capacitor per pixel, holding the charge for the entire frame period. The refresh rate is set by the oscillator inside the ST7789V, which runs at 1 MHz to 5 MHz, and you can adjust it via command 0x36 (MADCTL) to control the scan direction. For example, setting bit 5 to 1 reverses the row scan order, which is useful for mounting the display upside down. The multiplexing also involves the backlight, which is typically a white LED with a forward voltage of 3.0V to 3.2V at 20 mA. You can PWM the backlight at 1 kHz to 10 kHz to adjust brightness, but be careful: PWM frequencies below 1 kHz cause visible flicker, and above 10 kHz you might hear coil whine from the LED driver. The display's response time is 10 ms to 20 ms (rise and fall), so 60 Hz refresh is fine for most graphics, but fast-moving objects might show ghosting. To mitigate this, use a higher refresh rate like 80 Hz by overclocking the SPI clock to 30 MHz, but check the datasheet: the ST7789V maximum SPI clock is 30 MHz for write operations, and exceeding it can cause data corruption. The display's power consumption at full brightness and 60 Hz is about 50 mW (3.3V * 15 mA for logic + 3.2V * 20 mA for backlight), which is low enough for battery-powered projects. For multiplexing with multiple displays, you can daisy-chain them by sharing the SPI bus and using separate CS lines, but each display needs its own DC and RESET pins. The ST7789V supports a cascading mode where you can connect the SDO (serial data out) of one display to the SDI (serial data in) of the next, but this doubles the data transfer time. A better approach is to use a SPI multiplexer like the 74HC4051 to select between up to 8 displays, but the CS pin method is simpler for up to 4 displays. The display's pixel pitch is 0.12 mm (calculated as 1.3 inches diagonal = 33.02 mm, with 240 pixels across, so 33.02 mm / 240 = 0.1376 mm per pixel), giving a sharp image at a viewing distance of 30 cm. The IPS technology means viewing angles are 80 degrees in all directions, so contrast ratio stays above 800:1 even when viewed from the side. The color gamut covers 65% of the NTSC standard, typical for this class of display, with a gamma curve of 2.2. When multiplexing, you need to initialize the driver with specific commands: 0x11 (sleep out), 0x36 (set MADCTL for RGB order and scan direction), 0x3A (set pixel format to 16-bit), 0xB0 (set porch values: 8 lines for VBP, 10 pixels for HBP), and 0x29 (display on). The total initialization sequence takes about 100 ms, including a 50 ms delay after sleep out. For real-time applications like a smartwatch, you can use a frame buffer in RAM on the microcontroller, but the ESP32 has 520 KB of SRAM, which can hold two full frames (115,200 bytes each) with room to spare. The DMA engine on the ESP32 can transfer SPI data at 40 MHz, but the ST7789V caps at 30 MHz, so you set the clock divider to achieve 26.7 MHz (80 MHz / 3). This gives a frame transfer time of 34.5 milliseconds for a full frame, leaving 16.5 milliseconds for processing in a 60 Hz cycle. To reduce power, you can use the display's partial refresh mode: set the vertical scrolling area with command 0x33, and update only a 10-line strip at the bottom, which reduces data to 4,800 bytes per frame. This is how e-ink-style animations work on TFT displays, but the ST7789V doesn't support partial refresh in the same way—it still requires a full frame write, but you can use window addressing to limit the area. The display's gate driver uses a shift register that advances one row per horizontal sync pulse, generated internally at 15 kHz (240 rows * 60 Hz). The source driver charges each column's data line in parallel, using a sample-and-hold circuit that updates at 15 MHz (240 columns * 60 Hz * 1,024 gray levels). This is the essence of multiplexing: time-division multiplexing of rows and space-division multiplexing of columns. The display's contrast ratio is 1000:1 typical, with a brightness of 300 cd/m² when the backlight is at full current. You can measure the actual power consumption with a multimeter in series with the power supply: at 60 Hz with a static image, the current draw is 12 mA for logic and 18 mA for backlight, totaling 30 mA at 3.3V. For a battery with 1000 mAh capacity, this gives 33 hours of continuous operation. To extend battery life, use a lower refresh rate like 30 Hz for static images, which cuts logic power by half because the oscillator runs slower. The display's sleep mode (command 0x10) reduces current to 0.5 mA, but you need a 10 ms wake-up time. When multiplexing in a project with a Raspberry Pi Pico, you can use the PIO (Programmable I/O) to generate SPI signals at 30 MHz with precise timing, bypassing the CPU. The PIO state machine can handle the CS and DC toggling automatically, reducing CPU load to near zero. This is critical for high-speed multiplexing because the CPU can focus on graphics rendering while the PIO handles data streaming. The display's maximum refresh rate is 80 Hz, but the ST7789V datasheet specifies a typical frame rate of 60 Hz. Going above 80 Hz can cause the internal charge pump to overheat, as the row driver switches faster. The display's operating temperature range is -20°C to +70°C, so multiplexing at low temperatures might require a slower clock due to increased resistance in the TFTs. At -20°C, the row driver's charge time increases by 30%, so you might need to reduce the SPI clock to 15 MHz to avoid data corruption. The display's pixel storage capacitor is 0.1 pF, and the row line capacitance is 10 pF per row, so the total row capacitance is 2.4 nF (240 columns * 10 pF). The row driver charges this capacitance in 10 microseconds, which is why the row scan time is 69 microseconds. The column driver uses a 6-bit DAC for each of the 240 columns, giving 64 gray levels per color channel, but the 16-bit color interface maps to 65,536 colors via a lookup table. The actual color depth is 262,144 colors (18-bit) internally, but the interface accepts 16-bit. For multiplexing with a high-resolution image, you can use dithering to simulate more colors, but the display's gamma correction (command 0xE0) can be adjusted to improve linearity. The default gamma curve has a slope of 2.2, but you can change it to 1.8 for brighter images. The display's response time is 15 ms (rise) and 10 ms (fall), so the total pixel switching time is 25 ms, which is slower than the 16.7 ms frame period at 60 Hz. This means pixels don't fully settle before the next frame, causing a slight blur. To reduce this, use overdrive: increase the voltage for the first frame to 6V (instead of 3.3V) to speed up the liquid crystal alignment, but the ST7789V doesn't support overdrive natively—you need an external circuit. The display's backlight is a single LED with a luminous flux of 5 lumens, giving an efficiency of 80 lumens per watt. The LED's lifetime is 20,000 hours at 20 mA, so multiplexing for 8 hours a day gives 6.8 years of operation. The display's glass thickness is 0.5 mm, with a polarizer on top and a diffuser layer for the backlight. The total module thickness is 2.5 mm including the FPC (flexible printed circuit) connector. The FPC has 14 pins with a 0.5 mm pitch, so you need a matching connector on your PCB. The pinout is: 1-VCC (3.3V), 2-GND, 3-CS, 4-RESET, 5-DC, 6-SDI (MOSI), 7-SCK, 8-LED (backlight anode), 9-GND, 10-SDO (optional, for daisy-chaining), 11-TE (tearing effect output), 12-GND, 13-GND, 14-GND. The TE pin outputs a pulse at the start of each frame, which you can use for synchronization. For multiplexing with a camera, you can use the TE pin to trigger a capture at the exact moment the display refreshes, avoiding tearing. The display's SPI protocol is mode 0 (CPOL=0, CPHA=0), meaning data is sampled on the rising edge of SCK. The maximum cable length for SPI at 20 MHz is 10 cm, so keep the wiring short. For longer distances, use a level shifter like the 74LVC245 to boost the signal. The display's internal voltage regulator generates 1.8V for the core logic from the 3.3V input, with a dropout voltage of 0.2V. The regulator's efficiency is 90%, so the 1.8V rail consumes 10 mA from the 3.3V input, accounting for 33 mW. The row and column drivers use a charge pump to generate 6V for the TFT gate voltage, which consumes an additional 5 mA. The total logic power is 3.3V * 15 mA = 49.5 mW. The backlight power is 3.2V * 20 mA = 64 mW, so the total is 113.5 mW. For a battery-powered project, you can reduce backlight power by using a PWM duty cycle of 50%, cutting it to 32 mW. The display's multiplexing efficiency is measured by the number of pixels per pin: 57,600 pixels / 6 pins = 9,600 pixels per pin, which is excellent for a small display. Compare this to a parallel RGB interface that uses 18 pins for 57,600 pixels, giving 3,200 pixels per pin. The SPI interface is three times more efficient in terms of pin usage, but it requires a higher clock rate to achieve the same frame rate. For example, a parallel interface at 10 MHz can transfer a frame in 11.5 milliseconds (115,200 bytes / 10,000,000 bytes/second), while SPI at 20 MHz takes 46 milliseconds. So SPI is slower but uses fewer pins. The trade-off is acceptable for most microcontroller projects because the CPU can do other tasks during the transfer. The display's driver IC supports a 240x240 resolution at 60 Hz with a pixel clock of 3.456 MHz (240 columns * 240 rows * 60 Hz). The SPI clock must be at least 3.456 MHz * 16 bits per pixel = 55.3 MHz to achieve real-time updates, but the ST7789V's maximum is 30 MHz, so you need to buffer frames in RAM. This is why the display is called a "buffer-based" multiplexing system: the driver IC has its own RAM, so you can write data at any speed, and the internal oscillator reads it at the correct rate. The RAM is 240x240x18 bits = 1,036,800 bits = 129.6 KB. The RAM is organized as two banks for double-buffering, but the ST7789V uses a single-buffer architecture, meaning you see the last written frame. To avoid tearing, use the TE pin to detect when the internal scan is in the vertical blanking interval (VBI), which lasts 8 row times (8 * 69 microseconds = 552 microseconds). During VBI, you can write a new frame without causing tearing. The display's VBI is 8 lines at 60 Hz, so the total blanking time is 8 / 240 * 16.67 ms = 0.56 ms. This is enough time to write a partial update of 10,000 bytes at 20 MHz (4 ms), so you can update a small area during VBI without tearing. For full-frame updates, you need to write during the active area, which causes tearing if the internal scan passes the row you're updating. To avoid this, use double-buffering on the microcontroller: write to a second buffer while the display shows the first, then swap buffers during VBI. The ESP32's dual-core architecture allows one core to handle SPI transfers while the other core renders graphics. The display's SPI interface supports quad-SPI (QSPI) on some modules, but the standard 4-wire SPI is more common. QSPI can transfer 4 bits per clock cycle, quadrupling the throughput to 120 Mbps at 30 MHz, but the ST7789V doesn't support QSPI natively—you need a different driver IC like the ILI9341. The display's pixel format can be set to 12-bit (RGB444) via command 0x3A, reducing data per pixel to 1.5 bytes, which cuts frame transfer time to 34.5 milliseconds at 20 MHz (86,400 bytes). This is a common trick for achieving 30 FPS on slow microcontrollers. The color accuracy drops to 4,096 colors, but for UI elements like text and icons, it's acceptable. The display's gamma correction can be tuned with command 0xE0 (positive gamma) and 0xE1 (negative gamma), with 15 registers each. The default values are 0x70, 0x04, 0x08, 0x09, 0x09, 0x05, 0x2A, 0x33, 0x41, 0x07, 0x13, 0x13, 0x29, 0x2E, 0x33. Adjusting these can improve contrast for specific applications, like medical imaging. The display's viewing angle performance is measured by contrast ratio at 45 degrees: it drops to 200:1 for IPS, which is still usable. The display's response time at 25°C is 15 ms, but at 60°C it drops to 8 ms, and at 0°C it increases to 30 ms. For outdoor use, the display's brightness of 300 cd/m² is sufficient in shade, but in direct sunlight, you need a brightness of 500 cd/m² or a transflective polarizer. The display's backlight can be driven at 30 mA for short bursts to achieve 450 cd/m², but this