# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Overview

If you're looking for the most compact li'l color display for a [Raspberry Pi](https://www.adafruit.com/category/361) (most&nbsp;likely a [Pi Zero](https://www.adafruit.com/category/813)) project, this might be just the thing you need!

![](https://cdn-learn.adafruit.com/assets/assets/000/082/843/medium800thumb/adafruit_products_ezgif-2-b96268de44f7.jpg?1571856567)

The **Adafruit Mini PiTFT - 135x240 Color TFT Add-on for Raspberry Pi** is your little TFT pal, ready to snap onto any and all Raspberry Pi computers, to give you a little display. The Mini PiTFT comes with a full color 240x135 pixel IPS display with great visibility at all angles. The TFT uses only the SPI port so its very fast, and we leave plenty of pins remaining available for buttons, LEDs, sensors, etc. It's also nice and compact so it will fit into any case.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/537/medium800thumb/adafruit_products_4484.jpg?1579991666)

The **Adafruit Mini PiTFT - 240x240 Color TFT Add-on for Raspberry Pi** is a bit larger, 1.3" diagonal and has 240x240 pixels instead of 240x135

![](https://cdn-learn.adafruit.com/assets/assets/000/082/842/medium800/adafruit_products_4393_iso_ORIG_2019_10.jpg?1571856509)

These display are super small, only about 1.14" or 1.3" diagonal, but since they are IPS displays, both are very readable with high contrast and visibility. We had a little space on the PCB so we give you two tactile buttons on GPIO pins so you can create a simple user interface. [On the bottom we have a Qwiic/STEMMA QT connector for I2C sensors and device so you can plug and play any of our STEMMA QT devices](https://www.adafruit.com/?q=stemma%20qt).

![](https://cdn-learn.adafruit.com/assets/assets/000/087/538/medium800/adafruit_products_4484_quarter_ORIG_2020_01.jpg?1579991762)

Using the display is very easy, we have a kernel driver and Python library for the ST7789 chipset. You can set it up as a console output so you can have text and user interface through the Raspberry Pi OS _or_ you draw images, text, whatever you like, using the Python imaging library. Our tests showed ~15 FPS update rates so you can do animations or simple video.

 **Comes completely pre-assembled and tested** so you don't need to do anything but plug it in and install our Python code! **Works with any Raspberry Pi computer.**

![](https://cdn-learn.adafruit.com/assets/assets/000/082/840/medium800/adafruit_products_4393_top_lit_ORIG_2019_10.jpg?1571856478)

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Pinouts

Both the 1.3" and 1.14" versions of the Mini PiTFT have the same 2x12 connector and pinouts.

![adafruit_products_4393_quarter_ORIG_2019_10.jpg](https://cdn-learn.adafruit.com/assets/assets/000/087/539/medium640/adafruit_products_4393_quarter_ORIG_2019_10.jpg?1579991932)

![adafruit_products_4484_quarter_ORIG_2020_01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/087/540/medium640/adafruit_products_4484_quarter_ORIG_2020_01.jpg?1579992036)

![](https://cdn-learn.adafruit.com/assets/assets/000/082/846/medium800/adafruit_products_image.png?1571856698)

The mini PiTFT connects to the 'top' 2x12 headers on the Pi's 2x20 header connection. It uses the following pins:

- **5.0V** - Connected to the display backlight
- **3.3V** - Connected to the display power and also the STEMMA QT / Qwiic connector
- **GND** - Ground for everything
- **SDA & SCL** - I2C data for the STEMMA QT / Qwiic connector. Not used by buttons or display
- **GPIO22** - Used to turn the backlight on and off. If you never want to turn the backlight off, cut the small jumper on the bottom of the PiTFT to free up GPIO22
- **GPIO23 & GPIO24** - Connected to the two front buttons. These pins have 10K pullups to 3.3V so when the button is pressed, you will read a LOW voltage on these pins
- **SCK, MOSI, CE0 & GPIO25 -** These are the display control pins. Note that MISO is not connected even though it is a SPI pin because you cannot read back from the display.

Not used: **GPIO4, GPIO17, GPIO18, GPIO27**

**If you are using the 240x135 1.14" (small rectangular) Mini PiTFT**, you can attach other hardware to the Pi on those pins if you use a stacking header - it will go through the 2x12 connector on the Mini PiTFT. This wont work on the 1.3" because the holes don't go through the PCB

### GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3

[GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3](https://www.adafruit.com/product/2223)
Connect your own PCB to a Raspberry Pi B+ and stack on top with this normal-height female header with extra long pins. &nbsp;The female header part is about 8.5mm tall, good for small HATs that do not to clear the USB/Ethernet jacks. This header has extra long 10mm pins, compared with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2223)
[Related Guides to the Product](https://learn.adafruit.com/products/2223/guides)
![Angled top shot of the 2x20 extra tall socket header.](https://cdn-shop.adafruit.com/640x480/2223-08.jpg)

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## 1.14" 240x135 Kernel Module Install

Danger: 

There's two ways you can use the 240x135 display.

Warning: 

 **The easy way** is to use 'pure Python 3' and Pillow library to draw to the display from within Python. This is great for showing text, stats, images etc that you design yourself. If you want to do that, skip this page and go to the Python install/usage page

**The hard way** is to install a kernel module to add support for the TFT display that will make the console appear on the display. This is cute because you can have any program print text or draw to the framebuffer (or, say, with pygame) and Linux will take care of displaying it for you. If you don't need the console or direct framebuffer access, please consider using the 'pure Python' technique instead as it is not as delicate.

![](https://cdn-learn.adafruit.com/assets/assets/000/082/875/medium800thumb/adafruit_products_ezgif-2-b96268de44f7.jpg?1571860490)

Warning: 

# Prepare the Pi!

Before you begin, its a good idea to get your Pi completely updated and upgraded. We assume you have burned an SD card and can log into the console to install stuff.

Run

```terminal
sudo apt update -y
sudo apt-get update -y
sudo apt-get upgrade -y
```

To fully update and upgrade your Pi!

![](https://cdn-learn.adafruit.com/assets/assets/000/082/858/medium800/adafruit_products_image.png?1571859092)

## Setup Virtual Environment

If you are installing on the Bookworm version of Raspberry Pi OS or later, you will need to install your python modules in a virtual environment. You can find more information in the [Python Virtual Environment Usage on Raspberry Pi](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi) guide. To Install and activate the virtual environment, use the following commands:

```terminal
sudo apt install python3-venv
python -m venv env --system-site-packages
```

To activate the virtual environment:

```terminal
source env/bin/activate
```

After that is complete run

**sudo shutdown -h now**

to shutdown the Pi safely. Remove power and attach the miniPiTFT. Watch that the pins plug into the **first 2x12 headers!** The rounded corner and mounting hole should line up.

![](https://cdn-learn.adafruit.com/assets/assets/000/082/861/medium800/adafruit_products_image.png?1571859279)

Attach power to the Pi and re-log in. The PiTFT should be lit but nothing on the screen.

Run the following at the terminal

```terminal
cd ~
pip3 install --upgrade adafruit-python-shell click
sudo apt-get install -y git
git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git
cd Raspberry-Pi-Installer-Scripts
sudo -E env PATH=$PATH python3 adafruit-pitft.py --display=st7789_240x135 --rotation=270 --install-type=console
```

![](https://cdn-learn.adafruit.com/assets/assets/000/099/781/medium800/adafruit_products_PiTFT_Installation.png?1614382336)

When you get asked to reboot, reboot!

![](https://cdn-learn.adafruit.com/assets/assets/000/096/678/medium800/adafruit_products_PiTFT_Reboot.png?1604335307)

Zat's it! You will now have the miniPiTFT with a console display on it

![](https://cdn-learn.adafruit.com/assets/assets/000/082/874/medium800/adafruit_products_4393_demo_ORIG_2019_10.jpg?1571860426)

If you ever get a display like this, it means your kernel changed - either due to an upgrade/update or because you switched Pi boards. The solution is to simply re-run the scripts above!

![adafruit_products_4393_top_screen_02_ORIG_2019_10.jpg](https://cdn-learn.adafruit.com/assets/assets/000/082/855/medium640/adafruit_products_4393_top_screen_02_ORIG_2019_10.jpg?1571858960)

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## 1.3" 240x240 Kernel Module Install

There's two ways you can use the 1.3" 240x240 display.

Warning: 

 **The easy way** is to use 'pure Python 3' and Pillow library to draw to the display from within Python. This is great for showing text, stats, images etc that you design yourself. If you want to do that, skip this page and go to the Python install/usage page

**The hard way** is to install a kernel module to add support for the TFT display that will make the console appear on the display. This is cute because you can have any program print text or draw to the framebuffer (or, say, with pygame) and Linux will take care of displaying it for you. If you don't need the console or direct framebuffer access, please consider using the 'pure Python' technique instead as it is not as delicate.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/541/medium800thumb/adafruit_products_4484.jpg?1579992386)

Warning: 

# Prepare the Pi!

Before you begin, its a good idea to get your Pi completely updated and upgraded. We assume you have burned an SD card and can log into the console to install stuff.

Run

```terminal
sudo apt update -y
sudo apt-get update -y
sudo apt-get upgrade -y
```

To fully update and upgrade your Pi!

![](https://cdn-learn.adafruit.com/assets/assets/000/082/858/medium800/adafruit_products_image.png?1571859092)

## Setup Virtual Environment

If you are installing on the Bookworm version of Raspberry Pi OS or later, you will need to install your python modules in a virtual environment. You can find more information in the [Python Virtual Environment Usage on Raspberry Pi](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi) guide. To Install and activate the virtual environment, use the following commands:

```terminal
sudo apt install python3-venv
python -m venv env --system-site-packages
```

To activate the virtual environment:

```terminal
source env/bin/activate
```

After that is complete run

**sudo shutdown -h now**

to shutdown the Pi safely. Remove power and attach the miniPiTFT. Watch that the pins plug into the **first 2x12 headers!** The rounded corner and mounting hole should line up.

Attach power to the Pi and re-log in. The PiTFT should be lit but nothing on the screen.

Run the following at the terminal

```terminal
cd ~
pip3 install --upgrade adafruit-python-shell click
sudo apt-get install -y git
git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git
cd Raspberry-Pi-Installer-Scripts
sudo -E env PATH=$PATH python3 adafruit-pitft.py --display=st7789_240x240 --rotation=0 --install-type=console
```

![](https://cdn-learn.adafruit.com/assets/assets/000/099/782/medium800/adafruit_products_PiTFT_Installation.png?1614382372)

When you get asked to reboot, reboot!

![](https://cdn-learn.adafruit.com/assets/assets/000/096/673/medium800/adafruit_products_PiTFT_Reboot.png?1604334059)

Zat's it! You will now have the miniPiTFT with a console display on it

![](https://cdn-learn.adafruit.com/assets/assets/000/087/543/medium800/adafruit_products_image.png?1579992682)

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Python Setup

Warning: 

# Attaching
It's easy to use display breakouts with Python and the&nbsp;[Adafruit CircuitPython RGB Display](https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display)&nbsp;module.&nbsp; This module allows you to easily write Python code to control the display.

Since the PiTFT comes preassembled, all you need to do is place it onto the GPIO pins.

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms,&nbsp;[please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Connect the display as shown below to your Raspberry Pi.

Info: 

Warning: 

For the 1.14":

![](https://cdn-learn.adafruit.com/assets/assets/000/082/903/medium800/adafruit_products_4393-06.jpg?1571866945)

For the 1.3":

![](https://cdn-learn.adafruit.com/assets/assets/000/096/410/medium800/adafruit_products_Pi_MiniTFT_1-3in_plugged_in.png?1603729442)

# Setup

You'll need to install the Adafruit\_Blinka library that provides the CircuitPython support in Python. This may also require enabling SPI on your platform and verifying you are running Python 3. [Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Danger: If you have already installed the kernel module, you will need to remove it by editing your /boot/firmware/config.txt file before proceeding.

## Python Installation of RGB Display Library

Once that's done, from your command line run the following commands:

```terminal
pip3 install adafruit-circuitpython-rgb-display
```

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

If that complains about pip3 not being installed, then run this first to install it:

```terminal
sudo apt-get install python3-pip
```

## DejaVu TTF Font

Raspberry Pi usually comes with the DejaVu font already installed, but in case it didn't, you can run the following to install it:

```terminal
sudo apt-get install fonts-dejavu
```

This package was previously calls **ttf-dejavu** , so if you are running an older version of Raspberry Pi OS, it may be called that.

## Pillow Library

We also need PIL, the Python Imaging Library, to allow graphics and using text with custom fonts. There are several system libraries that PIL relies on, so installing via a package manager is the easiest way to bring in everything:

```terminal
sudo apt-get install python3-pil
```

## NumPy Library

A recent improvement of the RGB\_Display library makes use of NumPy for some additional speed. This can be installed with the following command:

```terminal
sudo apt-get install python3-numpy
```

That's it. You should be ready to go.

# Quickstart Button Test
This button test demo will test to make sure you have everything setup correctly. Go ahead and save the file to your Raspberry Pi in your home directory as **rgb\_display\_minipitfttest.py.**

https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/main/examples/rgb_display_minipitfttest.py

Go ahead and run it with this command:

```terminal
python3 rgb_display_minipitfttest.py
```

Once it is running, push the buttons. The top button should make the display light up **Red** , the bottom **Blue** , and pressing both at the same time should make it **Green**.

## Modifications for the 1.3" Display

To get the **stats.py** example to display properly on the 1.3" TFT Display, you will need to make some changes due to the different geometry of the display. The parameters you will need to adjust are the **height** , **width,**  **x\_offset** , **y\_offset** , and **rotation**.

The new values should be:

- `height = 240`
- `width = 240`
- `x_offset = 0`
- `y_offset = 80`
- `rotation = 180`

The easiest way to replace them may be to copy the following code block and replace it in the above code.

```python
# Create the ST7789 display:
disp = st7789.ST7789(
    spi,
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
    width=240,
    height=240,
    x_offset=0,
    y_offset=80,
)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new("RGB", (width, height))
rotation = 180
```

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Python Stats Example

Warning: 

We can also display some stats about your Pi such as the IP address, resource usage, and even the CPU Temperature. Start by saving the code below as **stats.py** in your home directory on your Raspberry Pi.

https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/main/examples/rgb_display_minipitftstats.py

Go ahead and run the script by typing:

`python3 stats.py`

It should display some system information.

![](https://cdn-learn.adafruit.com/assets/assets/000/082/938/medium800/adafruit_products_4393-06.jpg?1571946069)

## Modifications for the 1.3" Display

To get the **stats.py** example to display properly on the 1.3" TFT Display, you will need to make some changes due to the different geometry of the display. The parameters you will need to adjust are the **height** , **width** , **x\_offset** , **y\_offset** , and **rotation**.

The new values should be:

- `height = 240`
- `width = 240`
- `x_offset = 0`
- `y_offset = 80`
- `rotation = 180`

The easiest way to replace them may be to copy the following code block and replace it in the above code.

```python
# Create the ST7789 display:
disp = st7789.ST7789(
    spi,
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
    width=240,
    height=240,
    x_offset=0,
    y_offset=80,
)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new("RGB", (width, height))
rotation = 180
```

## Running Stats on Boot

You can pretty easily make it so this handy program runs every time you boot your Pi.

The fastest/easiest way is to put it in&nbsp; **/etc/rc.local**

Run&nbsp; **sudo nano /etc/rc.local** &nbsp;and add the line

`sudo python3 /home/pi/stats.py &`

on its own line right before&nbsp; **exit 0**

Then save and exit. Reboot to verify that the screen comes up on boot!

![](https://cdn-learn.adafruit.com/assets/assets/000/082/939/medium800/adafruit_products_1__pi_oledpi_____ssh_.png?1571946139)

[For more advanced usage, check out our linux system services guide](https://learn.adafruit.com/running-programs-automatically-on-your-tiny-computer/)

## Troubleshooting Stats on Boot

For the normal installation of Blinka on Raspberry Pi, we have you install stuff without the sudo keyword, which will install the libraries locally. However, to have the script run at boot, you will need to have the libraries available on a more system wide level. You can test this out by running the following command and see if the the stats come up:

`sudo python3 /home/pi/stats.py`

If you have any errors, most can be fixed by running the following command:

`sudo pip3 install --upgrade adafruit-blinka adafruit-circuitpython-rgb-display spidev`

Once you can get it to come up, go ahead and press Control+C and reboot the system. It should come up now.

Sometimes the Pi can boot too fast, so you may also need to add `sleep 10` on the line before the command you added in **/etc/rc.local**.

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Python Usage

Warning: 

Now that you have everything setup, we're going to look over three different examples. For the first, we'll take a look at automatically scaling and cropping an image and then centering it on the display.

## Turning on the Backlight

On some displays, the backlight is controlled by a separate pin such as the 1.3" TFT Bonnet with Joystick. On such displays, running the below code will likely result in the display remaining black. To turn on the backlight, you will need to add a small snippet of code. If your backlight pin number differs, be sure to change it in the code:

```python
# Turn on the Backlight
backlight = DigitalInOut(board.D26)
backlight.switch_to_output()
backlight.value = True
```

## Displaying an Image

Here's the full code to the example. We will go through it section by section to help you better understand what is going on. Let's start by downloading an image of Blinka. This image has enough border to allow resizing and cropping with a variety of display sizes and rations to still look good.

![](https://cdn-learn.adafruit.com/assets/assets/000/082/210/medium800/arduino_compatibles_blinka.jpg?1570817179)

Make sure you save it as **blinka.jpg** and place it in the same folder as your script. Here's the code we'll be loading onto the Raspberry Pi. We'll go over the interesting parts.

https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/main/examples/rgb_display_pillow_image.py

So we start with our usual imports including a couple of Pillow modules and the display drivers. That is followed by defining a few pins here. The reason we chose these is because they allow you to use the same code with the PiTFT if you chose to do so.

```python
import digitalio
import board
from PIL import Image, ImageDraw
import adafruit_rgb_display.ili9341 as ili9341
import adafruit_rgb_display.st7789 as st7789
import adafruit_rgb_display.hx8357 as hx8357
import adafruit_rgb_display.st7735 as st7735
import adafruit_rgb_display.ssd1351 as ssd1351
import adafruit_rgb_display.ssd1331 as ssd1331

# Configuration for CS and DC pins
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
```

Next we'll set the baud rate from the default 24 MHz so that it works on a variety of displays. The exception to this is the SSD1351 driver, which will automatically limit it to 16MHz even if you pass 24MHz. We'll set up out SPI bus and then initialize the display.

We wanted to make these examples work on as many displays as possible with very few changes. The ILI9341 display is selected by default. For other displays, go ahead and comment out these lines:

```python
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
```

and uncomment the line appropriate for your display and possibly the line below in the case of longer initialization sequences. The displays have a rotation property so that it can be set in just one place.

```python
#disp = st7789.ST7789(spi, rotation=90,                            # 2.0" ST7789
#disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180,  # 1.3", 1.54" ST7789
#disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789
#disp = hx8357.HX8357(spi, rotation=180,                           # 3.5" HX8357
#disp = st7735.ST7735R(spi, rotation=90,                           # 1.8" ST7735R
#disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3,   # 1.44" ST7735R
#disp = st7735.ST7735R(spi, rotation=90, bgr=True, width=80,       # 0.96" MiniTFT Rev A ST7735R
#disp = st7735.ST7735R(spi, rotation=90, invert=True, width=80,    # 0.96" MiniTFT Rev B ST7735R
#x_offset=26, y_offset=1,#disp = ssd1351.SSD1351(spi, rotation=180,                         # 1.5" SSD1351
#disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351
#disp = ssd1331.SSD1331(spi, rotation=180,                         # 0.96" SSD1331
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE
)
```

Next we read the current rotation setting of the display and if it is 90 or 270 degrees, we need to swap the width and height for our calculations, otherwise we just grab the width and height. We will create an `image` with our dimensions and use that to create a `draw` object. The `draw` object will have all of our drawing functions.

```python
# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
if disp.rotation % 180 == 90:
    height = disp.width   # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width   # we swap height/width to rotate it to landscape!
    height = disp.height
image = Image.new('RGB', (width, height))
 
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
```

Next we clear whatever is on the screen by drawing a black rectangle. This isn't strictly necessary since it will be overwritten by the image, but it kind of sets the stage.

```python
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
disp.image(image)
```

Next we open the Blinka image, which we've named **blinka.jpg** , which assumes it is in the same directory that you are running the script from. Feel free to change it if it doesn't match your configuration.

```python
image = Image.open("blinka.jpg")
```

Here's where it starts to get interesting. We want to scale the image so that it matches either the width or height of the display, depending on which is smaller, so that we have some of the image to chop off when we crop it. So we start by calculating the width to height ration of both the display and the image. If the height is the closer of the dimensions, we want to match the image height to the display height and let it be a bit wider than the display. Otherwise, we want to do the opposite.

Once we've figured out how we're going to scale it, we pass in the new dimensions and using a **Bicubic** rescaling method, we reassign the newly rescaled image back to `image`. Pillow has quite a few different methods to choose from, but Bicubic does a great job and is reasonably fast.

```python
# Scale the image to the smaller screen dimension
image_ratio = image.width / image.height
screen_ratio = width / height
if screen_ratio &lt; image_ratio:
    scaled_width = image.width * height // image.height
    scaled_height = height
else:
    scaled_width = width
    scaled_height = image.height * width // image.width
image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
```

Next we want to figure the starting x and y points of the image where we want to begin cropping it so that it ends up centered. We do that by using a standard centering function, which is basically requesting the difference of the center of the display and the center of the image. Just like with scaling, we replace the `image` variable with the newly cropped image.

```python
# Crop and center the image
x = scaled_width // 2 - width // 2
y = scaled_height // 2 - height // 2
image = image.crop((x, y, x + width, y + height))
```

Finally, we take our image and display it. At this point, the image should have the exact same dimensions at the display and fill it completely.

```python
disp.image(image)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/082/228/medium800/arduino_compatibles_2.2_Breakout_Image.jpeg?1570818097)

## Drawing Shapes and Text

In the next example, we'll take a look at drawing shapes and text. This is very similar to the displayio example, but it uses Pillow instead. Here's the code for that.

https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/main/examples/rgb_display_pillow_demo.py

Just like in the last example, we'll do our imports, but this time we're including the `ImageFont` Pillow module because we'll be drawing some text this time.

```python
import digitalio
import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_rgb_display.ili9341 as ili9341
```

Next we'll define some parameters that we can tweak for various displays. The `BORDER` will be the size in pixels of the green border between the edge of the display and the inner purple rectangle. The `FONTSIZE` will be the size of the font in points so that we can adjust it easily for different displays.

```python
BORDER = 20
FONTSIZE = 24
```

Next, just like in the previous example, we will set up the display, setup the rotation, and create a draw object. **If you have are using a different display than the ILI9341, go ahead and adjust your initializer as explained in the previous example.** After that, we will setup the background with a green rectangle that takes up the full screen. To get green, we pass in a tuple that has our **Red** , **Green** , and **Blue** color values in it in that order which can be any integer from `0` to `255`.

```python
draw.rectangle((0, 0, width, height), fill=(0, 255, 0))
disp.image(image)
```

Next we will draw an inner purple rectangle. This is the same color value as our example in displayio quickstart, except the hexadecimal values have been converted to decimal. We use the `BORDER` parameter to calculate the size and position that we want to draw the rectangle.

```python
draw.rectangle((BORDER, BORDER, width - BORDER - 1, height - BORDER - 1),
               fill=(170, 0, 136))
```

Next we'll load a TTF font. The `DejaVuSans.ttf` font should come preloaded on your Pi in the location in the code. We also make use of the `FONTSIZE` parameter that we discussed earlier.

```python
# Load a TTF Font
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', FONTSIZE)
```

Now we draw the text Hello World onto the center of the display. You may recognize the centering calculation was the same one we used to center crop the image in the previous example. In this example though, we get the font size values using the `getsize()` function of the font object.

```python
# Draw Some Text
text = "Hello World!"
(font_width, font_height) = font.getsize(text)
draw.text((width//2 - font_width//2, height//2 - font_height//2),
          text, font=font, fill=(255, 255, 0))
```

Finally, just like before, we display the image.

```python
disp.image(image)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/082/164/medium800/arduino_compatibles_2.2_Breakout_Demo.jpeg?1570647999)

## Displaying System Information

In this last example we'll take a look at getting the system information and displaying it. This can be very handy for system monitoring. Here's the code for that example:

https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/main/examples/rgb_display_pillow_stats.py

Just like the last example, we'll start by importing everything we imported, but we're adding two more imports. The first one is `time` so that we can add a small delay and the other is `subprocess` so we can gather some system information.

```python
import time
import subprocess
import digitalio
import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_rgb_display.ili9341 as ili9341
```

Next, just like in the first two examples, we will set up the display, setup the rotation, and create a draw object. **If you have are using a different display than the ILI9341, go ahead and adjust your initializer as explained in the previous example.**

Just like in the first example, we're going to draw a black rectangle to fill up the screen. After that, we're going to set up a couple of constants to help with positioning text. The first is the `padding` and that will be the Y-position of the top-most text and the other is `x` which is the X-Position and&nbsp;represents the left side of the text.

```python
# First define some constants to allow easy positioning of text.
padding = -2
x = 0
```

Next, we load a font just like in the second example.

```python
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)
```

Now we get to the main loop and by using `while True:`, it will loop until **Control+C** is pressed on the keyboard. The first item inside here, we clear the screen, but notice that instead of giving it a tuple like before, we can just pass `0` and it will draw black.

```python
draw.rectangle((0, 0, width, height), outline=0, fill=0)
```

Next, we run a few scripts using the `subprocess` function that get called to the Operating System to get information. The in each command is passed through awk in order to be formatted better for the display. By having the OS do the work, we don't have to. These little scripts came from `https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load`

```python
cmd = "hostname -I | cut -d\' \' -f1"
IP = "IP: "+subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB  %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB  %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "cat /sys/class/thermal/thermal_zone0/temp |  awk \'{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}\'" # pylint: disable=line-too-long
Temp = subprocess.check_output(cmd, shell=True).decode("utf-8")
```

Now we display the information for the user. Here we use yet another way to pass color information. We can pass it as a color string using the pound symbol, just like we would with HTML. With each line, we take the height of the line using `getsize()` and move the pointer down by that much.

```python
y = padding
draw.text((x, y), IP, font=font, fill="#FFFFFF")
y += font.getsize(IP)[1]
draw.text((x, y), CPU, font=font, fill="#FFFF00")
y += font.getsize(CPU)[1]
draw.text((x, y), MemUsage, font=font, fill="#00FF00")
y += font.getsize(MemUsage)[1]
draw.text((x, y), Disk, font=font, fill="#0000FF")
y += font.getsize(Disk)[1]
draw.text((x, y), Temp, font=font, fill="#FF00FF")
```

Finally, we write all the information out to the display using `disp.image()`. Since we are looping, we tell Python to sleep for `0.1` seconds so that the CPU never gets too busy.

```python
disp.image(image)
time.sleep(.1)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/082/169/medium800/arduino_compatibles_2.2_Breakout_Stats.jpeg?1570657644)

# Adafruit Mini PiTFT - Color TFT Add-ons for Raspberry Pi

## Downloads

# Files

- [Mini PiTFT display EagleCAD files on GitHub](https://github.com/adafruit/Adafruit-Mini-PiTFT-240x135-TFT-PCB)
- [1.14" 240x135 Fritzing object](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20Mini%20PiTFT%20-%20135x240%20Color%20TFT%20Add-on%20for%20Raspberry%20Pi.fzpz)
- [1.3" 240x240 Fritzing object](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20Mini%20PiTFT%201.3%20-%20240x240%20TFT%20Add-on%20for%20Raspberry%20Pi.fzpz)

# Datasheets
[Display Module datasheet](https://cdn-learn.adafruit.com/assets/assets/000/082/881/original/C13930-001_1.14__ZJY114IPS_datasheet.pdf?1571860941)
[ST7789VW datasheet 1.0](https://cdn-learn.adafruit.com/assets/assets/000/082/882/original/ST7789VW_SPEC_V1.0.pdf?1571860977)
# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/082/879/medium800/adafruit_products_schem.png?1571860665)

![](https://cdn-learn.adafruit.com/assets/assets/000/082/880/medium800/adafruit_products_fabprint.png?1571860853)

# Schematic and Fab print for 1.3" MiniTFT
![](https://cdn-learn.adafruit.com/assets/assets/000/096/407/medium800/adafruit_products_1-3in_Pi_MiniTFT_sch.png?1603729286)

![](https://cdn-learn.adafruit.com/assets/assets/000/096/413/medium800/adafruit_products_1-3in_Pi_MiniTFT_fab_print.png?1603730413)


## Primary Products

### Adafruit Mini PiTFT - 135x240 Color TFT Add-on for Raspberry Pi

[Adafruit Mini PiTFT - 135x240 Color TFT Add-on for Raspberry Pi](https://www.adafruit.com/product/4393)
If you're looking for the most compact li'l color display for a [Raspberry Pi](https://www.adafruit.com/category/361) (most&nbsp;likely a [Pi Zero](https://www.adafruit.com/category/813)) project, this might be just the thing you need!

The **...**

In Stock
[Buy Now](https://www.adafruit.com/product/4393)
[Related Guides to the Product](https://learn.adafruit.com/products/4393/guides)

## Featured Products

### Adafruit Mini PiTFT 1.3" - 240x240 TFT Add-on for Raspberry Pi

[Adafruit Mini PiTFT 1.3" - 240x240 TFT Add-on for Raspberry Pi](https://www.adafruit.com/product/4484)
If you're looking for the most compact li'l color display for a [Raspberry Pi](https://www.adafruit.com/category/361) (most&nbsp;likely a [Pi Zero](https://www.adafruit.com/category/813)) project, this might be just the thing you need!

The **...**

Out of Stock
[Buy Now](https://www.adafruit.com/product/4484)
[Related Guides to the Product](https://learn.adafruit.com/products/4484/guides)
### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

In Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long](https://www.adafruit.com/product/4401)
This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4401)
[Related Guides to the Product](https://learn.adafruit.com/products/4401/guides)

## Related Guides

- [PiTFT Python + Pillow Animated Gif Player](https://learn.adafruit.com/pitft-linux-python-animated-gif-player.md)
- [Raspberry Pi Rotary Encoder Animated Gif Player](https://learn.adafruit.com/python-rotary-animated-gif-player-two-different-ways.md)
- [Coffee Rater](https://learn.adafruit.com/coffee-rater.md)
- [Pi Hole Ad Blocker with Pi Zero W](https://learn.adafruit.com/pi-hole-ad-blocker-with-pi-zero-w.md)
- [PiPyPirate Radio](https://learn.adafruit.com/pipypirate-radio.md)
- [Adafruit ESP32 Feather V2](https://learn.adafruit.com/adafruit-esp32-feather-v2.md)
- [World's Smallest MAME Arcade Cabinet](https://learn.adafruit.com/worlds-smallest-mame-arcade-cabinet.md)
- [Adafruit eInk Display Breakouts and FeatherWings](https://learn.adafruit.com/adafruit-eink-display-breakouts.md)
- [CLUE Sensor Plotter in CircuitPython](https://learn.adafruit.com/clue-sensor-plotter-circuitpython.md)
- [Introducing Circuit Playground](https://learn.adafruit.com/introducing-circuit-playground.md)
- [Adafruit ESP32-S2 Feather](https://learn.adafruit.com/adafruit-esp32-s2-feather.md)
- [Wireless Dual Stepper Control with Adafruit IO, Raspberry Pi and Python](https://learn.adafruit.com/wireless-stepper-control-with-adafruit-io-circuitpython-raspberry-pi-python.md)
- [Adafruit 2.13" Monochrome E-Ink Bonnet for Raspberry Pi](https://learn.adafruit.com/2-13-in-e-ink-bonnet.md)
- [Meat Skull Centerpiece](https://learn.adafruit.com/meat-skull-centerpiece.md)
- [Adafruit Class Library for Windows IoT Core](https://learn.adafruit.com/adafruit-class-library-for-windows-iot-core.md)
