/ README.rst
README.rst
1 Introduction 2 ============ 3 4 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-rgb_display/badge/?version=latest 5 :target: https://circuitpython.readthedocs.io/projects/rgb_display/en/latest/ 6 :alt: Documentation Status 7 8 .. image :: https://img.shields.io/discord/327254708534116352.svg 9 :target: https://adafru.it/discord 10 :alt: Discord 11 12 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/workflows/Build%20CI/badge.svg 13 :target: https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/actions/ 14 :alt: Build Status 15 16 Port of display drivers from https://github.com/adafruit/micropython-adafruit-rgb-display to Adafruit CircuitPython for use on Adafruit's SAMD21-based and other CircuitPython boards. 17 18 .. note:: This driver currently won't work on micropython.org firmware, instead you want the micropython-adafruit-rgb-display driver linked above! 19 20 This CircuitPython driver currently supports displays that use the following display-driver chips: HX8353, HX8357, ILI9341, S6D02A1, ST7789, SSD1331, SSD1351, and ST7735 (including variants ST7735R and ST7735S). 21 22 Dependencies 23 ============= 24 This driver depends on: 25 26 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 27 * `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_ 28 29 Please ensure all dependencies are available on the CircuitPython filesystem. 30 This is easily achieved by downloading 31 `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_. 32 33 For the Pillow Examples, you will need to be running CPython. This means using a Single Board Computer 34 such as a Raspberry Pi or using a chip such as an FT232H on Linux, Window, or Mac. CircuitPython does 35 not support PIL/pillow (python imaging library)! 36 37 For improved performance consider installing NumPy. 38 39 Installing from PyPI 40 ==================== 41 42 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 43 PyPI <https://pypi.org/project/adafruit-circuitpython-rgb-display/>`_. To install for current user: 44 45 .. code-block:: shell 46 47 pip3 install adafruit-circuitpython-rgb-display 48 49 To install system-wide (this may be required in some cases): 50 51 .. code-block:: shell 52 53 sudo pip3 install adafruit-circuitpython-rgb-display 54 55 To install in a virtual environment in your current project: 56 57 .. code-block:: shell 58 59 mkdir project-name && cd project-name 60 python3 -m venv .env 61 source .env/bin/activate 62 pip3 install adafruit-circuitpython-rgb-display 63 64 Usage Example 65 ============= 66 67 2.2", 2.4", 2.8", 3.2" TFT 68 --------------------------- 69 70 .. code-block:: python 71 72 import time 73 import busio 74 import digitalio 75 from board import SCK, MOSI, MISO, D2, D3 76 77 from adafruit_rgb_display import color565 78 import adafruit_rgb_display.ili9341 as ili9341 79 80 81 # Configuration for CS and DC pins: 82 CS_PIN = D2 83 DC_PIN = D3 84 85 # Setup SPI bus using hardware SPI: 86 spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) 87 88 # Create the ILI9341 display: 89 display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN), 90 dc=digitalio.DigitalInOut(DC_PIN)) 91 92 # Main loop: 93 while True: 94 # Clear the display 95 display.fill(0) 96 # Draw a red pixel in the center. 97 display.pixel(120, 160, color565(255, 0, 0)) 98 # Pause 2 seconds. 99 time.sleep(2) 100 # Clear the screen blue. 101 display.fill(color565(0, 0, 255)) 102 # Pause 2 seconds. 103 time.sleep(2) 104 105 106 1.14" TFT with Raspbery Pi 4 107 ----------------------------- 108 109 With 1.14" `wiring <https://learn.adafruit.com/adafruit-1-14-240x135-color-tft-breakout/python-wiring-and-setup>`_, here is the working code: 110 111 .. code-block:: python 112 113 import time 114 import busio 115 import digitalio 116 from board import SCK, MOSI, MISO, CE0, D24, D25 117 118 from adafruit_rgb_display import color565 119 from adafruit_rgb_display.st7789 import ST7789 120 121 122 # Configuration for CS and DC pins: 123 CS_PIN = CE0 124 DC_PIN = D25 125 RESET_PIN = D24 126 BAUDRATE = 24000000 127 128 # Setup SPI bus using hardware SPI: 129 spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) 130 131 # Create the ST7789 display: 132 display = ST7789( 133 spi, 134 rotation=90, 135 width=135, 136 height=240, 137 x_offset=53, 138 y_offset=40, 139 baudrate=BAUDRATE, 140 cs=digitalio.DigitalInOut(CS_PIN), 141 dc=digitalio.DigitalInOut(DC_PIN), 142 rst=digitalio.DigitalInOut(RESET_PIN)) 143 144 # Main loop: same as above 145 while True: 146 # Clear the display 147 display.fill(0) 148 # Draw a red pixel in the center. 149 display.pixel(120, 160, color565(255, 0, 0)) 150 # Pause 2 seconds. 151 time.sleep(2) 152 # Clear the screen blue. 153 display.fill(color565(0, 0, 255)) 154 # Pause 2 seconds. 155 time.sleep(2) 156 157 158 Contributing 159 ============ 160 161 Contributions are welcome! Please read our `Code of Conduct 162 <https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display/blob/master/CODE_OF_CONDUCT.md>`_ 163 before contributing to help this project stay welcoming. 164 165 Documentation 166 ============= 167 168 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.