/ adafruit_character_lcd / character_lcd_spi.py
character_lcd_spi.py
  1  # The MIT License (MIT)
  2  #
  3  # Copyright (c) 2018 Kattni Rembor for Adafruit Industries
  4  #
  5  # Permission is hereby granted, free of charge, to any person obtaining a copy
  6  # of this software and associated documentation files (the "Software"), to deal
  7  # in the Software without restriction, including without limitation the rights
  8  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9  # copies of the Software, and to permit persons to whom the Software is
 10  # furnished to do so, subject to the following conditions:
 11  #
 12  # The above copyright notice and this permission notice shall be included in
 13  # all copies or substantial portions of the Software.
 14  #
 15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 21  # THE SOFTWARE.
 22  """
 23  `adafruit_character_lcd.character_lcd_spi`
 24  ====================================================
 25  
 26  Module for using SPI with I2C/SPI character LCD backpack
 27  
 28  * Author(s): Kattni Rembor
 29  
 30  Implementation Notes
 31  --------------------
 32  
 33  **Hardware:**
 34  
 35  "* `I2C / SPI character LCD backpack <https://www.adafruit.com/product/292>`_"
 36  
 37  **Software and Dependencies:**
 38  
 39  * Adafruit CircuitPython firmware:
 40    https://github.com/adafruit/circuitpython/releases
 41  * Adafruit's Bus Device library (when using I2C/SPI):
 42    https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
 43  
 44  """
 45  
 46  import adafruit_74hc595
 47  from adafruit_character_lcd.character_lcd import Character_LCD_Mono
 48  
 49  __version__ = "0.0.0-auto.0"
 50  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
 51  
 52  
 53  class Character_LCD_SPI(Character_LCD_Mono):  # pylint: disable=too-few-public-methods
 54      """Character LCD connected to I2C/SPI backpack using its SPI connection.
 55      This is a subclass of Character_LCD and implements all of the same
 56      functions and functionality.
 57  
 58      To use, import and initialise as follows:
 59  
 60      .. code-block:: python
 61  
 62          import board
 63          import busio
 64          import digitalio
 65          import adafruit_character_lcd.character_lcd_mono as character_lcd
 66  
 67          spi = busio.SPI(board.SCK, MOSI=board.MOSI)
 68          latch = digitalio.DigitalInOut(board.D5)
 69          lcd = character_lcd.Character_LCD_SPI(spi, latch, 16, 2)
 70      """
 71  
 72      def __init__(self, spi, latch, columns, lines, backlight_inverted=False):
 73          # pylint: disable=too-many-arguments
 74          """Initialize character LCD connected to backpack using SPI connection
 75          on the specified SPI bus and latch line with the specified number of
 76          columns and lines on the display. Optionally specify if backlight is
 77          inverted.
 78          """
 79          # pylint: enable=too-many-arguments
 80  
 81          self._shift_register = adafruit_74hc595.ShiftRegister74HC595(spi, latch)
 82          reset = self._shift_register.get_pin(1)
 83          enable = self._shift_register.get_pin(2)
 84          db4 = self._shift_register.get_pin(6)
 85          db5 = self._shift_register.get_pin(5)
 86          db6 = self._shift_register.get_pin(4)
 87          db7 = self._shift_register.get_pin(3)
 88          backlight_pin = self._shift_register.get_pin(7)
 89          super().__init__(
 90              reset,
 91              enable,
 92              db4,
 93              db5,
 94              db6,
 95              db7,
 96              columns,
 97              lines,
 98              backlight_pin=backlight_pin,
 99              backlight_inverted=backlight_inverted,
100          )