Skip to content

Added the ST7735 Display Driver #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Examples of unacceptable behavior by participants include:

The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you don’t just aim to be
"technically unimpeachable", but rather try to be your best self.
"technically unimpeachable", but rather try to be your best self.

We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
Expand Down Expand Up @@ -72,7 +72,7 @@ You may report in the following ways:
In any situation, you may send an email to <[email protected]>.

On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
to all Community Helpers by tagging @community moderators. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Expand Down
47 changes: 30 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,40 @@ Usage Example
=============

.. code-block:: python
import adafruit_st7735

import board
import busio
import displayio
import time

displayio.release_displays()
from adafruit_st7735 import ST7735

spi = busio.SPI(board.SCL, board.SDA)
bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8)
display = adafruit_st7735.ST7735(bus, width=128, height=128)
spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

s = displayio.Shape(10, 10)
p = displayio.Palette(2)
p[1] = 0xff0000
s = displayio.Sprite(s, pixel_shader=p, position=(0,0))
everything = displayio.Group(max_size=10)
everything.append(s)
display.show(everything)

time.sleep(10)
displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)

display = ST7735(display_bus, width=128, height=128)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 128, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

try:
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette,
position=(0, 0))
except TypeError:
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette,
x=0, y=0)
splash.append(bg_sprite)

while True:
pass

Contributing
============
Expand Down
57 changes: 24 additions & 33 deletions adafruit_st7735.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries LLC
# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams
# for Adafruit Industries LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,21 +21,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_ST7735`
`adafruit_st7735`
====================================================

Displayio driver for ST7735 based displays.

* Author(s): Scott Shawcroft
* Author(s): Melissa LeBlanc-Williams

Implementation Notes
--------------------

**Hardware:**

.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
inline format: "* `Link Text <url>`_"

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
Expand All @@ -47,35 +45,28 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git"


_INIT_SEQUENCE = (
b"\x01\x80\x96" # SWRESET
b"\x11\x80\xff" # SLPOUT
b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1
b"\xb2\x03\x01\x2C\x2D" #
b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D"
b"\xb4\x01\x07" # _INVCTR line inversion
b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA
b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V
b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency
b"\xc3\x02\x8a\x2a"
b"\xc4\x02\x8a\xee"
b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V
b"\x2a\x00" # _INVOFF
b"\x36\x01\x18" # _MADCTL bottom to top refresh
# 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
# fix on VTL
b"\x3a\x01\x05" # COLMOD - 16bit color
b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma
b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1
b"\x2a\x03\x02\x00\x81" # _CASET XSTART = 2, XEND = 129
b"\x2b\x03\x02\x00\x81" # _RASET XSTART = 2, XEND = 129
b"\x01\x80\x32" # _SWRESET and Delay 50ms
b"\x11\x80\xFF" # _SLPOUT
b"\x3A\x81\x05\x0A" # _COLMOD
b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1
b"\x36\x01\x08" # _MADCTL
b"\xB6\x02\x15\x02" # _DISSET5
#1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL
b"\xB4\x01\x00" # _INVCTR line inversion
b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay
b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V
b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency
b"\xC5\x82\x3C\x38\x0A" # _VMCTR1
b"\xFC\x02\x11\x15" # _PWCTR6
b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma
b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1
b"\x13\x80\x0a" # _NORON
b"\x29\x80\x64" # _DISPON
b"\x29\x80\xFF" # _DISPON
)

# pylint: disable=too-few-public-methods
class ST7735(displayio.Display):
"""ST7735 driver for ST7735R Green tabs"""
# TODO(tannewt): Add support for Red tabs and non-R chips. https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp
def __init__(self, bus, *, width, height):
super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2)
"""ST7735 driver"""
def __init__(self, bus, **kwargs):
super().__init__(bus, _INIT_SEQUENCE, **kwargs)
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
.. use this format as the module name: "adafruit_foo.foo"

.. automodule:: adafruit_st7735
:members:
:members:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio", "busio"]

autodoc_mock_imports = ["displayio"]

intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}

Expand Down
10 changes: 5 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Table of Contents
.. toctree::
:caption: Tutorials

.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
the toctree above for use later.

.. toctree::
:caption: Related Products

.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
the toctree above for use later.
1.8" SPI TFT display, 160x128 18-bit color <https://www.adafruit.com/product/618>
Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout <https://www.adafruit.com/product/3533>
1.8" Color TFT LCD display with MicroSD Card Breakout <https://www.adafruit.com/product/358>
Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout <https://www.adafruit.com/product/2088>
Adafruit Mini Color TFT with Joystick FeatherWing <https://www.adafruit.com/product/3321>

.. toctree::
:caption: Other Links
Expand Down
45 changes: 31 additions & 14 deletions examples/st7735_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import adafruit_st7735
"""
This test will initialize the display using displayio
and draw a solid red background
"""

import board
import busio
import displayio
import time
from adafruit_st7735 import ST7735

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)

display = ST7735(display_bus, width=128, height=128)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

spi = busio.SPI(board.SCL, board.SDA)
bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8)
display = adafruit_st7735.ST7735(bus, width=128, height=128)
color_bitmap = displayio.Bitmap(128, 128, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

s = displayio.Shape(10, 10)
p = displayio.Palette(2)
p[1] = 0xff0000
s = displayio.Sprite(s, pixel_shader=p, position=(0,0))
everything = displayio.Group(max_size=10)
everything.append(s)
display.show(everything)
try:
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette,
position=(0, 0))
except TypeError:
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette,
x=0, y=0)
splash.append(bg_sprite)

time.sleep(10)
while True:
pass