How to use a 2.4 inch display with a Teensy board?
How to Use a 2.4 Inch Display with a Teensy Board
To use a 2.4 inch display with a Teensy board, you need to connect the display’s SPI pins to the Teensy’s hardware SPI ports, install the appropriate library (like Adafruit_GFX and ILI9341 or ST7789 depending on the driver chip), and write code to initialize the display and draw graphics. The most common display for this size is the 2.4 inch 240x320 ips display, which typically uses an ILI9341 or ST7789 driver. Teensy 4.0, 4.1, or 3.6 boards are ideal because they run at 600 MHz or 180 MHz, respectively, and have dedicated SPI hardware that can push pixels at over 60 MHz clock speed. For example, a Teensy 4.0 can drive a 240x320 display at 60+ frames per second when using DMA (Direct Memory Access).
Hardware Wiring: Pin-by-Pin Details
Let’s get into the wiring specifics. A typical 2.4-inch IPS display with SPI interface has 8 pins: VCC, GND, CS, RESET, DC (Data/Command), MOSI, MISO, and SCK. Some modules also include a backlight pin (LED or BL) and a touch controller (like XPT2046) with its own CS and SPI pins. For Teensy 4.0, the hardware SPI pins are: MOSI on pin 11, MISO on pin 12, SCK on pin 13, and CS can be any digital pin (commonly pin 10). DC and RESET can be any digital pins, often pin 9 and pin 8, respectively. VCC connects to 3.3V on the Teensy (never 5V, as Teensy is 3.3V logic and the display’s logic level is also 3.3V). GND to GND. If your display has a backlight pin, you can connect it to a PWM-capable pin (like pin 5) to control brightness via analogWrite().
Here’s a concrete wiring table for Teensy 4.0:
| Display Pin | Teensy 4.0 Pin | Notes |
|---|---|---|
| VCC | 3.3V | Must be 3.3V, not 5V |
| GND | GND | Common ground |
| CS | 10 | Chip select, can be any digital pin |
| RESET | 8 | Reset line, active low |
| DC | 9 | Data/Command, high for data |
| MOSI | 11 | Master Out Slave In |
| MISO | 12 | Master In Slave Out (optional for read) |
| SCK | 13 | SPI clock |
| LED/BL | 5 | Backlight PWM, optional |
If you’re using Teensy 3.6, the SPI pins are the same: MOSI on pin 11, MISO on pin 12, SCK on pin 13, CS on pin 10. Teensy 4.1 has additional SPI ports (SPI1 and SPI2) but the default SPI0 is on pins 11, 12, 13. For displays with touch, the touch controller (XPT2046) typically uses its own CS pin (e.g., pin 6) and shares the same MOSI, MISO, SCK lines. That means you can run both the display and touch on the same SPI bus, just with separate CS pins. The Teensy’s SPI library handles this fine.
Library Selection and Installation
You have two main library paths. For ILI9341-based displays, use the Adafruit_ILI9341 library along with Adafruit_GFX. For ST7789-based displays, use the Adafruit_ST7789 library. But many 2.4-inch IPS displays use the ILI9341 driver, which supports 240x320 resolution at 18-bit color (262k colors). The ST7789 is also common but often used in 1.3-inch or 1.8-inch displays; however, some 2.4-inch modules do use ST7789. Check the driver chip on your module’s PCB—it’s usually printed as “ILI9341” or “ST7789V”.
To install, open the Arduino IDE (or PlatformIO), go to Tools > Manage Libraries, search for “Adafruit GFX” and install it, then search for “Adafruit ILI9341” and install it. For Teensy-specific optimizations, you can also install the “Teensyduino” add-on which includes optimized SPI routines. The Teensy 4.0’s SPI clock can be set to 60 MHz or even 80 MHz, but the ILI9341’s max SPI clock is typically 80 MHz (though 60 MHz is more stable). In your code, you can set the SPI speed in the constructor: Adafruit_ILI9341 tft = Adafruit_ILI9341(&SPI, cs, dc, rst); and then call tft.begin(40000000) to set 40 MHz, or tft.begin(60000000) for 60 MHz. At 60 MHz, a full screen fill of 240x320 pixels (76,800 pixels) takes about 1.2 milliseconds with DMA, which gives you a theoretical 800+ fps, but practical frame rates are limited by the display’s response time (typically 10-20 ms).
Code Example: Initialization and Basic Drawing
Here’s a minimal working sketch for Teensy 4.0 with an ILI9341 display:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(&SPI, TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
tft.begin(60000000); // 60 MHz SPI clock
tft.setRotation(1); // Landscape orientation
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("Hello from Teensy 4.0!");
}
void loop() {
// draw a moving circle
static int x = 0;
tft.fillCircle(x, 160, 10, ILI9341_RED);
delay(10);
tft.fillCircle(x, 160, 10, ILI9341_BLACK);
x = (x + 1) % 240;
}
This code initializes the display at 60 MHz, sets landscape orientation, clears the screen, and prints text. The loop draws a red circle moving horizontally. The fillCircle function is from Adafruit_GFX and uses Bresenham’s algorithm. For higher performance, you can use DMA transfers. The Teensy 4.0’s DMA controller can move pixel data from a buffer to the display’s SPI port without CPU intervention. The tft.fillScreen() function already uses DMA internally in the Adafruit library when running on Teensy 4.0, but for custom shapes, you can use tft.dmaSend() or the ILI9341_t3 library (a Teensy-optimized fork) that exposes DMA directly.
Performance Data: Teensy vs. Other Boards
To give you a concrete sense of performance, here’s a comparison of frame rates for a 2.4-inch display (240x320) when running a full-screen fill operation:
| Board | CPU Speed | SPI Clock | Fill Time (ms) | Max FPS |
|---|---|---|---|---|
| Teensy 4.0 | 600 MHz | 60 MHz | 1.2 | 833 |
| Teensy 3.6 | 180 MHz | 30 MHz | 2.5 | 400 |
| Arduino Uno | 16 MHz | 8 MHz | 30 | 33 |
| ESP32 | 240 MHz | 40 MHz | 2.0 | 500 |
These numbers assume DMA is enabled. Without DMA, the Teensy 4.0 still runs at about 1.8 ms per fill (around 555 FPS) because the CPU is fast enough to push pixels via SPI. The Arduino Uno is crippled by its 8 MHz SPI and lack of DMA. The ESP32 is competitive but its SPI implementation has more overhead. The Teensy 4.0 wins because of its dedicated SPI hardware with 16-word FIFO and DMA engine that can run in the background.
Power Consumption and Thermal Considerations
When driving a 2.4-inch IPS display at full brightness, the display itself draws about 80-120 mA from the 3.3V rail. The Teensy 4.0 draws around 100 mA at 600 MHz. So total current is about 200-220 mA. That’s fine for USB power (500 mA from a computer). But if you’re using a battery, a 500 mAh LiPo lasts about 2.5 hours. The display’s backlight is the biggest power hog. You can reduce it by using PWM. For example, setting analogWrite(5, 128) (50% duty) cuts backlight current to about 40 mA, dropping total current to 140 mA. The Teensy 4.0 can get warm (around 50°C under full load) but not dangerously hot. If you’re using a plastic enclosure, ensure ventilation.
Touch Integration (If Your Display Has It)
Many 2.4-inch IPS displays come with a resistive touch layer (XPT2046 controller). The touch controller uses SPI on the same bus but with a separate CS pin. For example, connect touch CS to pin 6. Then use the XPT2046_Touchscreen library. Here’s a quick wiring addition:
| Touch Pin | Teensy 4.0 Pin |
|---|---|
| T_CS | 6 |
| MOSI | 11 (shared) |
| MISO | 12 (shared) |
| SCK | 13 (shared) |
In code, you initialize the touch with XPT2046_Touchscreen ts(6); and call ts.begin(). The touch data comes as raw 12-bit values (0-4095) for X and Y. You map them to screen coordinates: int x = map(ts.getX(), 0, 4095, 0, 240);. Note that resistive touch needs calibration because the raw values vary with pressure and screen alignment. A typical calibration routine involves touching four corners and storing the min/max values. The Teensy’s EEPROM can store these calibration constants. The touch sampling rate is about 125 kHz, so you can poll at 100 Hz without issues.
Common Pitfalls and Debugging Tips
One frequent issue is the display not initializing. Check the RESET pin: some displays need a hardware reset pulse. In the code, the tft.begin() function handles this, but if you wired RESET to a pin, ensure it’s not left floating. If you’re using a 5V display (rare for 2.4-inch IPS), you’ll need a level shifter because Teensy’s 3.3V logic can’t drive 5V inputs reliably. Most 2.4-inch IPS displays are 3.3V, but verify the datasheet. Another issue is SPI speed: if you set the clock too high (e.g., 80 MHz), the display may show glitches. Drop to 40 MHz for stability. Also, the MISO pin is optional for write-only operations; if you don’t connect it, the library still works but can’t read display memory. For most graphics, that’s fine.
If you see garbled colors, check the color mode. The ILI9341 supports 16-bit (RGB565) and 18-bit (RGB666) modes. The Adafruit library uses 16-bit by default, which matches the display’s typical mode. If you’re using a different library, ensure the color depth matches. Also, the display’s orientation matters: tft.setRotation(0) is portrait with the ribbon cable at the bottom, setRotation(1) is landscape, setRotation(2) is portrait upside down, setRotation(3) is landscape reversed. The coordinate system is 0,0 at top-left.
Advanced: Using DMA for Smooth Animation
For animation-heavy projects like a mini game or a waveform display, you want to use DMA. The Teensy 4.0 has a dedicated DMA controller with 16 channels. The Adafruit library doesn’t expose DMA directly, but the ILI9341_t3 library (by Paul Stoffregen) does. This library is specifically optimized for Teensy 3.x and 4.x. It allows you to use tft.useFrameBuffer(true) to create a framebuffer in RAM, then tft.updateScreen() to DMA the buffer to the display. The framebuffer for 240x320 at 16-bit color is 240*320*2 = 153,600 bytes. That’s 150 KB, which fits in Teensy 4.0’s 2 MB RAM (or 1 MB on Teensy 4.0). The DMA transfer takes about 1 ms, leaving the CPU free to calculate the next frame. This is how you achieve 60 fps with complex graphics. For example, a 3D cube rotation or a particle system can run at 30-60 fps without screen tearing.
Real-World Projects and Use Cases
I’ve seen this combination used in a portable oscilloscope, where the Teensy 4.0 samples analog data at 2 MHz and displays a waveform on the 2.4-inch screen. The DMA framebuffer allows the waveform to update at 50 fps while the CPU handles FFT calculations. Another project is a flight simulator instrument panel, where multiple Teensy 4.0 boards each drive a 2.4-inch display showing airspeed, altitude, and heading. The SPI bus can be daisy-chained if you use separate CS pins, but each display needs its own CS line. For a single Teensy driving two displays, you can use two SPI ports (SPI0 and SPI1 on Teensy 4.1) or share the same bus with different CS. The performance drop is minimal because the SPI bus is fast enough.
Data on Display Response Time
The 2.4-inch IPS display’s response time (gray-to-gray) is typically 10-20 ms, which limits the perceived refresh rate. Even if the Teensy pushes 800 fps, the display’s liquid crystals can’t switch that fast. So the practical maximum is around 60-100 fps for smooth motion. The IPS technology gives wide viewing angles (170 degrees) and good color reproduction (65% NTSC typical). The contrast ratio is around 1000:1. The brightness is usually 300-400 cd/m², which is readable indoors but may need shading in direct sunlight. The pixel pitch is 0.15 mm, which is fine for text at 2-3 mm height.
Power Supply Considerations
When powering the Teensy and display from a USB battery, use a cable with low resistance (20 AWG or thicker) to avoid voltage drop. The Teensy 4.0’s 3.3V regulator can supply up to 250 mA, which is enough for the display (120 mA) and Teensy itself (100 mA), but if you add other peripherals, you might exceed it
Ready to get in the water?
Small boats, shallow reefs, and guides who know every crevice by name — depart from Garden Cove Marina.