How to connect a 1.3 inch 240x240 display to Arduino?
How to connect a 1.3 inch 240x240 display to Arduino
To connect a 1.3 inch 240x240 IPS display to an Arduino, you need to wire the SPI interface pins from the display module to the corresponding SPI pins on your Arduino board. The display typically uses a 4-wire SPI communication protocol (SCLK, MOSI, DC, CS, plus RST and VCC/GND). For an Arduino Uno, connect the display’s SCLK to pin 13, MOSI to pin 11, DC (Data/Command) to pin 9, CS (Chip Select) to pin 10, RST (Reset) to pin 8, VCC to 3.3V or 5V (check your module’s voltage rating—most 1.3 inch 240x240 IPS displays run at 3.3V logic but can tolerate 5V power), and GND to ground. If your display uses a separate backlight pin (often labeled BL or LED), connect it through a 100-ohm resistor to 3.3V or 5V to control brightness. After wiring, install the Adafruit ST7789 library (or a compatible one like TFT_eSPI) via the Arduino Library Manager, then upload a test sketch to verify the display initializes and shows graphics. This setup works for both 240x240 resolution and 1.3 inch diagonal size, common in modules based on the ST7789 driver IC.
Hardware specifications and pinout details
The 1.3 inch 240x240 ips display (often sold as a breakout board) uses the ST7789V controller, which supports a maximum resolution of 240x320 but is configured here for 240x240. The display’s active area measures 23.4mm x 23.4mm, with a pixel pitch of 0.0975mm. Typical modules have 8 pins: VCC, GND, SCLK, MOSI, DC, CS, RST, and BL. Some variants include an extra MISO pin (not used in SPI write-only mode). The SPI clock speed can go up to 40 MHz, but Arduino Uno’s hardware SPI maxes out at 8 MHz (half the system clock), which is sufficient for smooth 60 fps updates. Power consumption is around 20-30 mA at full brightness (backlight on), dropping to 5 mA with backlight off. The display’s viewing angle is 170 degrees (IPS technology), and it supports 262K colors (18-bit RGB). Below is a reference table for common Arduino board connections:
| Display Pin | Arduino Uno | Arduino Mega | Arduino Nano |
|---|---|---|---|
| VCC | 3.3V or 5V | 3.3V or 5V | 3.3V or 5V |
| GND | GND | GND | GND |
| SCLK | 13 (SCK) | 52 (SCK) | 13 (SCK) |
| MOSI | 11 (MOSI) | 51 (MOSI) | 11 (MOSI) |
| DC | 9 | 9 | 9 |
| CS | 10 | 10 | 10 |
| RST | 8 | 8 | 8 |
| BL | Via 100Ω to 3.3V | Via 100Ω to 3.3V | Via 100Ω to 3.3V |
Library selection and configuration
Two popular libraries work with this display: Adafruit ST7789 (version 1.2.0 or later) and TFT_eSPI (version 2.5.43 or later). The Adafruit library requires manual pin definitions in your sketch, while TFT_eSPI uses a configuration file (User_Setup.h) where you set the driver to ST7789, resolution to 240x240, and assign pins. For TFT_eSPI, open the library’s User_Setup.h file and uncomment these lines: #define ST7789_DRIVER, #define TFT_WIDTH 240, #define TFT_HEIGHT 240, then set #define TFT_CS 10, #define TFT_DC 9, #define TFT_RST 8, and #define TFT_MOSI 11, #define TFT_SCLK 13. If using hardware SPI, also comment out #define TFT_SOFT_SPI. The Adafruit library, on the other hand, uses a constructor like Adafruit_ST7789 tft = Adafruit_ST7789(cs, dc, rst); and then calls tft.init(240, 240); in setup(). Both libraries handle the 240x240 resolution natively, but you must set the rotation correctly—default rotation 0 might show a 240x320 area with black bars; call tft.setRotation(2); to fill the screen.
Wiring considerations and common pitfalls
One frequent mistake is assuming the display runs at 5V logic. While the module’s VCC pin can accept 5V for power, the SPI data lines (SCLK, MOSI, DC, CS) are 3.3V logic only. Feeding 5V from an Arduino Uno’s digital output (which outputs 5V) can damage the ST7789 controller over time. To fix this, use a level shifter (e.g., 74LVC245 or a resistive divider) between the Arduino and the display. Alternatively, power the Arduino at 3.3V (if using a 3.3V variant like Arduino Pro Mini 3.3V) or use a voltage divider on each SPI line: a 10kΩ series resistor followed by a 20kΩ to ground gives 3.3V from 5V. Another issue is the backlight pin—some modules have a common anode LED backlight, meaning you connect the BL pin to GND through a resistor to turn it on, not to VCC. Check your module’s datasheet: if the backlight is active low, connect BL to GND via a 100Ω resistor; if active high, connect to VCC via the resistor. A wrong connection can cause no backlight or a short circuit.
Software initialization sequence
After wiring, you need to initialize the display with specific commands. The ST7789 requires a hardware reset (pulse RST low for 10ms, then high) followed by a sleep-out command (0x11), then a display-on command (0x29). Both libraries handle this automatically in their init() or begin() functions. For a minimal sketch using Adafruit ST7789, include #include <Adafruit_GFX.h> and #include <Adafruit_ST7789.h>, then define pins: #define TFT_CS 10, #define TFT_DC 9, #define TFT_RST 8. Create the object: Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);. In setup(), call tft.init(240, 240);, then tft.fillScreen(ST77XX_BLACK); to test. If the screen stays blank, check your wiring, especially the CS and RST pins—floating CS can cause the display to ignore SPI commands. Also, verify that the display’s SPI mode is mode 0 (CPOL=0, CPHA=0), which is the default for both libraries.
Performance benchmarks and frame rates
With an Arduino Uno at 16 MHz, using hardware SPI at 8 MHz, the 1.3 inch 240x240 ips display can achieve a full-screen fill (240x240 pixels, 57,600 pixels) in about 15-20 milliseconds using the Adafruit library’s fillScreen() function. Drawing a bitmap image from flash memory takes longer: a 240x240 16-bit color image (115,200 bytes) transfers in roughly 50-60 ms, giving a frame rate of 16-20 fps. TFT_eSPI is slightly faster due to optimized SPI transactions—full-screen fills in 12-15 ms, and bitmap transfers in 40-50 ms. For animations, you can achieve 30 fps with simple shapes, but complex graphics (like JPEG decoding) drop to 5-10 fps because the Uno lacks hardware acceleration. If you need higher performance, switch to an ESP32 or Teensy 3.2, which can drive SPI at 40 MHz and push 60+ fps for the same display.
Power management and backlight control
The display’s total power draw varies with backlight brightness. At 100% PWM duty cycle (backlight on continuously), current consumption is 25 mA at 3.3V (82.5 mW). Reducing backlight to 50% via PWM (e.g., using Arduino’s analogWrite() on the BL pin) drops current to 15 mA. The ST7789 controller itself draws 2-3 mA in active mode and 0.1 mA in sleep mode (after sending command 0x10). To put the display to sleep, call tft.sleep(); (Adafruit) or tft.writecommand(0x10); (TFT_eSPI). Wake it with tft.wake(); (0x11). This is useful for battery-powered projects—sleep mode reduces total system draw to under 1 mA (including Arduino idle). Note that the backlight is separate from the controller; you must turn it off manually via a digital pin or PWM output. A common approach is to connect BL to a MOSFET (e.g., 2N7000) controlled by an Arduino pin, allowing full on/off control without resistor losses.
Display orientation and coordinate system
The ST7789’s memory is organized as 240 columns (x) by 320 rows (y), but the 1.3 inch module only exposes 240x240 pixels, leaving an 80-row unused area. The driver IC’s column address window must be set to 0-239 and row address window to 0-239. If you use tft.setRotation(0);, the origin (0,0) is at the top-left when the ribbon cable is at the bottom. Rotation 1 rotates 90 degrees clockwise, rotation 2 rotates 180 degrees, and rotation 3 rotates 270 degrees. In rotation 2, the origin is at the bottom-right (if cable at bottom), which is useful for mounting the display upside-down. The coordinate system uses 16-bit integers for x and y, so drawing at (240, 240) is out of bounds—always clamp coordinates to 0-239. For text rendering, the Adafruit GFX library uses a 5x7 pixel font by default, giving 48 characters per line (240/5) and 34 lines (240/7). You can change font size with tft.setTextSize(2); for 10x14 pixels, yielding 24 characters per line and 17 lines.
Troubleshooting common issues
If the display shows nothing after uploading a sketch, first check the backlight: shine a flashlight at the screen to see if there’s any image (the ST7789’s pixels are visible without backlight). If you see a faint image, the backlight circuit is wrong—re-check the BL pin polarity. If no image at all, verify SPI connections with a multimeter: measure continuity between Arduino pins and display pins. Also, ensure the CS pin is pulled low during SPI transactions—some libraries don’t handle CS automatically, so you might need to call tft.setSPISpeed(4000000); to slow down SPI if wiring is long (over 20 cm). Another issue is wrong library configuration: if you’re using TFT_eSPI with the wrong driver (e.g., ILI9341 instead of ST7789), the display may show random colors. Re-check User_Setup.h for #define ST7789_DRIVER. If colors are inverted (e.g., red appears as blue), you may need to set #define TFT_INVERSION_ON or #define TFT_INVERSION_OFF in TFT_eSPI, or call tft.invertDisplay(true); in Adafruit library. Finally, some modules have a built-in voltage regulator that requires 5V VCC—if you power at 3.3V, the display may not initialize. Check your module’s datasheet: if it says “3.3V/5V compatible,” it likely has a regulator; otherwise, stick to 3.3V.
Advanced usage: double buffering and DMA
For smooth animations, you can implement double buffering using an external SRAM chip (e.g., 23LC1024) connected via SPI, which stores a full 240x240 frame (115,200 bytes). The Arduino Uno has only 2 KB of SRAM, so you can’t buffer a frame in RAM. With an external SRAM, you write pixel data to the buffer, then copy the buffer to the display using a fast SPI transfer (like tft.pushImage()). This eliminates tearing artifacts. Another technique is using the ST7789’s partial display mode (command 0x30), which lets you update only a rectangular region—useful for widgets or gauges. For example, to update a 50x50 pixel area, set the column and page address windows with commands 0x2A and 0x2B, then send only 2,500 pixels (5,000 bytes) instead of the full frame. This reduces SPI traffic by 95% for small updates.
Compatibility with different Arduino boards
While the Uno is the most common, the 1.3 inch 240x240 ips display works with many boards. On an Arduino Mega, use pins 52 (SCLK), 51 (MOSI), and any digital pin for CS, DC, RST (e.g., 10, 9, 8). The Mega’s SPI runs at 8 MHz like the Uno, but its larger flash memory (256 KB) allows storing multiple full-screen bitmaps. On an Arduino Nano, the pinout is identical to the Uno (pins 13, 11, 10, 9, 8). For 3.3V boards like the Arduino Due (which runs at 84 MHz), SPI can go up to 42 MHz, giving 60+ fps. However, the Due’s logic is 3.3V, so no level shifting is needed. For ESP8266 or ESP32, use the TFT_eSPI library with hardware SPI on pins: ESP8266 uses GPIO14 (SCLK), GPIO13 (MOSI), and custom CS/DC/RST (e.g., GPIO15, GPIO2, GPIO0). ESP32 has two SPI buses: VSPI (default: GPIO18 SCLK, GPIO23 MOSI, GPIO5 CS, GPIO19 DC, GPIO18 RST) or HSPI. The ESP32 can drive the display at 40 MHz, achieving 100+ fps for simple graphics.
Cost and sourcing considerations
This specific display module (ST7789-based, 1.3 inch, 240x240) is widely available from Chinese distributors for $3-5 per unit (in single quantities) on platforms like AliExpress or Amazon. The breakout board typically includes a 4-pin or 8-pin header (2.54mm pitch), with or without a backlight control transistor. Some modules come with a pre-soldered 8-pin female header, while others require soldering. The display’s glass thickness is about 1.1mm, and the PCB is 1.0mm thick, with a total weight of 6-8 grams. For volume orders (100+), prices drop to $2-3 per unit. Compare this to OLED displays of similar size (1.3 inch OLED 128x64) which cost $5-8 but have lower resolution and narrower viewing angles. The IPS LCD offers better color reproduction and higher pixel density (261 PPI vs 128 PPI for OLED), making it suitable for detailed graphics like weather icons or game sprites.
Real-world project examples
In a typical project, you can use this display as a dashboard for sensor data. For instance, connect a DHT22 temperature/humidity sensor to an Arduino Uno, read values every 2 seconds, and display them on the 1.3 inch 240x240 screen. The code would call tft.fillScreen(ST77XX_BLACK); to clear the screen, then draw text at specific coordinates: tft.setCursor(