diff --git a/CHANGES.rst b/CHANGES.rst index 64c2455..b7b4410 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ ChangeLog +------------+---------------------------------------------------------------------+------------+ | Version | Description | Date | +============+=====================================================================+============+ +| **1.1.0** | * Add LS013B4DN04 Monochrome LCD display driver | 2018/01/01 | ++------------+---------------------------------------------------------------------+------------+ | **1.0.3** | * Changed version number to inside ``luma/lcd/__init__.py`` | 2017/11/23 | +------------+---------------------------------------------------------------------+------------+ | **1.0.2** | * Documentation and dependencies updates | 2017/10/30 | diff --git a/LICENSE.rst b/LICENSE.rst index ba20f16..7219c19 100644 --- a/LICENSE.rst +++ b/LICENSE.rst @@ -1,7 +1,7 @@ The MIT License (MIT) --------------------- -Copyright (c) 2013-17 Richard Hull & Contributors +Copyright (c) 2013-18 Richard Hull & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 1992791..a9914a8 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ luma.lcd **|** Luma.LCD ======== -**PCD8544, ST7735, HT1621, UC1701X Display Drivers** +**PCD8544, ST7735, HT1621, UC1701X, LS013B4DN04 Display Drivers** .. image:: https://travis-ci.org/rm-hull/luma.lcd.svg?branch=master :target: https://travis-ci.org/rm-hull/luma.lcd @@ -26,12 +26,12 @@ Luma.LCD .. image:: https://img.shields.io/pypi/v/luma.lcd.svg :target: https://pypi.python.org/pypi/luma.lcd -.. image:: https://img.shields.io/maintenance/yes/2017.svg?maxAge=2592000 +.. image:: https://img.shields.io/maintenance/yes/2018.svg?maxAge=2592000 -Python library interfacing LCD displays with the PCD8544, ST7735, HT1621 and -UC1701X 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, HT1621, +UC1701X and LS013B4DN04 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, @@ -49,6 +49,8 @@ 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/uc1701x.png +.. image:: https://raw.github.com/rm-hull/luma.lcd/master/doc/images/ls013b4dn04.jpg + Documentation ------------- Full documentation with installation instructions and examples can be found on @@ -58,7 +60,7 @@ License ------- The MIT License (MIT) -Copyright (c) 2013-17 Richard Hull & Contributors +Copyright (c) 2013-18 Richard Hull & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/doc/images/ls013b4dn04.jpg b/doc/images/ls013b4dn04.jpg new file mode 100644 index 0000000..527e987 Binary files /dev/null and b/doc/images/ls013b4dn04.jpg differ diff --git a/doc/index.rst b/doc/index.rst index b31335c..f065e5b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,12 +1,12 @@ -Luma.LCD: Display drivers for PCD8544, ST7735, HT1621, UC1701X -============================================================== +Luma.LCD: Display drivers for PCD8544, ST7735, HT1621, UC1701X, LS013B4DN04 +=========================================================================== .. image:: https://travis-ci.org/rm-hull/luma.lcd.svg?branch=master :target: https://travis-ci.org/rm-hull/luma.lcd .. image:: https://coveralls.io/repos/github/rm-hull/luma.lcd/badge.svg?branch=master :target: https://coveralls.io/github/rm-hull/luma.lcd?branch=master -.. image:: https://img.shields.io/maintenance/yes/2017.svg?maxAge=2592000 +.. image:: https://img.shields.io/maintenance/yes/2018.svg?maxAge=2592000 .. image:: https://img.shields.io/pypi/pyversions/luma.lcd.svg :target: https://pypi.python.org/pypi/luma.lcd diff --git a/doc/install.rst b/doc/install.rst index 3294807..d42173d 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -140,7 +140,25 @@ SCK SPI clock P01-23 GPIO 11 (SCLK) SDA SPI data P01-19 GPIO 10 (MOSI) RS Data/command P01-16 GPIO 23 RST Reset P01-18 GPIO 24 -CS SPI chip select P01-24 GPIO 8 (CE0) Chip Select +CS SPI chip select P01-24 GPIO 8 (CE0) +============= ================= ======== ============== + +LS013B4DN04 +""""""""""" +Also known as Adafruit_1393 + +============= ================= ======== ============== +LCD Pin Remarks RPi Pin RPi Function +============= ================= ======== ============== +VIN +3.3V P01-01 3V3 +3V3 +3.3V P01-01 3V3 +GND Ground P01-06 GND +SCLK SPI clock P0-23 GPIO 11 (SCLK) +MOSI SPI data P01-19 GPIO 10 (MOSI) +CS SPI chip select P01-24 GPIO 8 (CE0) +EXTMD External mode P01-14 GND +DISP Display on/off P01-16 GPIO 23 +EXTIN PWM clock P01-12 GPIO 18 (PWM0) ============= ================= ======== ============== Installing from PyPI diff --git a/doc/intro.rst b/doc/intro.rst index 438caac..6a2d7b0 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -1,9 +1,9 @@ Introduction ------------ -Interfacing small LCD displays with the PCD8544, ST7735, HT1621 and UC1701X -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: +Interfacing small LCD displays with the PCD8544, ST7735, HT1621, UC1701X and +LS013B4DN04 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: * scrolling/panning capability, * terminal-style printing, @@ -36,6 +36,10 @@ switchable backlight: .. image:: images/uc1701x.png +The LS013B4DN04 display supports a resolution of 96 x 96 monochrome pixels: + +.. image:: images/ls013b4dn04.jpg + .. seealso:: Further technical information for the specific device can be found in the datasheet below: @@ -44,6 +48,7 @@ switchable backlight: - :download:`ST7735 ` - :download:`HT1621 ` - :download:`UC1701X ` + - :download:`LS013B4DN04 ` 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 diff --git a/doc/python-usage.rst b/doc/python-usage.rst index 3d98773..66b41e2 100644 --- a/doc/python-usage.rst +++ b/doc/python-usage.rst @@ -3,11 +3,13 @@ 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 or -UC1701X, use the :py:class:`luma.lcd.device.st7735` or -:py:class:`luma.lcd.device.uc1701x` class respectively. Usage is very simple if -you have ever used `Pillow `_ or PIL. +:py:class:`luma.lcd.device.pcd8544` class. Likewise, to drive the ST7735, +UC1701X or LS013B4DN04, use the :py:class:`luma.lcd.device.st7735`, +:py:class:`luma.lcd.device.uc1701x`, :py:class:`luma.lcd.device.ls013b4dn04` or +class respectively. Usage is very simple if you have ever used `Pillow +`_ or PIL. First, import and initialise the device: @@ -15,7 +17,7 @@ First, import and initialise the device: from luma.core.interface.serial import spi from luma.core.render import canvas - from luma.lcd.device import pcd8544, st7735, uc1701x + from luma.lcd.device import pcd8544, st7735, uc1701x, ls013b4dn04 serial = spi(port=0, device=0, gpio_DC=23, gpio_RST=24) device = pcd8544(serial) @@ -24,8 +26,9 @@ The display device should now be configured for use. Note, all the example code snippets in this section are interchangeable between PCD8544 and ST7735 devices. -The :py:class:`~luma.lcd.device.pcd8544`, :py:class:`~luma.lcd.device.st7735` and -:py:class:`~luma.lcd.device.uc1701x` classes all expose a +The :py:class:`~luma.lcd.device.pcd8544`, :py:class:`~luma.lcd.device.st7735`, +:py:class:`~luma.lcd.device.uc1701x` and +:py:class:`~luma.lcd.device.ls013b4dn04` classes all expose a :py:meth:`~luma.lcd.device.pcd8544.display` method which takes an image with attributes consistent with the capabilities of the device. However, for most cases, for drawing text and graphics primitives, the canvas class should be @@ -67,9 +70,10 @@ colour RGB images, whereby 24-bit RGB images are downscaled to 18-bit RGB. Landscape / Portrait Orientation """""""""""""""""""""""""""""""" By default the PCD8544, ST7735 and UC1701X displays will all be oriented in -landscape mode (84x48, 160x128 and 128x64 pixels respectively). Should you have -an application that requires the display to be mounted in a portrait aspect, -then add a :py:attr:`rotate=N` parameter when creating the device: +landscape mode (84x48, 160x128 and 128x64 pixels respectively). The LS013B4DN04 +supports a native resolution of 96x96 pixels. Should you have an application +that requires the display to be mounted in a portrait aspect, then add a +:py:attr:`rotate=N` parameter when creating the device: .. code:: python @@ -93,9 +97,9 @@ 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: +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 @@ -104,13 +108,13 @@ wrapper, as follows: 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: + + +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 diff --git a/doc/tech-spec/LS013B4DN04.pdf b/doc/tech-spec/LS013B4DN04.pdf new file mode 100644 index 0000000..726ff0c Binary files /dev/null and b/doc/tech-spec/LS013B4DN04.pdf differ diff --git a/luma/__init__.py b/luma/__init__.py index 46e975f..79340ad 100644 --- a/luma/__init__.py +++ b/luma/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. from pkgutil import extend_path diff --git a/luma/lcd/__init__.py b/luma/lcd/__init__.py index 50bfcb4..6a4a5d1 100644 --- a/luma/lcd/__init__.py +++ b/luma/lcd/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/luma/lcd/aux.py b/luma/lcd/aux.py index 7500c85..b84cfc4 100644 --- a/luma/lcd/aux.py +++ b/luma/lcd/aux.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. diff --git a/luma/lcd/const.py b/luma/lcd/const.py index f358be6..df391f6 100644 --- a/luma/lcd/const.py +++ b/luma/lcd/const.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. @@ -21,3 +21,7 @@ class ht1621(object): class uc1701x(object): DISPLAYON = 0xAF DISPLAYOFF = 0xAE + + +class ls013b4dn04(object): + pass diff --git a/luma/lcd/device.py b/luma/lcd/device.py index a9f518a..d3cb8e0 100644 --- a/luma/lcd/device.py +++ b/luma/lcd/device.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. """ @@ -43,7 +43,7 @@ from luma.lcd.segment_mapper import dot_muncher -__all__ = ["pcd8544", "st7735", "ht1621", "uc1701x"] +__all__ = ["pcd8544", "st7735", "ht1621", "uc1701x", "ls013b4dn04"] class pcd8544(device): @@ -427,3 +427,89 @@ def contrast(self, value): """ assert(0 <= value <= 255) self.command(0x81, value >> 2) + + +class ls013b4dn04(device): + """ + Serial interface to a monochrome LS013B4DN04 LCD display. + + On creation, an initialization sequence is pumped to the display to properly + configure it. Further control commands can then be called to affect the + brightness and other settings. + + :param serial_interface: The serial interface (usually a + :py:class:`luma.core.interface.serial.spi` instance) to delegate sending + data and commands through. + :param rotate: An integer value of 0 (default), 1, 2 or 3 only, where 0 is + no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 + represents 270° rotation. + :type rotate: int + + .. versionadded:: 1.1.0 + """ + def __init__(self, serial_interface=None, rotate=0, **kwargs): + super(ls013b4dn04, self).__init__(luma.lcd.const.ls013b4dn04, serial_interface) + self.capabilities(96, 96, rotate) + self._mask = [1 << (i % 8) for i in reversed(range(self._w))] + self._offsets = [(i // 8) for i in range(self._w)] + self._vcom = 0x40 + + self.clear() + self.show() + + def toggleVCOM(self): + self._vcom = 0x40 if self._vcom == 0 else 0x00 + + def reverseByte(self, n): + return int('{:08b}'.format(n)[::-1], 2) + + def display(self, image): + """ + Takes a 1-bit :py:mod:`PIL.Image` and dumps it to the LS013B4DN04 + LCD display. + """ + assert(image.mode == self.mode) + assert(image.size == self.size) + + image = self.preprocess(image) + image_data = list(image.getdata()) + off = self._offsets + mask = self._mask + + self.toggleVCOM() + buf = [0x80 | self._vcom] + + for line in range(self._h): + addr = self.reverseByte(line + 1) + row = bytearray(self._w // 8) + + frm = line * self._w + to = frm + self._w + for idx, pix in enumerate(image_data[frm:to]): + if pix > 0: + row[off[idx]] |= mask[idx] + + buf.append(addr) + buf += list(row) + buf.append(0x00) + + buf.append(0x00) + print(buf) + self.data(buf) + + def clear(self): + self.toggleVCOM() + self.command(0x20 | self._vcom, 0x00) + + def show(self): + pass + + def hide(self): + pass + + def contrast(self, value): + """ + Sets the LCD contrast + """ + assert(0 <= value <= 255) + pass diff --git a/luma/lcd/segment_mapper.py b/luma/lcd/segment_mapper.py index 177778d..6a07c56 100644 --- a/luma/lcd/segment_mapper.py +++ b/luma/lcd/segment_mapper.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2017 Richard Hull and contributors +# Copyright (c) 2017-18 Richard Hull and contributors # See LICENSE.rst for details. _DIGITS = { diff --git a/setup.py b/setup.py index 97a9695..bda7c22 100755 --- a/setup.py +++ b/setup.py @@ -43,10 +43,10 @@ def find_version(*file_paths): version=version, author="Richard Hull", author_email="richard.hull@destructuring-bind.org", - description=("A library to drive PCD8544, HT1621, ST7735 and UC1701X-based LCDs"), + description=("A library to drive PCD8544, HT1621, ST7735, UC1701X and LS013B4DN04-based LCDs"), long_description="\n\n".join([README, CONTRIB, CHANGES]), license="MIT", - keywords="raspberry pi rpi lcd nokia 5110 display screen pcd8544 st7735 uc1701x ht1621 spi 84x48 160x128", + keywords="raspberry pi rpi lcd nokia 5110 display screen pcd8544 st7735 uc1701x ht1621 ls013b4dn04 spi 84x48 160x128", url="https://github.com/rm-hull/luma.lcd", download_url="https://github.com/rm-hull/luma.lcd/tarball/" + version, namespace_packages=["luma"], diff --git a/tests/baseline_data.py b/tests/baseline_data.py index 8540c36..b82cec7 100644 --- a/tests/baseline_data.py +++ b/tests/baseline_data.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. import io diff --git a/tests/helpers.py b/tests/helpers.py index d886546..6b72014 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2017 Richard Hull and contributors +# Copyright (c) 2017-18 Richard Hull and contributors # See LICENSE.rst for details. try: diff --git a/tests/test_backlight.py b/tests/test_backlight.py index e8882a6..64532fd 100644 --- a/tests/test_backlight.py +++ b/tests/test_backlight.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. import luma.core.error diff --git a/tests/test_ht1621.py b/tests/test_ht1621.py index 8d16faf..c611bba 100644 --- a/tests/test_ht1621.py +++ b/tests/test_ht1621.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/tests/test_pcd8544.py b/tests/test_pcd8544.py index a365187..d4ef45d 100644 --- a/tests/test_pcd8544.py +++ b/tests/test_pcd8544.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/tests/test_segment_mapper.py b/tests/test_segment_mapper.py index c73f7f1..5e95ad4 100644 --- a/tests/test_segment_mapper.py +++ b/tests/test_segment_mapper.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2014-17 Richard Hull and contributors +# Copyright (c) 2014-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/tests/test_st7735.py b/tests/test_st7735.py index 7482b35..8486447 100644 --- a/tests/test_st7735.py +++ b/tests/test_st7735.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/tests/test_uc1701x.py b/tests/test_uc1701x.py index 0ece2c1..3ddd017 100644 --- a/tests/test_uc1701x.py +++ b/tests/test_uc1701x.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Richard Hull and contributors +# Copyright (c) 2017-18 Richard Hull and contributors # See LICENSE.rst for details. """ diff --git a/tox.ini b/tox.ini index 3fc01fe..0a4a41e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,4 +1,4 @@ -# Copyright (c) 2013-17 Richard Hull and contributors +# Copyright (c) 2013-18 Richard Hull and contributors # See LICENSE.rst for details. [tox]