mirror of
https://github.com/wahyd4/Adafruit_Python_SSD1306.git
synced 2026-08-09 04:46:43 +10:00
Add optional i2c_address parameter to init function for overriding the address of the SSD1306 display.
This commit is contained in:
@@ -70,7 +70,7 @@ class SSD1306Base(object):
|
||||
"""
|
||||
|
||||
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None,
|
||||
gpio=None, spi=None, i2c_bus=I2C.get_default_bus()):
|
||||
gpio=None, spi=None, i2c_bus=I2C.get_default_bus(), i2c_address=SSD1306_I2C_ADDRESS):
|
||||
self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
|
||||
self._spi = None
|
||||
self._i2c = None
|
||||
@@ -94,7 +94,7 @@ class SSD1306Base(object):
|
||||
# Handle hardware I2C
|
||||
elif i2c_bus is not None:
|
||||
self._log.debug('Using hardware I2C')
|
||||
self._i2c = I2C.Device(SSD1306_I2C_ADDRESS, i2c_bus)
|
||||
self._i2c = I2C.Device(i2c_address, i2c_bus)
|
||||
else:
|
||||
raise ValueError('Unable to determine if using SPI or I2C.')
|
||||
# Initialize DC pin if using SPI.
|
||||
|
||||
@@ -48,6 +48,9 @@ disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
|
||||
# 128x64 display with hardware I2C:
|
||||
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
|
||||
|
||||
# Note you can change the I2C address by passing an i2c_address parameter like:
|
||||
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
|
||||
|
||||
# Alternatively you can specify an explicit I2C bus number, for example
|
||||
# with the 128x32 display you would use:
|
||||
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
|
||||
|
||||
Reference in New Issue
Block a user