Skip to content

stm32-cpp/stm32-cpp-ssd1306

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

STM32 C++ SSD1306 Library

Prerequisites

This library uses libopencm3 for I²C communication.

Usage example

#include <SSD1306/SSD1306.h>
#include <SSD1306/Fonts/Pentacom.h>

// Init i2c (see libopencm3 documentation)
i2c_peripheral_disable(I2C1);
i2c_set_clock_frequency(I2C1, ...);
...
i2c_peripheral_enable(I2C1);

// Create SSD1306 instance
hw::SSD1306 ssd1306(
  I2C1,
  0x3c, // i2c address
  128,  // display width
  64    // display height
);

// Initialize display
ssd1306.init();

// Clear and update
ssd1306.clear();
ssd1306.refresh();

delay(1000);

// White fill
ssd1306.fill(
  hw::SSD1306::Color::White
);

// Create font
hw::Fonts::Pentacom font;

// Draw String
ssd1306.drawWString(
  10,   // X
  10,   // Y
  &font,
  hw::SSD1306::Color::Black,
  hw::SSD1306::WrapType::NoWrap,
  L"Hello World"
);

// Salute random dog
ssd1306.drawWString(
  10,   // X
  40,   // Y
  &font,
  hw::SSD1306::Color::Black,
  hw::SSD1306::WrapType::NoWrap,
  L"Привет, пёс!"
);

// Push changes
ssd1306.refresh();

Font creation

Font used in this library initially was found in StanislavLakhtin's ssd1306 library. You can use his tool and instructions to create your own font.