Crate sh1106

source ·
Expand description

sh1106 OLED display driver

The driver must be initialised by passing an I2C or SPI interface peripheral to the Builder, which will in turn create a driver instance in a particular mode. By default, the builder returns a mode::RawMode instance which isn’t very useful by itself. You can coerce the driver into a more useful mode by calling into() and defining the type you want to coerce to. For example, to initialise the display with an I2C interface and mode::GraphicsMode, you would do something like this:

use sh1106::{prelude::*, Builder};

let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();

display.init().unwrap();
display.flush().unwrap();

display.set_pixel(10, 20, 1);

display.flush().unwrap();

See the example for more usage. The entire embedded_graphics featureset is supported by this driver.

It’s possible to customise the driver to suit your display/application. Take a look at the Builder for available options.

Examples

Examples can be found in the examples/ folder

Draw some text to the display

Uses mode::GraphicsMode and embedded_graphics.

use embedded_graphics::{
    mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
    pixelcolor::BinaryColor,
    prelude::*,
    text::{Baseline, Text},
};
use sh1106::{prelude::*, Builder};

let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();

display.init().unwrap();
display.flush().unwrap();

let text_style = MonoTextStyleBuilder::new()
    .font(&FONT_6X10)
    .text_color(BinaryColor::On)
    .build();

Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top)
    .draw(&mut display)
    .unwrap();

Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top)
    .draw(&mut display)
    .unwrap();

display.flush().unwrap();

Re-exports

Modules

Enums

  • Errors in this crate