From a2823590f29a0b5213492fae75e8bb044aafc45d Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Sat, 26 Jul 2014 15:08:00 -0700 Subject: [PATCH] Add optional i2c_address parameter to init function for overriding the address of the SSD1306 display. --- Adafruit_SSD1306/SSD1306.py | 4 ++-- examples/shapes.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Adafruit_SSD1306/SSD1306.py b/Adafruit_SSD1306/SSD1306.py index a01d3ea..d99b5fa 100644 --- a/Adafruit_SSD1306/SSD1306.py +++ b/Adafruit_SSD1306/SSD1306.py @@ -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. diff --git a/examples/shapes.py b/examples/shapes.py index f788571..9b1a18c 100644 --- a/examples/shapes.py +++ b/examples/shapes.py @@ -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)