5 releases

0.1.4 Apr 21, 2024
0.1.3 Apr 20, 2024
0.1.2 Apr 20, 2024
0.1.1 Apr 20, 2024
0.1.0 Apr 20, 2024

#129 in Embedded development

30 downloads per month


726 lines

SSD3306 I2C  

crates.io License Documentation

A Rust crate for SSD1306 LCD display over I2C



This crate is a fork of James Waples's SH1106 crate modifed for SSD1306 use updated to use embedded-hal 1.0.

The SSD1306 LCD contains old fashion 8 bit parallel interface, a SPI and I2C interface. This crate only uses the I2C interface. Also, note that this driver includes support for several display sizes but only 128 x 64 is avialble for the SSD1306 (as far as I know).


  • updated to use embedded-hal version 1.0.x
  • supports embedded-hal-bus 0.1.0 for I2C bus sharing
  • uses embedded-graphics crate for graphics abstraction
  • designed for embedded use (ESP32-C3, -C6 and -S3, etc.)
  • supports both primary and secondary SSD1306 I2C addresses (default is primary = 0x3c)
  • no_std embedded compatible


I wanted to add a LCD display to my home automation environmental sensor IoT creation but I could not find a crate for the SSD1306 that depends on embedded-hal 1.0. It needs to have several devices on one I2C bus and since my sensors are embedded-hal 1.0 based the SSD1306 crate needs to be also. So I did a quick job of migrating James's SH1106 crate from embedded-hal 0.2.x to 1.0, and modified it for the SSD1306 LCD. Why start with SH1106 instead of his SSD1306 create: because the SH1106 seemed more modern and does not depend on other embedded-hal 0.2 crates like display-interface-i2c (which is four years old now). Note that this ssd1306-i2c crate does not support SH1106 display because the display initialization is not compatible.

My Sparkfun SSD1306 LCD (LCD-23453) only supports I2C so I could not work with or test SPI.

Recent version history

  • 0.1.4 More documentation
  • 0.1.1 Some document typo fixes
  • 0.1.0 Initial release


Add the dependencies to Cargo.toml.

ssd1306-i2c version = "0.1"
embedded-graphics = "0.8.1" 
esp-idf-hal = "0.43.0"  # an embedded-hal for your platform

Simple Example

A more complete example is in the repository examples path. See James's SSH1106 crate repository examples folder for more examples: https://github.com/jamwaffles/sh1106/tree/master/examples.

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

use embedded_graphics::{
    mono_font::{ascii::FONT_6X10, ascii::FONT_6X13_BOLD, MonoTextStyleBuilder},
    image::{Image, ImageRawLE},
    text::{Baseline, Text},

use log::info;


fn main() -> Result<()> {
  // Bind the log crate to the ESP Logging facilities

  let peripherals = Peripherals::take().unwrap();
  let pins = peripherals.pins;
  let sda = pins.gpio0;
  let scl = pins.gpio1;
  let i2c = peripherals.i2c0;
  let config = I2cConfig::new().baudrate(400.kHz().into());
  let i2c_dev = I2cDriver::new(i2c, sda, scl, &config)?;

  let mut display: GraphicsMode<_> = Builder::new()
    .with_i2c_addr(0x3d)  //or 0x3c

  info!("calling display.init()");


  //********* display some text

  // creating MonoTextStyleBuilder
  let text_style = MonoTextStyleBuilder::new()

  let text_style_bold = MonoTextStyleBuilder::new()

  info!("displaying Hello world! on LCD");
  Text::with_baseline("Hello Rust World!....", Point::zero(), text_style_bold, Baseline::Top)
    .draw(&mut display)
  info!("displaying Hello Rust! on LCD");
  Text::with_baseline("SSD1306-I2C", Point::new(0, 19), text_style, Baseline::Top)
    .draw(&mut display)


  loop {
    info!("looping with delay so ESP32 watchdog does not restart controller");




You are free to copy, modify, and distribute this application with attribution under the terms of either

at your option.

This project is not affiliated with nor endorsed in any way by Sparkfun.


~11K SLoC