Skip to content

Commit 95a9f14

Browse files
committed
SPI working, I2C not.
1 parent 6e064f9 commit 95a9f14

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

adafruit_character_lcd/character_lcd.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,8 @@ class Character_LCD_Mono(Character_LCD):
531531
532532
"""
533533
# pylint: disable-msg=too-many-arguments
534-
def __init__(self, rs, en, d4, d5, d6, d7, columns, lines,
534+
def __init__(self, rs, en, db4, db5, db6, db7, columns, lines,
535535
backlight_pin=None, backlight_inverted=False):
536-
reset = rs
537-
enable = en
538-
db4 = d4
539-
db5 = d5
540-
db6 = d6
541-
db7 = d7
542536

543537
# Backlight pin and inversion
544538
self.backlight_pin = backlight_pin
@@ -548,10 +542,8 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines,
548542
if backlight_pin is not None:
549543
self.backlight_pin.direction = digitalio.Direction.OUTPUT
550544
if backlight_inverted:
551-
self.backlight_pin.value = 0 # Turn inverted backlight on
552-
else:
553-
self.backlight_pin.value = 1 # Turn backlight on
554-
super().__init__(reset, enable, db4, db5, db6, db7, columns, lines)
545+
self.backlight_pin.value = not backlight_inverted # Turn backlight on
546+
super().__init__(rs, en, db4, db5, db6, db7, columns, lines)
555547
# pylint: enable-msg=too-many-arguments
556548

557549
@property
@@ -611,13 +603,7 @@ class Character_LCD_RGB(Character_LCD):
611603
612604
"""
613605
# pylint: disable-msg=too-many-arguments
614-
def __init__(self, rs, en, d4, d5, d6, d7, columns, lines, red, green, blue, read_write=None):
615-
reset = rs
616-
enable = en
617-
db4 = d4
618-
db5 = d5
619-
db6 = d6
620-
db7 = d7
606+
def __init__(self, rs, en, db4, db5, db6, db7, columns, lines, red, green, blue, read_write=None):
621607

622608
# Define read_write (rw) pin
623609
self.read_write = read_write
@@ -643,7 +629,7 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines, red, green, blue, rea
643629
)
644630

645631
self._color = [0, 0, 0]
646-
super().__init__(reset, enable, db4, db5, db6, db7, columns, lines)
632+
super().__init__(rs, en, db4, db5, db6, db7, columns, lines)
647633

648634
@property
649635
def color(self):

adafruit_character_lcd/mono_i2c.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from adafruit_character_lcd.character_lcd import Character_LCD_Mono
2+
3+
4+
class Character_LCD_I2C(Character_LCD_Mono):
5+
"""Character LCD connected to I2C/SPI backpack using its I2C connection.
6+
This is a subclass of Character_LCD and implements all of the same
7+
functions and functionality.
8+
9+
To use, import and initialise as follows:
10+
11+
.. code-block:: python
12+
13+
import board
14+
import busio
15+
import adafruit_character_lcd.character_lcd_mono as character_lcd
16+
17+
i2c = busio.I2C(board.SCL, board.SDA)
18+
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
19+
"""
20+
def __init__(self, i2c, columns, lines, backlight_inverted=False):
21+
"""Initialize character LCD connected to backpack using I2C connection
22+
on the specified I2C bus with the specified number of columns and
23+
lines on the display. Optionally specify if backlight is inverted.
24+
"""
25+
import adafruit_mcp230xx
26+
self._mcp = adafruit_mcp230xx.MCP23008(i2c)
27+
reset = self._mcp.get_pin(1)
28+
enable = self._mcp.get_pin(2)
29+
db4 = self._mcp.get_pin(3)
30+
db5 = self._mcp.get_pin(4)
31+
db6 = self._mcp.get_pin(5)
32+
db7 = self._mcp.get_pin(6)
33+
backlight_pin = self._mcp.get_pin(7)
34+
self.backlight_inverted = backlight_inverted
35+
super().__init__(reset, enable, db4, db5, db6, db7, columns, lines,
36+
backlight_pin=backlight_pin, backlight_inverted=backlight_inverted)

adafruit_character_lcd/mono_spi.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from adafruit_character_lcd.character_lcd import Character_LCD_Mono
2+
3+
4+
class Character_LCD_SPI(Character_LCD_Mono):
5+
"""Character LCD connected to I2C/SPI backpack using its SPI connection.
6+
This is a subclass of Character_LCD and implements all of the same
7+
functions and functionality.
8+
9+
To use, import and initialise as follows:
10+
11+
.. code-block:: python
12+
13+
import board
14+
import busio
15+
import digitalio
16+
import adafruit_character_lcd.character_lcd_mono as character_lcd
17+
18+
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
19+
latch = digitalio.DigitalInOut(board.D5)
20+
lcd = character_lcd.Character_LCD_SPI(spi, latch, 16, 2)
21+
"""
22+
23+
def __init__(self, spi, latch, columns, lines, backlight_inverted=False):
24+
# pylint: disable=too-many-arguments
25+
"""Initialize character LCD connected to backpack using SPI connection
26+
on the specified SPI bus and latch line with the specified number of
27+
columns and lines on the display. Optionally specify if backlight is
28+
inverted.
29+
"""
30+
# pylint: enable=too-many-arguments
31+
import adafruit_74hc595
32+
self._shift_register = adafruit_74hc595.ShiftRegister74HC595(spi, latch)
33+
reset = self._shift_register.get_pin(1)
34+
enable = self._shift_register.get_pin(2)
35+
db4 = self._shift_register.get_pin(6)
36+
db5 = self._shift_register.get_pin(5)
37+
db6 = self._shift_register.get_pin(4)
38+
db7 = self._shift_register.get_pin(3)
39+
backlight_pin = self._shift_register.get_pin(7)
40+
self.backlight_inverted = backlight_inverted
41+
super().__init__(reset, enable, db4, db5, db6, db7, columns, lines,
42+
backlight_pin=backlight_pin, backlight_inverted=backlight_inverted)

0 commit comments

Comments
 (0)