# RA8875 Touch Display Driver Board

## Overview

 **Revision History:**

- **As of August 14, 2023 –&nbsp;** We updated this board&nbsp;**(Rev E)**&nbsp;with&nbsp;a tristate circuit on MISO and a new backlight driver chip. It's also been updated&nbsp;with&nbsp;**[Adafruit Pinguin](https://github.com/adafruit/Adafruit_Pinguin)** to make a lovely and legible silkscreen. It is otherwise electrically and mechanically compatible!

![](https://cdn-learn.adafruit.com/assets/assets/000/124/400/medium800/lcds___displays_1590-09.jpg?1694710052)

Have you gazed longingly at large TFT displays - you know what I'm talking about here, 4", 5" or 7" TFTs with up to 800x480 pixels. Then you look at your Arduino. You love your Arduino (you really do!) but there's no way it can control a display like that, one that requires 60Hz refresh and 4 MHz pixel clocking. Heck, it doesn't even have enough pins. I suppose you could move to ARM core processors with TTL display drivers built in but you've already got all these shields working and anyways you like small micros you've got.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/398/medium800/lcds___displays_1590-06.jpg?1694709992)

What if I told you there was a driver chip that could fulfill those longings? A chip that can control up 800x480 displays, and heck, a resistive touchscreen as well. All you need to give up is 5 or so SPI pins. Would you even believe me? Well, sit down because this product may shock you.  
  
The RA8875 is a powerful TFT driver chip. It is a perfect match for any chip that wants to draw on a big TFT screen but doesn't quite have the oomph (whether it be hardware or speed). Inside is 768KB of RAM, so it can buffer the display (and depending on the screen size also have double overlaying). The interface is SPI with a very basic register read/write method of communication (no strange and convoluted packets). The chip has a range of hardware-accelerated shapes such as lines, rectangles, triangles, ellipses, built in and round-rects. There is also a built in English/European font set (see the datasheet section 7-4-1 for the font table) This makes it possible to draw fast even over SPI.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/399/medium800/lcds___displays_1590-10.jpg?1694710022)

The RA8875 can also handle standard 4-wire resistive touchscreens over the same SPI interface to save you pins. There's an IRQ pin that you can use to help manage touch interrupts. The touchscreen handler isn't the most precise driver we've used, so we broke out the X/Y pins so&nbsp;[you can connect them up to something like the STMPE610 which is a very classy touchscreen controller.](http://www.adafruit.com/products/1571)

![](https://cdn-learn.adafruit.com/assets/assets/000/071/341/medium800/lcds___displays_1590-04.jpg?1550380672)

On the PCB we have the main chip, level shifting so you can use safely with 3-5V logic. There is also a 3V regulator to provide clean power to the chip and the display. For the backlight, we put a constant-current booster that can provide 25mA or 50mA at up to 24V. The connector to the screen is a classic '40 pin' connector. All the 40-pin TFT's in the Adafruit shop are known to work well. There are other 40-pin displays that have different pinouts or backlight management and these may not work - they may even damage the driver or TFT if the boost converter pushes 24V into the display logic pins! For that reason, we only recommend the displays we've tested and sell here.  
  
Each order comes with an assembled, tested RA8875 breakout and a stick of header. You'll also need to purchase a 40-pin TFT screen. We currently have 4.3", 5.0" and 7.0" screens available.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/401/medium800/lcds___displays_1590-11.jpg?1694710074)

To get you started we've written a graphics library that handles the basic interfacing, drawing and reading functions.&nbsp;[Download the Adafruit RA8875 library from github](https://github.com/adafruit/Adafruit_RA8875)&nbsp;and&nbsp;[install as described in our tutorial.](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use)&nbsp;Connect a 40 pin TFT to the FPC port and wire up the SPI interface to an Arduino as described in the example code. Once started you'll be able to see the graphic/text demo and then touch the screen to 'paint'. For more advanced details on what the RA8875 can do (and it can do a lot) check the datasheet.

[**Please note!** &nbsp;The RA8875 does not tri-state the MISO pin on boards sold before August 14, 2023. It should not share that pin with any other SPI device (including an SD card reader) without the use of a 74HC125 or similar](https://forums.adafruit.com/viewtopic.php?f=47&t=60533&start=45#p323058)

For the level shifter we use the&nbsp;[CD74HC4050](http://www.ti.com/product/CD74HC4050)&nbsp;which has a typical propagation delay of ~10ns

# RA8875 Touch Display Driver Board

## Pinouts

 **Revision History:**

- **As of August 14, 2023 –&nbsp;** We updated this board&nbsp;**(Rev E)**&nbsp;with&nbsp;a tristate circuit on MISO and a new backlight driver chip. It's also been updated&nbsp;with&nbsp;**[Adafruit Pinguin](https://github.com/adafruit/Adafruit_Pinguin)** to make a lovely and legible silkscreen. It is otherwise electrically and mechanically compatible!

![](https://cdn-learn.adafruit.com/assets/assets/000/124/403/medium800/lcds___displays_main.jpg?1694710736)

## Power Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/124/404/medium800/lcds___displays_powerpins.jpg?1694710780)

These are the pins that are involved with powering the RA8875:

- **VIN** &nbsp;- power input, connect to 3-5VDC.
- **GND&nbsp;** - power and signal ground. Connect to your power supply and microcontroller ground.
- **3Vo&nbsp;** is the output from the onboard 3.3V regulator. If you have a need for a clean 3.3V output, you can use this! It can provide at least 100mA output.

## SPI Logic pins
![](https://cdn-learn.adafruit.com/assets/assets/000/124/405/medium800/lcds___displays_spi.jpg?1694710795)

All pins are 3-5 V compliant, so you can use with 3V or 5V micocontrollers

- **SCK** &nbsp;- this is the SPI clock pin, its an input to the chip
- **MISO** - this is the Microcontroller In Serial Out pin, for data sent from the RA8875 to your processor - this is 3.3V logic output, and can be read by 5V microcontrollers just fine.
  - **For Rev E: This pin _does_ tri-state when the CS pin is pulled low**
  - **For earlier versions: This pin _does not_ tri-state when the CS pin is pulled low,** so it cannot share an SPI bus without a tri-state chip like the 74HC125 or similar

- **MOSI** - this is the Microcontroller Out Serial In pin, for data sent from your processor to the RA8875
- **CS** &nbsp;- this is the chip select pin, drop it low to start an SPI transaction. Its an input to the chip. **This pin is not pulled high by default! Please either set it high or add a pullup resistor to keep the chip disabled!**

## Touch Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/124/407/medium800/lcds___displays_touch.jpg?1694710820)

These are the pins that are involved with the touch panel for the RA8875. The X and Y pairs of pins are ideal for reading touches using an external touch controller such as the [TSC2007](https://www.adafruit.com/product/5423) or [TSC2046](https://www.adafruit.com/product/5767):

- **INT** - interrupt pin that goes low when the panel is being touched
- **Y+&nbsp;** - touch panel Y positive signal
- **Y-&nbsp;** - touch panel Y negative signal
- **X+&nbsp;** - touch panel X positive signal
- **X-&nbsp;** - touch panel X negative signal

## Other Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/124/408/medium800/lcds___displays_other.jpg?1694710844)

These are the remaining pins for the RA8875:

- **LITE** &nbsp;- PWM Signal used to externally control the Backlight
- **RST&nbsp;** - Reset line for the RA8875. It is active low meaning you would reset the RA8875 by pulling this pin to ground.
- **WAIT&nbsp;** - output to indicate that the RA8875 is in a busy state. The RA8875 can't communicate with the microcontroller when the wait pin is active. It is active low and could be used by the microcontroller to poll busy status.

## TFT Connector
Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/124/409/medium800/lcds___displays_tft.jpg?1694710958)

This 40-pin connector is where you would attach your TFT display.

# RA8875 Touch Display Driver Board

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/124/410/medium800/lcds___displays_1590-09.jpg?1694711180)

Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard -&nbsp; **long pins down**

![lcds___displays_Step_A.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/884/medium640/lcds___displays_Step_A.jpg?1551078474)

Place the breakout board over the pins so that the short pins poke through the breakout pads

![lcds___displays_Step_B.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/888/medium640/lcds___displays_Step_B.jpg?1551079482)

Be sure to solder all pins for reliable electrical contact.  
  
_(For tips on soldering, be sure to check out our&nbsp;_[_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._

![lcds___displays_Step_C.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/886/medium640/lcds___displays_Step_C.jpg?1551079449)

![lcds___displays_Step_D.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/887/medium640/lcds___displays_Step_D.jpg?1551079459)

Check your solder joints visually and continue onto the next steps

![lcds___displays_Step_E.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/889/medium640/lcds___displays_Step_E.jpg?1551079531)

Connect the LCD. Very carefully slide the ears out, insert the cable with the gold contacts facing up, then slide the ears back in.

![lcds___displays_Step_F.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/890/medium640/lcds___displays_Step_F.jpg?1551080365)

You're done! Continue on to the next steps.

![lcds___displays_Step_G.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/891/medium640/lcds___displays_Step_G.jpg?1551080684)

# RA8875 Touch Display Driver Board

## Arduino Code

To get this display working on the Arduino, first we will need to install a couple of Arduino libraries.

## Install Arduino Libraries

Lets begin by installing all the libraries we need. Open up the library manager in Arduino IDE

![](https://cdn-learn.adafruit.com/assets/assets/000/072/402/medium800/lcds___displays_Manage_Libraries?1551940761)

Search for and install the Following libraries:

### Adafruit GFX
![](https://cdn-learn.adafruit.com/assets/assets/000/072/403/medium800/lcds___displays_Adafruit_GFX?1551941580)

If using an earlier version of the Arduino IDE (pre-1.8.10), locate and install **Adafruit\_BusIO** (newer versions handle this prerequisite automatically).

### Adafruit RA8875
![](https://cdn-learn.adafruit.com/assets/assets/000/072/404/medium800/lcds___displays_Adafruit_RA8875?1551941624)

Once you have installed these, restart the Arduino IDE

## Arduino Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/071/907/medium800/lcds___displays_RA8875_Arduino_bb.jpg?1551112606)

Start by connecting the power pins

- **3-5V Vin** &nbsp;connects to the Arduino&nbsp; **5V** &nbsp;pin
- **GND** &nbsp;connects to Arduino ground
- **SCK** &nbsp;connects to SPI clock. On Arduino Uno/Duemilanove/328-based, thats&nbsp; **Digital 13**. On Mega's, its&nbsp; **Digital 52** &nbsp;and on Leonardo/Due/Metro M0/M4 it's&nbsp; **ICSP-3** &nbsp;([See SPI Connections for more details](http://arduino.cc/en/Reference/SPI))
- **MISO** &nbsp;connects to SPI MISO. On Arduino Uno/Duemilanove/328-based, thats&nbsp; **Digital 12**. On Mega's, its&nbsp; **Digital 50** &nbsp;and on Leonardo/Due/Metro M0/M4 it's&nbsp; **ICSP-1** &nbsp;([See SPI Connections for more details](http://arduino.cc/en/Reference/SPI))
- **MOSI** &nbsp;connects to SPI MOSI. On Arduino Uno/Duemilanove/328-based, thats&nbsp; **Digital 11**. On Mega's, its&nbsp; **Digital 51** &nbsp;and on Leonardo/Due/Metro M0/M4 it's&nbsp; **ICSP-4** &nbsp;([See SPI Connections for more details](http://arduino.cc/en/Reference/SPI "Link: http://arduino.cc/en/Reference/SPI"))
- **CS** &nbsp;connects to our SPI Chip Select pin. We'll be using&nbsp; **Digital 10** &nbsp;but you can later change this to any pin
- **RST** &nbsp;connects to our Reset pin. We'll be using&nbsp; **Digital 9** &nbsp;but you can later change this pin as well.
- **INT** &nbsp;connects to our Interrupt pin. We'll be using&nbsp; **Digital 3** &nbsp;but you can later change this pin too.

That's it! You don't need to connect any of the other pins.

## Build Test

Start by opening up the **file -\> examples -\> Adafruit RA8875 -\> buildtest** :

![](https://cdn-learn.adafruit.com/assets/assets/000/072/405/medium800/lcds___displays_buildtest_Example?1551942767)

Be sure to set the screen size in the sketch to the appropriate size and upload it to your Arduino

You'll see a graphics test program run, showing drawing lines, text, rectangles, ellipses, triangles, etc.

![](https://cdn-learn.adafruit.com/assets/assets/000/072/431/medium800/lcds___displays_buildtest_Output.png?1552018421)

Feel free to touch the screen if your LCD Display is a touchscreen. The screen will start drawing dots where your finger was.

## Text Mode

Unlike many displays, the RA8875 requires switching modes between drawing text and graphics. They can still be drawn on the screen at the same time, but you are required to manually set the appropriate mode for the type of function you wish to call.

Start by opening up the&nbsp; **file -\> examples -\> Adafruit RA8875 -\> textmode**

![](https://cdn-learn.adafruit.com/assets/assets/000/072/433/medium800/lcds___displays_textmode_Example.png?1552019759)

Just like the previous example, be sure to set the screen size in the sketch to the appropriate size and upload it to your Arduino

You'll see a text mode test print out "Hello, World!" in a variety of colors and sizes.

![](https://cdn-learn.adafruit.com/assets/assets/000/072/435/medium800/lcds___displays_textmode_Output.jpg?1552020450)

# RA8875 Touch Display Driver Board

## CircuitPython Code

It is very easy to use the RA8875 with CircuitPython. We recommend using an M4 based board due to the size of library.

## CircuitPython Microcontroller Wiring

Start by connecting the power pins

- **3-5V Vin** &nbsp;connects to the Feather's&nbsp; **USB** &nbsp;pin
- **GND** &nbsp;connects to the Feather's ground
- **SCK** &nbsp;connects to SPI clock. On the Feather M4 Express, thats also&nbsp; **SCK**
- **MISO** &nbsp;connects to SPI MISO. On the Feather M4 Express, thats **MI**
- **MOSI** &nbsp;connects to SPI MOSI. On the Feather M4 Express, thats **MO**
- **CS** &nbsp;connects to our SPI Chip Select pin. We'll be using&nbsp; **Digital 9** &nbsp;but you can later change this to any pin
- **RST** &nbsp;connects to our Reset pin. We'll be using&nbsp; **Digital 10** &nbsp;but you can later change this pin as well.
- **INT** &nbsp;connects to our Interrupt pin. This pin is actually optional, but improves the accuracy. We'll be using&nbsp; **Digital 11** &nbsp;but you can later change this pin too.

That's it! You don't need to connect any of the other pins.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/893/medium800/lcds___displays_RA8875_fritzing.jpg?1551083550)

## Library Installation

You'll need to install the&nbsp;[Adafruit CircuitPython RA8875](https://github.com/adafruit/Adafruit_CircuitPython_RA8875)&nbsp;library on your CircuitPython board.&nbsp;

You will also need to install the [Adafruit CircuitPython BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) library which is the only dependency.

First, make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next, you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).&nbsp; Our introduction guide has&nbsp;[a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries)&nbsp;for both express and non-express boards.

Remember for non-express boards, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_ra8875**
- **adafruit\_bus\_device**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_ra8875** and&nbsp; **adafruit\_bus\_device&nbsp;** folders **&nbsp;** copied over.

## Usage

To demonstrate the usage of the display, we'll use the example python script included with the library.&nbsp;

https://github.com/adafruit/Adafruit_CircuitPython_RA8875/blob/main/examples/ra8875_simpletest.py

![](https://cdn-learn.adafruit.com/assets/assets/000/073/302/medium800/lcds___displays_simpletest.jpg?1552887185)

We start out by importing any libraries we want to use in our code. This includes a special function that converts 24-bit color into 16-bit color which is what this display uses.

```
import time
import busio
import digitalio
import board

import adafruit_ra8875.ra8875 as ra8875
from adafruit_ra8875.ra8875 import color565
```

Next, we define a bunch of colors for ease of reuse.

```python
BLACK = color565(0, 0, 0)
RED = color565(255, 0, 0)
BLUE = color565(0, 255, 0)
GREEN = color565(0, 0, 255)
YELLOW = color565(255, 255, 0)
CYAN = color565(0, 255, 255)
MAGENTA = color565(255, 0, 255)
WHITE = color565(255, 255, 255)
```

Next, we initialize SPI and the display. 6 MHz was about the fastest that it would stably run in CircuitPython. Initialization is much easier in CircuitPython. By default this runs for a display of 800x480 pixels in size. If you have a display of a different size such as the 480x272, you could pass the width and height parameters into the constructor.

```
# Configuration for CS and RST pins:
cs_pin = digitalio.DigitalInOut(board.D9)
rst_pin = digitalio.DigitalInOut(board.D10)
int_pin = digitalio.DigitalInOut(board.D11)

# Config for display baudrate (default max is 6mhz):
BAUDRATE = 6000000

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Create and setup the RA8875 display:
display = ra8875.RA8875(spi, cs=cs_pin, rst=rst_pin, baudrate=BAUDRATE)
display.init()
```

Next, we fill the screen with a few different colors.

```
display.fill(RED)
time.sleep(0.500)
display.fill(YELLOW)
time.sleep(0.500)
display.fill(BLUE)
time.sleep(0.500)
display.fill(CYAN)
time.sleep(0.500)
display.fill(MAGENTA)
time.sleep(0.500)
```

After that, we clear the screen and draw a bunch of different shapes to demonstrate the hardware accelerated shape drawing functions.

```
display.fill(BLACK)
display.circle(100, 100, 50, BLACK)
display.fill_circle(100, 100, 49, BLUE)

display.fill_rect(11, 11, 398, 198, GREEN)
display.rect(10, 10, 400, 200, BLUE)
display.fill_round_rect(200, 10, 200, 100, 10, RED)
display.round_rect(199, 9, 202, 102, 12, BLUE)
display.pixel(10, 10, BLACK)
display.pixel(11, 11, BLACK)
display.line(10, 10, 200, 100, RED)
display.triangle(200, 15, 250, 100, 150, 125, BLACK)
display.fill_triangle(200, 16, 249, 99, 151, 124, YELLOW)
display.ellipse(300, 100, 100, 40, RED)
display.fill_ellipse(300, 100, 98, 38, BLUE)
display.curve(50, 100, 80, 40, 2, BLACK)
display.fill_curve(50, 100, 78, 38, 2, WHITE)
```

Next, we draw some text on the screen. Please note that unlike the Arduino library, mode changing is automatically handled in the library.

```
display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
display.txt_trans(WHITE)
display.txt_size(2)
testvar = 99
display.txt_write("Player Score: " + str(testvar))
```

Finally, touch is enabled and in the main loop we read the coordinates of the text, display where the touch occurred on the screen and draw circles in that location.

```
display.touch_init(int_pin)
display.touch_enable(True)

x_scale = 1024 / display.width
y_scale = 1024 / display.height

# Main loop:
while True:
    if display.touched():
        coords = display.touch_read()
        display.fill_circle(int(coords[0]/x_scale), int(coords[1]/y_scale), 4, MAGENTA)
        display.txt_color(WHITE, BLACK)
        display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
        display.txt_size(2)
        display.txt_write("Position (" + str(int(coords[0]/x_scale)) + ", " +
                          str(int(coords[1]/y_scale)) + ")")
```

## Loading a Bitmap

In this next example, we'll decode and load a bitmap that is stored as a file on the MicroController. Although the image is included in the examples folder of the library, we have provided a link to it for your convenience.

[Click here to Download ra8875_blinka.bmp](https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_RA8875/master/examples/ra8875_blinka.bmp)
https://github.com/adafruit/Adafruit_CircuitPython_RA8875/blob/main/examples/ra8875_bmptest.py

![](https://cdn-learn.adafruit.com/assets/assets/000/073/303/medium800/lcds___displays_bmptest.jpg?1552887354)

Let's dive in and take a look at how the code works. Just like the previous example, we start out by importing the libraries we need. In this case, we also need struct to help with color encoding.

```
import busio
import digitalio
import board

import adafruit_ra8875.ra8875 as ra8875
from adafruit_ra8875.ra8875 import color565
try:
    import struct
except ImportError:
    import ustruct as struct
```

White is the only color we will use, so we define that here.

```
WHITE = color565(255, 255, 255)
```

Next, we initialize the screen and set the background to white.

```
# Configuration for CS and RST pins:
cs_pin = digitalio.DigitalInOut(board.D9)
rst_pin = digitalio.DigitalInOut(board.D10)

# Config for display baudrate (default max is 6mhz):
BAUDRATE = 6000000

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Create and setup the RA8875 display:
display = ra8875.RA8875(spi, cs=cs_pin, rst=rst_pin, baudrate=BAUDRATE)
display.init()
display.fill(WHITE)

```

We have a helper function next for decoding 16-bit bitmaps into the correct bit structure. Even though we are using a 24-bit bmp in this example, if you would like to replace the image with one of your own and it happens to be a 16-bit bitmap, it will still work.

```
def convert_555_to_565(rgb):
    return (rgb &amp; 0x7FE0) &lt;&lt; 1 | 0x20 | rgb &amp; 0x001F
```

After that, we define a BMP class that will read the headers, decode the bitmap, and draw it to the screen. It starts off by initializing all of the values to 0 or None.

```
class BMP(object):
    def __init__(self, filename):
        self.filename = filename
        self.colors = None
        self.data = 0
        self.data_size = 0
        self.bpp = 0
        self.width = 0
        self.height = 0
        self.read_header()
```

Then it goes through and reads the important information in the header at specific places in the file. In this case, the bytes are in little endian format which means the bytes are arranged with starting with the least significant byte values are at the smallest address. If you are interested, you can read more about endianness, on&nbsp;[Wikipedia.](https://en.wikipedia.org/wiki/Endianness#Little-endian)

```
    def read_header(self):
        if self.colors:
            return
        with open(self.filename, 'rb') as f:
            f.seek(10)
            self.data = int.from_bytes(f.read(4), 'little')
            f.seek(18)
            self.width = int.from_bytes(f.read(4), 'little')
            self.height = int.from_bytes(f.read(4), 'little')
            f.seek(28)
            self.bpp = int.from_bytes(f.read(2), 'little')
            f.seek(34)
            self.data_size = int.from_bytes(f.read(4), 'little')
            f.seek(46)
            self.colors = int.from_bytes(f.read(4), 'little')
```

In the Draw function we read the appropriate amount of data depending on the file encoding, make sure it's in a format that the display understands, and push it to the display. Because the data is pushed directly out to the RA8875, the amount of memory required is pretty minimal.

```
    def draw(self, disp, x=0, y=0):
        print("{:d}x{:d} image".format(self.width, self.height))
        print("{:d}-bit encoding detected".format(self.bpp))
        line = 0
        line_size = self.width * (self.bpp//8)
        if line_size % 4 != 0:
            line_size += (4 - line_size % 4)
        current_line_data = b''
        with open(self.filename, 'rb') as f:
            f.seek(self.data)
            disp.set_window(x, y, self.width, self.height)
            for line in range(self.height):
                current_line_data = b''
                line_data = f.read(line_size)
                for i in range(0, line_size, self.bpp//8):
                    if (line_size-i) &lt; self.bpp//8:
                        break
                    if self.bpp == 16:
                        color = convert_555_to_565(line_data[i] | line_data[i+1] &lt;&lt; 8)
                    if self.bpp == 24 or self.bpp == 32:
                        color = color565(line_data[i+2], line_data[i+1], line_data[i])
                    current_line_data = current_line_data + struct.pack("&gt;H", color)
                disp.setxy(x, self.height - line + y)
                disp.push_pixels(current_line_data)
            disp.set_window(0, 0, disp.width, disp.height)
```

Finally, we declare our class, figure out the center of the screen and draw the bitmap. This allows it to display on both the larger and smaller screens.

```
bitmap = BMP("/ra8875_blinka.bmp")
x_position = (display.width // 2) - (bitmap.width // 2)
y_position = (display.height // 2) - (bitmap.height // 2)
bitmap.draw(display, x_position, y_position)
```

# RA8875 Touch Display Driver Board

## Python Wiring and Usage

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

We'll cover how to wire the display to your Raspberry Pi. First assemble your display.

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: 

- **3-5V Vin** connects to the Raspberry Pi's **3V** &nbsp;pin
- **GND** connects to the Raspberry Pi's **ground**
- **SCK** connects to SPI clock. On the Raspberry Pi, thats **SLCK**
- **MISO** connects to SPI MISO. On the Raspberry Pi, thats also **MISO**
- **MOSI** connects to SPI MOSI. On the Raspberry Pi, thats also **MOSI**
- **CS** &nbsp;connects to our SPI Chip Select pin. We'll be using&nbsp; **GPIO 13.**
- **RST** &nbsp;connects to our Reset pin. We'll be using&nbsp; **GPIO 5** but you can later change this pin later.
- **INT** &nbsp;connects to our Interrupt pin. This pin is actually optional, but improves the accuracy. We'll be using&nbsp; **GPIO 6** &nbsp;but you can later change this pin too.

![](https://cdn-learn.adafruit.com/assets/assets/000/091/172/medium800/lcds___displays_RA8875_bb.jpg?1589498569)

[Download Fritzing Diagram](https://cdn-learn.adafruit.com/assets/assets/000/091/173/original/RA8875.fzz?1589498651)
## 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)!

### Python Installation of RA8875 Library

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

- `sudo pip3 install adafruit-circuitpython-ra8875`

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:

- `sudo apt-get install python3-pip`

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

## Usage

To use the RA8875 with the Raspberry Pi, you only need to make one or two changes to the CircuitPython examples in order to use them on the Pi.

### Pin Mapping

First we need to change the Pin mapping because some of the pins that are used on the Feather are not available on the Raspberry Pi. Find the section with the following code:

```python
cs_pin = digitalio.DigitalInOut(board.D9)
rst_pin = digitalio.DigitalInOut(board.D10)
int_pin = digitalio.DigitalInOut(board.D11)
```

and change it to the following:

```python
cs_pin = digitalio.DigitalInOut(board.D13)
rst_pin = digitalio.DigitalInOut(board.D5)
int_pin = digitalio.DigitalInOut(board.D6)
```

### Display Size

Next, the driver defaults to the **480x800** sized display. If you have a different size, you will need to add a couple of parameters. Find the line that looks like this:

```python
display = ra8875.RA8875(spi, cs=cs_pin, rst=rst_pin, baudrate=BAUDRATE)
```

And go ahead and add a `width` and `height` parameter so if for instance, you had the 480x272 display, it would look like this:

```python
display = ra8875.RA8875(spi, cs=cs_pin, rst=rst_pin, baudrate=BAUDRATE, width=480, height=272)
```

That should be it. You should be able to run both examples as described on the CircuitPython page.

# RA8875 Touch Display Driver Board

## Downloads

## Files & Datasheets

- [RA8875 Full Datasheet](https://cdn-shop.adafruit.com/datasheets/RA8875_DS_V19_Eng.pdf)
- [RA8875 App note](https://cdn-shop.adafruit.com/datasheets/ra8875+app+note.pdf)
- [Fritzing object in Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library/raw/master/parts/Adafruit%20RA8875%20Driver%20Board%20for%2040-pin%20TFT%20Touch%20Displays.fzpz)
- [EagleCAD PCB Files on GitHub](https://github.com/adafruit/Adafruit-RA8875-Breakout-Board-PCB)

## Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/124/420/medium800/lcds___displays_RA8875_Schematic.png?1694716073)

## Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/124/426/medium800/lcds___displays_RA8875_Fab_Print.png?1694716469)


## Primary Products

### RA8875 Driver Board for 40-pin TFT Touch Displays - 800x480 Max

[RA8875 Driver Board for 40-pin TFT Touch Displays - 800x480 Max](https://www.adafruit.com/product/1590)
Have you gazed longingly at large TFT displays - you know what I'm talking about here, 4", 5" or 7" TFTs with up to 800x480 pixels. Then you look at your Arduino. You love your Arduino (you really do!) but there's no way it can control a display like that, one that...

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

## Featured Products

### 7.0" 40-pin TFT Display - 800x480 with Touchscreen

[7.0" 40-pin TFT Display - 800x480 with Touchscreen](https://www.adafruit.com/product/2354)
This 7.0" TFT screen has lots of pixels, 800x480 to be exact, an LED backlight and a resistive touchscreen overlay. Its great for when you need a lot of space for graphics or a user interface. These screens are commonly seen in consumer electronics, such as miniature TV's, GPS's,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2354)
[Related Guides to the Product](https://learn.adafruit.com/products/2354/guides)
### 5.0" 40-pin TFT Display - 800x480 with Touchscreen

[5.0" 40-pin TFT Display - 800x480 with Touchscreen](https://www.adafruit.com/product/1596)
This 5.0" TFT screen has lots of pixels, 800x480 to be exact, an LED backlight and a resistive touchscreen overlay. Its great for when you need a lot of space for graphics or a user interface. These screens are commonly seen in consumer electronics, such as miniature TV's, GPS's,...

In Stock
[Buy Now](https://www.adafruit.com/product/1596)
[Related Guides to the Product](https://learn.adafruit.com/products/1596/guides)
### 4.3" 40-pin TFT Display - 480x272 with Touchscreen

[4.3" 40-pin TFT Display - 480x272 with Touchscreen](https://www.adafruit.com/product/1591)
This 4.3" TFT screen has lots of pixels, 480x272 to be exact, an LED backlight and a resistive touchscreen overlay. Its great for when you need a lot of space for graphics or a user interface. These screens are commonly seen in consumer electronics, such as miniature TVs, GPSs, handheld...

In Stock
[Buy Now](https://www.adafruit.com/product/1591)
[Related Guides to the Product](https://learn.adafruit.com/products/1591/guides)
### Resistive Touch Screen Controller - STMPE610

[Resistive Touch Screen Controller - STMPE610](https://www.adafruit.com/product/1571)
Getting touchy performance with your screen's touch screen? Resistive touch screens are incredibly popular as overlays to TFT and LCD displays. Only problem is they require a bunch of analog pins and you have to keep polling them since the overlays themselves are basically just big...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1571)
[Related Guides to the Product](https://learn.adafruit.com/products/1571/guides)
### 74AHCT125 - Quad Level-Shifter (3V to 5V)

[74AHCT125 - Quad Level-Shifter (3V to 5V)](https://www.adafruit.com/product/1787)
Level shifting chips let you connect 3V and 5V devices together safely. This chip is similar to others in the shop (such as the 74LVC125) except this one is particularly good at converting **3V logic up to 5V**. This is in demand, especially when connecting some 3V devices such as...

In Stock
[Buy Now](https://www.adafruit.com/product/1787)
[Related Guides to the Product](https://learn.adafruit.com/products/1787/guides)
### Adjustable Bent-Wire Stand - up to 7" Tablets and Small Screens

[Adjustable Bent-Wire Stand - up to 7" Tablets and Small Screens](https://www.adafruit.com/product/1679)
This handy bent-wire display stand was originally designed to hold up 7" tablets but the rubberized design is great for general purpose electronics & TFT holding. We use it to hold up our HDMI displays while connected to a Pi - even though it is meant for 7" we found that its...

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

## Related Guides

- [Processing on the Raspberry Pi & PiTFT](https://learn.adafruit.com/processing-on-the-raspberry-pi-and-pitft.md)
- [Adafruit TFP401 HDMI/DVI Decoder to 40-pin TTL Display](https://learn.adafruit.com/adafruit-tfp401-hdmi-slash-dvi-decoder-to-40-pin-ttl-display.md)
- [Adafruit DPI Display Kippah](https://learn.adafruit.com/adafruit-dpi-display-kippah-ttl-tft.md)
- [Qualia S3 Compass](https://learn.adafruit.com/qualia-s3-compass.md)
- [Asteroid Tracker](https://learn.adafruit.com/asteroid-tracker.md)
- [Cartoon Character Clock](https://learn.adafruit.com/cartoon-character-clock.md)
- [Karel The Robot In CircuitPython](https://learn.adafruit.com/karel-the-robot-in-circuitpython.md)
- [A colorful CLUE slideshow purse with Bright Wearables](https://learn.adafruit.com/a-colorful-clue-slideshow-purse.md)
- [Feather ESP32-S3 TFT CircuitPython Day 2024 Countdown Clock](https://learn.adafruit.com/feather-esp32-s3-tft-circuitpython-day-2024-countdown-clock.md)
- [Cardboard Window Skull With Animated LED Eyes](https://learn.adafruit.com/cardboard-window-skull-animated-led-eyes.md)
- [Scrolling Countdown Timer](https://learn.adafruit.com/scrolling-countdown-timer.md)
- [CircuitPython Elgato WiFi Light Controller](https://learn.adafruit.com/circuitpython-elgato-wifi-light-controller.md)
- [Adafruit EYESPI Pi Beret](https://learn.adafruit.com/eyespi-pi-beret.md)
- [PyPortal Word of the Day Display](https://learn.adafruit.com/pyportal-word-of-the-day-display.md)
- [Adafruit 1.9" Color IPS TFT Display](https://learn.adafruit.com/adafruit-1-9-color-ips-tft-display.md)
