Skip to content

Commit 5f02c0d

Browse files
authored
Merge pull request #2 from makermelissa/master
Added the ST7735 Display Driver
2 parents f0d2565 + b984037 commit 5f02c0d

File tree

7 files changed

+94
-73
lines changed

7 files changed

+94
-73
lines changed

CODE_OF_CONDUCT.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Examples of unacceptable behavior by participants include:
4141

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

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

7474
On the Adafruit Discord, you may send an open message from any channel
75-
to all Community Helpers by tagging @community helpers. You may also send an
75+
to all Community Helpers by tagging @community moderators. You may also send an
7676
open message from any channel, or a direct message to @kattni#1507,
7777
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
7878
@Andon#8175.

README.rst

+30-17
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,40 @@ Usage Example
2929
=============
3030

3131
.. code-block:: python
32-
import adafruit_st7735
32+
3333
import board
34-
import busio
3534
import displayio
36-
import time
37-
38-
displayio.release_displays()
35+
from adafruit_st7735 import ST7735
3936
40-
spi = busio.SPI(board.SCL, board.SDA)
41-
bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8)
42-
display = adafruit_st7735.ST7735(bus, width=128, height=128)
37+
spi = board.SPI()
38+
tft_cs = board.D5
39+
tft_dc = board.D6
4340
44-
s = displayio.Shape(10, 10)
45-
p = displayio.Palette(2)
46-
p[1] = 0xff0000
47-
s = displayio.Sprite(s, pixel_shader=p, position=(0,0))
48-
everything = displayio.Group(max_size=10)
49-
everything.append(s)
50-
display.show(everything)
51-
52-
time.sleep(10)
41+
displayio.release_displays()
42+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
43+
44+
display = ST7735(display_bus, width=128, height=128)
45+
46+
# Make the display context
47+
splash = displayio.Group(max_size=10)
48+
display.show(splash)
49+
50+
color_bitmap = displayio.Bitmap(128, 128, 1)
51+
color_palette = displayio.Palette(1)
52+
color_palette[0] = 0xFF0000
53+
54+
try:
55+
bg_sprite = displayio.TileGrid(color_bitmap,
56+
pixel_shader=color_palette,
57+
position=(0, 0))
58+
except TypeError:
59+
bg_sprite = displayio.TileGrid(color_bitmap,
60+
pixel_shader=color_palette,
61+
x=0, y=0)
62+
splash.append(bg_sprite)
63+
64+
while True:
65+
pass
5366
5467
Contributing
5568
============

adafruit_st7735.py

100644100755
+24-33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The MIT License (MIT)
22
#
3-
# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries LLC
3+
# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams
4+
# for Adafruit Industries LLC
45
#
56
# Permission is hereby granted, free of charge, to any person obtaining a copy
67
# of this software and associated documentation files (the "Software"), to deal
@@ -20,21 +21,18 @@
2021
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2122
# THE SOFTWARE.
2223
"""
23-
`adafruit_ST7735`
24+
`adafruit_st7735`
2425
====================================================
2526
2627
Displayio driver for ST7735 based displays.
2728
28-
* Author(s): Scott Shawcroft
29+
* Author(s): Melissa LeBlanc-Williams
2930
3031
Implementation Notes
3132
--------------------
3233
3334
**Hardware:**
3435
35-
.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
36-
inline format: "* `Link Text <url>`_"
37-
3836
**Software and Dependencies:**
3937
4038
* Adafruit CircuitPython firmware for the supported boards:
@@ -47,35 +45,28 @@
4745
__version__ = "0.0.0-auto.0"
4846
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git"
4947

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

68+
# pylint: disable=too-few-public-methods
7769
class ST7735(displayio.Display):
78-
"""ST7735 driver for ST7735R Green tabs"""
79-
# TODO(tannewt): Add support for Red tabs and non-R chips. https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp
80-
def __init__(self, bus, *, width, height):
81-
super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2)
70+
"""ST7735 driver"""
71+
def __init__(self, bus, **kwargs):
72+
super().__init__(bus, _INIT_SEQUENCE, **kwargs)

docs/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
.. use this format as the module name: "adafruit_foo.foo"
66
77
.. automodule:: adafruit_st7735
8-
:members:
8+
:members:

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# digitalio, micropython and busio. List the modules you use. Without it, the
2222
# autodoc module docs will fail to generate with a warning.
2323
# autodoc_mock_imports = ["digitalio", "busio"]
24-
24+
autodoc_mock_imports = ["displayio"]
2525

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

docs/index.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

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

3535
.. toctree::
3636
:caption: Other Links

examples/st7735_simpletest.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
import adafruit_st7735
1+
"""
2+
This test will initialize the display using displayio
3+
and draw a solid red background
4+
"""
5+
26
import board
3-
import busio
47
import displayio
5-
import time
8+
from adafruit_st7735 import ST7735
9+
10+
spi = board.SPI()
11+
tft_cs = board.D5
12+
tft_dc = board.D6
613

714
displayio.release_displays()
15+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
16+
17+
display = ST7735(display_bus, width=128, height=128)
18+
19+
# Make the display context
20+
splash = displayio.Group(max_size=10)
21+
display.show(splash)
822

9-
spi = busio.SPI(board.SCL, board.SDA)
10-
bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8)
11-
display = adafruit_st7735.ST7735(bus, width=128, height=128)
23+
color_bitmap = displayio.Bitmap(128, 128, 1)
24+
color_palette = displayio.Palette(1)
25+
color_palette[0] = 0xFF0000
1226

13-
s = displayio.Shape(10, 10)
14-
p = displayio.Palette(2)
15-
p[1] = 0xff0000
16-
s = displayio.Sprite(s, pixel_shader=p, position=(0,0))
17-
everything = displayio.Group(max_size=10)
18-
everything.append(s)
19-
display.show(everything)
27+
try:
28+
bg_sprite = displayio.TileGrid(color_bitmap,
29+
pixel_shader=color_palette,
30+
position=(0, 0))
31+
except TypeError:
32+
bg_sprite = displayio.TileGrid(color_bitmap,
33+
pixel_shader=color_palette,
34+
x=0, y=0)
35+
splash.append(bg_sprite)
2036

21-
time.sleep(10)
37+
while True:
38+
pass

0 commit comments

Comments
 (0)