Skip to content

Commit 07d30d0

Browse files
committed
Revert code to last known good status
1 parent 044ef59 commit 07d30d0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

sparkfun_serlcd.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"
6161

6262
# imports
63-
# from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3
63+
from abc import ABC, abstractmethod
6464
from time import sleep
6565
from micropython import const
6666

@@ -139,8 +139,8 @@ def _map_range(value, in_min, in_max, out_min, out_max):
139139

140140
return int(result)
141141

142-
# base class
143-
class Sparkfun_SerLCD:
142+
# abstract base class
143+
class Sparkfun_SerLCD(ABC):
144144
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
145145
Use the appropriate driver communcation subclass Sprarkfun_SerLCD_I2C()
146146
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
@@ -382,6 +382,27 @@ def set_contrast(self, value):
382382
self._write_bytes(data)
383383
sleep(0.010)
384384

385+
def set_i2c_address(self, new_address):
386+
"""Change the I2C Address. 0x72 is the default.
387+
Note that this change is persistent. If anything goes wrong
388+
you may need to do a hardware reset to unbrick the display.
389+
390+
byte new_addr - new i2c address"""
391+
# Mask new address to byte
392+
new_address &= 0x00FF
393+
# Transmit to device on old address
394+
data = bytearray()
395+
# Send contrast command
396+
data.append(_SETTING_COMMAND)
397+
data.append(_ADDRESS_COMMAND) # 0x19
398+
data.append(new_address)
399+
self._write_bytes(data)
400+
# Update our own address so we can still talk to the display
401+
self._change_i2c_address(new_address)
402+
403+
# This may take awhile
404+
sleep(0.050)
405+
385406
def scroll_display_left(self, count=1):
386407
"""Scroll the display to the left"""
387408
self._special_command(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT, count)
@@ -442,11 +463,11 @@ def default_splash_screen(self):
442463

443464
# abstract methods
444465

445-
# @abstractmethod
466+
@abstractmethod
446467
def _write_bytes(self, data):
447468
pass
448469

449-
# @abstractmethod
470+
@abstractmethod
450471
def _change_i2c_address(self, addr):
451472
pass
452473

0 commit comments

Comments
 (0)