API Documentation

OLED display driver for SSD1306, SSD1322, SSD1325, SSD1331 and SH1106 devices.

Inheritance diagram of luma.core.device, luma.core.emulator, luma.core.mixin, luma.core.virtual, luma.oled.device

Breaking changes

Warning

Version 2.0.0 was released on 11 January 2017: this came with a rename of the project in github from ssd1306 to luma.oled to reflect the changing nature of the codebase. It introduces some structural changes to the package structure, namely breaking the library up into smaller components and renaming existing packages.

This should largely be restricted to having to update import statements only. To upgrade any existing code that uses the old package structure:

  • rename instances of oled.device to luma.oled.device.
  • rename any other usages of oled.* to luma.core.*.

This breaking change was necessary to be able to add different classes of devices, so that they could reuse core components.

luma.core.device

class luma.core.device.device(const=None, serial_interface=None)[source]

Bases: luma.core.mixin.capabilities

Base class for display driver classes

Warning

Direct use of the command() and data() methods are discouraged: Screen updates should be effected through the display() method, or preferably with the luma.core.render.canvas context manager.

capabilities(width, height, rotate, mode='1')
cleanup()[source]

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)[source]

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)[source]

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)[source]

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)
hide()[source]

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()[source]

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.core.device.dummy(width=128, height=64, rotate=0, mode='RGB', **kwargs)[source]

Bases: luma.core.device.device

Pseudo-device that acts like a physical display, except that it does nothing other than retain a copy of the displayed image. It is mostly useful for testing. Supports 24-bit color depth.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and makes a copy of it for later use/inspection.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

luma.core.emulator

class luma.core.emulator.capture(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, file_template='luma_{0:06}.png', **kwargs)[source]

Bases: luma.core.emulator.emulator

Pseudo-device that acts like a physical display, except that it writes the image to a numbered PNG file when the display() method is called. Supports 24-bit color depth.

capabilities(width, height, rotate, mode='1')
cleanup()
clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and dumps it to a numbered PNG file.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.core.emulator.dummy(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, **kwargs)[source]

Bases: luma.core.emulator.emulator

Pseudo-device that acts like a physical display, except that it does nothing other than retain a copy of the displayed image. It is mostly useful for testing. Supports 24-bit color depth.

capabilities(width, height, rotate, mode='1')
cleanup()
clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and makes a copy of it for later use/inspection.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.core.emulator.emulator(width, height, rotate, mode, transform, scale)[source]

Bases: luma.core.device.device

Base class for emulated display driver classes

capabilities(width, height, rotate, mode='1')
cleanup()[source]
clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)
hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image)[source]

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.core.emulator.gifanim(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, filename='luma_anim.gif', duration=0.01, loop=0, max_frames=None, **kwargs)[source]

Bases: luma.core.emulator.emulator

Pseudo-device that acts like a physical display, except that it collects the images when the display() method is called, and on exit, assembles them into an animated GIF image. Supports 24-bit color depth, albeit with an indexed color palette.

capabilities(width, height, rotate, mode='1')
cleanup()
clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes an image, scales it according to the nominated transform, and stores it for later building into an animated GIF.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

write_animation()[source]
class luma.core.emulator.pygame(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, frame_rate=60, **kwargs)[source]

Bases: luma.core.emulator.emulator

Pseudo-device that acts like a physical display, except that it renders to an displayed window. The frame rate is limited to 60FPS (much faster than a Raspberry Pi can acheive, but this can be overridden as necessary). Supports 24-bit color depth.

pygame is used to render the emulated display window, and it’s event loop is checked to see if the ESC key was pressed or the window was dismissed: if so sys.exit() is called.

capabilities(width, height, rotate, mode='1')
cleanup()
clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and renders it to a pygame display surface.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

to_surface(image)

Converts a PIL.Image into a pygame.Surface, transforming it according to the transform and scale constructor arguments.

class luma.core.emulator.transformer(pygame, width, height, scale)[source]

Bases: object

Helper class used to dispatch transformation operations.

identity(surface)[source]

Fast scale operation that does not sample the results

led_matrix(surface)[source]

Transforms the input surface into an LED matrix (1 pixel = 1 LED)

none(surface)[source]

No-op transform - used when scale = 1

scale2x(surface)[source]

Scales using the AdvanceMAME Scale2X algorithm which does a ‘jaggie-less’ scale of bitmap graphics.

seven_segment(surface)[source]
smoothscale(surface)[source]

Smooth scaling using MMX or SSE extensions if available

luma.core.error

Exceptions for this library.

exception luma.core.error.DeviceAddressError[source]

Bases: luma.core.error.Error

Exception raised when an invalid device address is detected.

args
message
exception luma.core.error.DeviceDisplayModeError[source]

Bases: luma.core.error.Error

Exception raised when an invalid device display mode is detected.

args
message
exception luma.core.error.DeviceNotFoundError[source]

Bases: luma.core.error.Error

Exception raised when a device cannot be found.

args
message
exception luma.core.error.DevicePermissionError[source]

Bases: luma.core.error.Error

Exception raised when permission to access the device is denied.

args
message
exception luma.core.error.Error[source]

Bases: exceptions.Exception

Base class for exceptions in this library.

args
message

luma.core.mixin

class luma.core.mixin.capabilities[source]

Bases: object

capabilities(width, height, rotate, mode='1')[source]
clear()[source]

Initializes the device memory with an empty (blank) image.

display(image)[source]
preprocess(image)[source]

luma.core.render

class luma.core.render.canvas(device, dither=False)[source]

Bases: object

A canvas returns a properly-sized PIL.ImageDraw object onto which the caller can draw upon. As soon as the with-block completes, the resultant image is flushed onto the device.

By default, any color (other than black) will be _generally_ treated as white when displayed on monochrome devices. However, this behaviour can be changed by adding dither=True and the image will be converted from RGB space into a 1-bit monochrome image where dithering is employed to differentiate colors at the expense of resolution.

luma.core.serial

class luma.core.serial.i2c(bus=None, port=1, address=60)[source]

Bases: object

Wrap an I2C interface to provide data and command methods.

Parameters:
  • bus – I2C bus instance.
  • port (int) – I2C port number.
  • address – I2C address.
Raises:

Note

  1. Only one of bus OR port arguments should be supplied; if both are, then bus takes precedence.
  2. If bus is provided, there is an implicit expectation that it has already been opened.
cleanup()[source]

Clean up I2C resources

command(*cmd)[source]

Sends a command or sequence of commands through to the I2C address - maximum allowed is 32 bytes in one go.

data(data)[source]

Sends a data byte or sequence of data bytes through to the I2C address - maximum allowed in one transaction is 32 bytes, so if data is larger than this, it is sent in chunks.

class luma.core.serial.noop[source]

Bases: object

Does nothing, used for pseudo-devices / emulators / anything really

noop(*args, **kwargs)[source]
class luma.core.serial.spi(spi=None, gpio=None, port=0, device=0, bus_speed_hz=8000000, transfer_size=4096, bcm_DC=24, bcm_RST=25)[source]

Bases: object

Wraps an SPI interface to provide data and command methods.

Parameters:
  • spi – SPI interface (must be compatible with py-spidev)
  • gpio – GPIO interface (must be compatible with RPi.GPIO). For slaves that dont need reset or D/C functionality, supply a noop() implementation instead.
  • port (int) – SPI port, defaults to 0
  • device (int) – SPI device, defaults to 0
  • bus_speed_hz – SPI bus speed, defaults to 8MHz
  • transfer_size – Max bytes to transfer in one go. Some implementations only support maxium of 64 or 128 bytes, whereas RPi/py-spidev supports 4096 (default).
  • bcm_DC (int) – The BCM pin to connect data/command select (DC) to (defaults to 24).
  • bcm_RST (int) – The BCM pin to connect reset (RES / RST) to (defaults to 24).
Raises:

luma.core.error.DeviceNotFoundError – SPI device could not be found.

cleanup()[source]

Clean up SPI & GPIO resources

command(*cmd)[source]

Sends a command or sequence of commands through to the SPI device.

data(data)[source]

Sends a data byte or sequence of data bytes through to the SPI device. If the data is more than 4Kb in size, it is sent in chunks.

luma.core.threadpool

class luma.core.threadpool.threadpool(num_threads)[source]

Pool of threads consuming tasks from a queue

add_task(func, *args, **kargs)[source]

Add a task to the queue

wait_completion()[source]

Wait for completion of all the tasks in the queue

class luma.core.threadpool.worker(tasks)[source]

Bases: threading.Thread

Thread executing tasks from a given tasks queue

daemon

A boolean value indicating whether this thread is a daemon thread (True) or not (False).

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when no alive non-daemon threads are left.

getName()
ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isAlive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

isDaemon()
is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

run()[source]
setDaemon(daemonic)
setName(name)
start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

luma.core.virtual

luma.core.virtual.calc_bounds(xy, entity)[source]

For an entity with width and height attributes, determine the bounding box if were positioned at (x, y).

class luma.core.virtual.history(device)[source]

Bases: luma.core.mixin.capabilities

Wraps a device (or emulator) to provide a facility to be able to make a savepoint (a point at which the screen display can be “rolled-back” to).

This is mostly useful for displaying transient error/dialog messages which could be subsequently dismissed, reverting back to the previous display.

capabilities(width, height, rotate, mode='1')
clear()

Initializes the device memory with an empty (blank) image.

display(image)[source]
preprocess(image)
restore(drop=0)[source]

Restores the last savepoint. If drop is supplied and greater than zero, then that many savepoints are dropped, and the next savepoint is restored.

savepoint()[source]

Copies the last displayed image.

class luma.core.virtual.hotspot(width, height, draw_fn=None)[source]

Bases: luma.core.mixin.capabilities

A hotspot (a place of more than usual interest, activity, or popularity) is a live display which may be added to a virtual viewport - if the hotspot and the viewport are overlapping, then the update() method will be automatically invoked when the viewport is being refreshed or its position moved (such that an overlap occurs).

You would either:

  • create a hotspot instance, suppling a render function (taking an PIL.ImageDraw object, width & height dimensions. The render function should draw within a bounding box of (0, 0, width, height), and render a full frame.
  • sub-class hotspot and override the :func:should_redraw and update() methods. This might be more useful for slow-changing values where it is not necessary to update every refresh cycle, or your implementation is stateful.
capabilities(width, height, rotate, mode='1')
clear()

Initializes the device memory with an empty (blank) image.

display(image)
paste_into(image, xy)[source]
preprocess(image)
should_redraw()[source]

Override this method to return true or false on some condition (possibly on last updated member variable) so that for slow changing hotspots they are not updated too frequently.

update(draw)[source]
luma.core.virtual.range_overlap(a_min, a_max, b_min, b_max)[source]

Neither range is completely greater than the other

class luma.core.virtual.snapshot(width, height, draw_fn=None, interval=1.0)[source]

Bases: luma.core.virtual.hotspot

A snapshot is a type of hotspot, but only updates once in a given interval, usually much less frequently than the viewport requests refresh updates.

capabilities(width, height, rotate, mode='1')
clear()

Initializes the device memory with an empty (blank) image.

display(image)
paste_into(image, xy)[source]
preprocess(image)
should_redraw()[source]

Only requests a redraw after interval seconds have elapsed

update(draw)
class luma.core.virtual.terminal(device, font=None, color='white', bgcolor='black', tabstop=4, line_height=None, animate=True)[source]

Bases: object

Provides a terminal-like interface to a device (or a device-like object that has mixin.capabilities characteristics).

backspace()[source]

Moves the cursor one place to the left, erasing the character at the current position. Cannot move beyound column zero, nor onto the previous line

carriage_return()[source]

Returns the cursor position to the left-hand side without advancing downwards.

clear()[source]

Clears the display and resets the cursor position to (0, 0).

erase()[source]

Erase the contents of the cursor’s current postion without moving the cursor’s position.

flush()[source]

Cause the current backing store to be rendered on the nominated device.

newline()[source]

Advances the cursor position ot the left hand side, and to the next line. If the cursor is on the lowest line, the displayed contents are scrolled, causing the top line to be lost.

println(text='')[source]

Prints the supplied text to the device, scrolling where necessary. The text is always followed by a newline.

putch(ch, flush=True)[source]

Prints the specific character, which must be a valid printable ASCII value in the range 32..127 only.

puts(text)[source]

Prints the supplied text, handling special character codes for carriage return (r), newline (n), backspace (b) and tab (t).

If the animate flag was set to True (default), then each character is flushed to the device, giving the effect of 1970’s teletype device.

tab()[source]

Advances the cursor position to the next (soft) tabstop.

class luma.core.virtual.viewport(device, width, height)[source]

Bases: luma.core.mixin.capabilities

add_hotspot(hotspot, xy)[source]

Add the hotspot at (x, y). The hotspot must fit inside the bounds of the virtual device. If it does not then an AssertError is raised.

capabilities(width, height, rotate, mode='1')
clear()

Initializes the device memory with an empty (blank) image.

display(image)[source]
is_overlapping_viewport(hotspot, xy)[source]

Checks to see if the hotspot at position (x, y) is (at least partially) visible according to the position of the viewport

preprocess(image)
refresh()[source]
remove_hotspot(hotspot, xy)[source]

Remove the hotspot at (x, y): Any previously rendered image where the hotspot was placed is erased from the backing image, and will be “undrawn” the next time the virtual device is refreshed. If the specified hotspot is not found (x, y), a ValueError is raised.

set_position(xy)[source]

luma.oled.device

class luma.oled.device.sh1106(serial_interface=None, width=128, height=64, rotate=0, **kwargs)[source]

Bases: luma.core.device.device

Encapsulates the serial interface to the monochrome SH1106 OLED display hardware. On creation, an initialization sequence is pumped to the display to properly configure it. Further control commands can then be called to affect the brightness and other settings.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a 1-bit PIL.Image and dumps it to the SH1106 OLED display.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.oled.device.ssd1306(serial_interface=None, width=128, height=64, rotate=0, **kwargs)[source]

Bases: luma.core.device.device

Encapsulates the serial interface to the monochrome SSD1306 OLED display hardware. On creation, an initialization sequence is pumped to the display to properly configure it. Further control commands can then be called to affect the brightness and other settings.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a 1-bit PIL.Image and dumps it to the SSD1306 OLED display.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.oled.device.ssd1322(serial_interface=None, width=256, height=64, rotate=0, mode='RGB', **kwargs)[source]

Bases: luma.core.device.device

Encapsulates the serial interface to the 4-bit greyscale SSD1322 OLED display hardware. On creation, an initialization sequence is pumped to the display to properly configure it. Further control commands can then be called to affect the brightness and other settings.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(cmd, *args)[source]

Sends a command and an (optional) sequence of arguments through to the delegated serial interface. Note that the arguments are passed through as data.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a 1-bit monochrome or 24-bit RGB PIL.Image and dumps it to the SSD1322 OLED display, converting the image pixels to 4-bit greyscale using a simplified Luma calculation, based on Y’=0.299R’+0.587G’+0.114B’.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.oled.device.ssd1325(serial_interface=None, width=128, height=64, rotate=0, mode='RGB', **kwargs)[source]

Bases: luma.core.device.device

Encapsulates the serial interface to the 4-bit greyscale SSD1325 OLED display hardware. On creation, an initialization sequence is pumped to the display to properly configure it. Further control commands can then be called to affect the brightness and other settings.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a 1-bit monochrome or 24-bit RGB PIL.Image and dumps it to the SSD1325 OLED display, converting the image pixels to 4-bit greyscale using a simplified Luma calculation, based on Y’=0.299R’+0.587G’+0.114B’.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.oled.device.ssd1331(serial_interface=None, width=96, height=64, rotate=0, **kwargs)[source]

Bases: luma.core.device.device

Encapsulates the serial interface to the 16-bit color (5-6-5 RGB) SSD1331 OLED display hardware. On creation, an initialization sequence is pumped to the display to properly configure it. Further control commands can then be called to affect the brightness and other settings.

capabilities(width, height, rotate, mode='1')
cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)[source]

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters:level (int) – Desired contrast level in the range of 0-255.
data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a 24-bit RGB PIL.Image and dumps it to the SSD1331 OLED display.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)
show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.