Skip to content

Commit

Permalink
HT1621 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Apr 15, 2017
1 parent 580eaa3 commit e3a0bf6
Show file tree
Hide file tree
Showing 13 changed files with 560 additions and 109 deletions.
16 changes: 9 additions & 7 deletions README.rst
Expand Up @@ -8,7 +8,7 @@ luma.lcd **|**

Luma.LCD
========
**PCD8544, ST7735 Display Drivers**
**PCD8544, ST7735, HT1621 Display Drivers**

.. image:: https://travis-ci.org/rm-hull/luma.lcd.svg?branch=master
:target: https://travis-ci.org/rm-hull/luma.lcd
Expand All @@ -28,24 +28,26 @@ Luma.LCD

.. image:: https://img.shields.io/maintenance/yes/2017.svg?maxAge=2592000

Python library interfacing LCD displays with the PCD8544 or ST7735 driver using
SPI on the Raspberry Pi and other linux-based single-board computers - it
provides a Pillow-compatible drawing canvas, and other functionality to
support:
Python library interfacing LCD displays with the PCD8544, ST7735 and HT1621
driver using SPI on the Raspberry Pi and other linux-based single-board
computers - it provides a Pillow-compatible drawing canvas, and other
functionality to support:

* scrolling/panning capability,
* terminal-style printing,
* state management,
* color/greyscale (where supported),
* dithering to monochrome

Both types of modules can be picked up on ebay with a breakout board
for a few pounds.
All modules can be picked up on ebay with a breakout board for a few pounds.

.. image:: https://raw.github.com/rm-hull/luma.lcd/master/doc/images/pcd8544.png

.. image:: https://raw.github.com/rm-hull/luma.lcd/master/doc/images/st7735.jpg

.. image:: https://raw.github.com/rm-hull/luma.lcd/master/doc/images/ht1621.jpg


Documentation
-------------
Full documentation with installation instructions and examples can be found on
Expand Down
Binary file added doc/images/ht1621.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 43 additions & 34 deletions doc/install.rst
Expand Up @@ -74,49 +74,58 @@ Raspberry Pi, up to and including the Raspberry Pi 3 B.

PCD8544
"""""""
========== ====== ============ ======== ==============
LCD Pin Name Remarks RPi Pin RPi Function
========== ====== ============ ======== ==============
1 RST Reset P01-18 GPIO 24
2 CE Chip Enable P01-24 GPIO 8 (CE0)
3 DC Data/Command P01-16 GPIO 23
4 DIN Data In P01-19 GPIO 10 (MOSI)
5 CLK Clock P01-23 GPIO 11 (SCLK)
6 VCC +3.3V Power P01-01 3V3
7 LIGHT Backlight P01-12 GPIO 18 (PCM_CLK)
8 GND Ground P01-06 GND
========== ====== ============ ======== ==============
======== ============ ======== ==============
LCD Pin Remarks RPi Pin RPi Function
======== ============ ======== ==============
RST Reset P01-18 GPIO 24
CE Chip Enable P01-24 GPIO 8 (CE0)
DC Data/Command P01-16 GPIO 23
DIN Data In P01-19 GPIO 10 (MOSI)
CLK Clock P01-23 GPIO 11 (SCLK)
VCC +3.3V Power P01-01 3V3
LIGHT Backlight P01-12 GPIO 18 (PCM_CLK)
GND Ground P01-06 GND
======== ============ ======== ==============

ST7735
""""""
========== ======= ================= ======== ==============
LCD Pin Name Remarks RPi Pin RPi Function
========== ======= ================= ======== ==============
1 GND Ground P01-06 GND
2 VCC +3.3V Power P01-01 3V3
3 NC Not connected - -
4 NC Not connected - -
5 NC Not connected - -
6 RESET Reset P01-18 GPIO 24
7 A0 Data/command P01-16 GPIO 23
8 SDA SPI data P01-19 GPIO 10 (MOSI)
9 SCK SPI clock P01-23 GPIO 11 (SCLK)
10 CS SPI chip select P01-24 GPIO 8 (CE0)
11 SD-SCK SD serial clock - -
12 SD-MISO SD data in - -
13 SD-MOSI SD data out - -
14 SD-CS SD chip select - -
15 LED+ Backlight control P01-12 GPIO 18 (PCM_CLK)
16 LED- Backlight ground P01-06 GND
========== ======= ================= ======== ==============
Depending on the board you bought, there may be different names for the same
pins, as detailed below.
============= ================= ======== ==============
LCD Pin Remarks RPi Pin RPi Function
============= ================= ======== ==============
GND Ground P01-06 GND
VCC +3.3V Power P01-01 3V3
RESET or RST Reset P01-18 GPIO 24
A0 or D/C Data/command P01-16 GPIO 23
SDA or DIN SPI data P01-19 GPIO 10 (MOSI)
SCK or CLK SPI clock P01-23 GPIO 11 (SCLK)
CS SPI chip select P01-24 GPIO 8 (CE0)
LED+ or BL Backlight control P01-12 GPIO 18 (PCM_CLK)
LED- Backlight ground P01-06 GND
============= ================= ======== ==============

HT1621
""""""
============= ================= ======== ==============
LCD Pin Remarks RPi Pin RPi Function
============= ================= ======== ==============
GND Ground P01-06 GND
VCC +3.3V Power P01-01 3V3
DAT SPI data P01-19 GPIO 10 (MOSI)
WR SPI clock P01-23 GPIO 11 (SCLK)
CS SPI chip select P01-24 GPIO 8 (CE0)
LED Backlight control P01-12 GPIO 18 (PCM_CLK)
============= ================= ======== ==============


Installing from PyPI
^^^^^^^^^^^^^^^^^^^^
Install the dependencies for library first with::

$ sudo usermod -a -G spi,gpio pi
$ sudo apt-get install python-dev python-pip
$ sudo -i pip install --upgrade pip
$ sudo -i pip install --upgrade pip setuptools
$ sudo apt-get purge python-pip

.. warning:: The default pip bundled with apt on Raspbian is really old, and can
Expand All @@ -127,7 +136,7 @@ Install the dependencies for library first with::
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

Proceed to install latest version of the library directly from
`PyPI <https://pypi.python.org/pypi?:action=display&name=luma.led_matrix>`_::
`PyPI <https://pypi.python.org/pypi?:action=display&name=luma.lcd>`_::

$ sudo -H pip install --upgrade luma.lcd

8 changes: 7 additions & 1 deletion doc/intro.rst
@@ -1,6 +1,6 @@
Introduction
------------
Interfacing small LCD displays with the PCD8544 and ST7735 driver in Python
Interfacing small LCD displays with the PCD8544, ST7735 and HT1621 driver in Python
using SPI on the Raspberry Pi and other linux-based single-board computers: the
library provides a Pillow-compatible drawing canvas, and other functionality to
support:
Expand All @@ -26,12 +26,18 @@ colors) with a switchable backlight:

.. image:: images/st7735.jpg

The HT1621 display (as purchased) supports six 7-segment characters with a
switchable backlight:

.. image:: images/ht1621.jpg

.. seealso::
Further technical information for the specific device can be found in the
datasheet below:

- :download:`PCD8544 <tech-spec/PCD8544.pdf>`
- :download:`ST7735 <tech-spec/ST7735.pdf>`
- :download:`HT1621 <tech-spec/HT1621.pdf>`

As well as display drivers for the physical device, there are emulators that
run in real-time (with pygame) and others that can take screenshots, or
Expand Down
113 changes: 49 additions & 64 deletions doc/python-usage.rst
@@ -1,5 +1,8 @@
Python usage
------------

Pixel Drivers
^^^^^^^^^^^^^
The PCD8544 is driven with python using the implementation in the
:py:class:`luma.lcd.device.pcd8544` class. Likewise, to drive the ST7735, use
the :py:class:`luma.lcd.device.st7735` class. Usage is very simple if you have
Expand Down Expand Up @@ -43,7 +46,7 @@ flushed to the device's display memory and the :mod:`PIL.ImageDraw` object is
garbage collected.

Color Model
^^^^^^^^^^^
"""""""""""
Any of the standard :py:mod:`PIL.ImageColor` color formats may be used, but
since the PCD8544 LCD is monochrome, only the HTML color names
:py:const:`"black"` and :py:const:`"white"` values should really be used; in
Expand All @@ -61,7 +64,7 @@ Note that there is no such limitation for the ST7735 device which supports 262K
colour RGB images, whereby 24-bit RGB images are downscaled to 18-bit RGB.

Landscape / Portrait Orientation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
""""""""""""""""""""""""""""""""
By default the PCD8544 and ST7735 displays will both be oriented in landscape
mode (84x48 and 160x128 pixels respectively). Should you have an application
that requires the display to be mounted in a portrait aspect, then add a
Expand All @@ -87,6 +90,48 @@ rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.
The :py:attr:`device.size`, :py:attr:`device.width` and :py:attr:`device.height`
properties reflect the rotated dimensions rather than the physical dimensions.

Seven-Segment Drivers
^^^^^^^^^^^^^^^^^^^^^
The HT1621 is driven with the :py:class:`luma,lcd.device.ht1621` class, but is
not accessed directly: it should be wrapped with the :py:class:`luma.core.virtual.sevensegment`
wrapper, as follows:

.. code:: python
from luma.core.virtual import sevensegment
from luma.lcd.device import ht1621
device = ht1621()
seg = sevensegment(device)
The **seg** instance now has a :py:attr:`~luma.led_matrix.virtual.sevensegment.text`
property which may be assigned, and when it does will update all digits
according to the limited alphabet the 7-segment displays support. For example,
assuming there are 2 cascaded modules, we have 16 character available, and so
can write:

.. code:: python
seg.text = "HELLO"
Rather than updating the whole display buffer, it is possible to update
'slices', as per the below example:

.. code:: python
seg.text[0:5] = "BYE"
This replaces ``HELLO`` in the previous example, replacing it with ``BYE``.
The usual python idioms for slicing (inserting / replacing / deleteing) can be
used here, but note if inserted text exceeds the underlying buffer size, a
:py:exc:`ValueError` is raised.

Floating point numbers (or text with '.') are handled slightly differently - the
decimal-place is fused in place on the character immediately preceding it. This
means that it is technically possible to get more characters displayed than the
buffer allows, but only because dots are folded into their host character.

Backlight Control
^^^^^^^^^^^^^^^^^
These displays typically require a backlight to illuminate the liquid crystal
Expand All @@ -95,65 +140,5 @@ be specified to control the backlight through software.

Examples
^^^^^^^^
After installing the library, download the `luma.examples
<https://github.com/rm-hull/luma.examples>`_ directory and try running the
following examples:

=============== ========================================================
Example Description
=============== ========================================================
3d_box.py Rotating 3D box wireframe & color dithering
bounce.py Display a bouncing ball animation and frames per second
carousel.py Showcase viewport and hotspot functionality
clock.py An analog clockface with date & time
colors.py Color rendering demo
crawl.py A vertical scrolling demo, which should be familiar
demo.py Use misc draw commands to create a simple image
game_of_life.py Conway's game of life
grayscale.py Greyscale rendering demo
invaders.py Space Invaders demo
maze.py Maze generator
perfloop.py Simple benchmarking utility to measure performance
pi_logo.py Display the Raspberry Pi logo (loads image as .png)
savepoint.py Example of savepoint/restore functionality
starfield.py 3D starfield simulation
sys_info.py Display basic system information
terminal.py Simple println capabilities
tv_snow.py Example image-blitting
welcome.py Unicode font rendering & scrolling
=============== ========================================================

See the README in that project for further information on how to run the demos.

Emulators
^^^^^^^^^
There are various display emulators available for running code against, for
debugging and screen capture functionality:

* The :py:class:`luma.emulator.device.capture` device will persist a numbered
PNG file to disk every time its :py:meth:`~luma.emulator.device.capture.display`
method is called.

* The :py:class:`luma.emulator.device.gifanim` device will record every image
when its :py:meth:`~luma.emulator.device.gifanim.display` method is called,
and on program exit (or Ctrl-C), will assemble the images into an animated GIF.

* The :py:class:`luma.emulator.device.pygame` device uses the :py:mod:`pygame`
library to render the displayed image to a pygame display surface.

Invoke the demos with::

$ python examples/clock.py -d capture

or::

$ python examples/clock.py -d pygame
.. note::
*Pygame* is required to use any of the emulated devices, but it is **NOT**
installed as a dependency by default, and so must be manually installed
before using any of these emulation devices (e.g. ``pip install pygame``).
See the install instructions in `luma.emulator <http://github.com/rm-hull/luma.emulator>`_
for further details.


After installing the library, head over to the `luma.examples <https://github.com/rm-hull/luma.examples>`_
repository. Details of how to run the examples is shown in the example repo's README.
Binary file added doc/tech-spec/HT1621.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions luma/lcd/const.py
Expand Up @@ -11,3 +11,8 @@ class pcd8544(object):
class st7735(object):
DISPLAYON = 0x29
DISPLAYOFF = 0x28


class ht1621(object):
DISPLAYON = 0x06
DISPLAYOFF = 0x04

0 comments on commit e3a0bf6

Please sign in to comment.