OLED dipleje s chipem SSD1306 se vyrábějí v různých provedeních (32x128 bodů a 64x128 bodů), v různých barvách a s různým připojením (SPI a I2c).

Bude následovat popis knihovny pico-ssd1306, pomocí které můžeme používat tyto displeje v jazyce C s pico-sdk. Knihovnu napsal David Schramm, je pod MIT licencí a možno ji stáhnou z Githubu. Já jsem do ní doplnil fonty 8x5 pixelů a 16x8 pixelů obsahující české znaky, v kódování ISO-8859-2. Knihovna byla testována na tomto konkrétním typu dipleje: 0.91" 128x32 OLED displej, I2C, bílý.

  • I2c adresa: 0x3C

  • Frekvence I2c: 400 KHz

Knihovna pico-ssd1306 nebude fungovat s displejem s čipem SH1106 (například s tímto LaskaKit OLED displej 128x64 1.3" I²C), musí se použít jiná knihovna pi-pico-ss-oled popsaná zde. Aktualizace 20.2.2024.
Schéma zapojení

Pico Oled SSD1306 I2C schema

Použití knihovny

Zkopírujte do svého projektu soubory font.h, ssd1306.c, ssd1306.h a pokud budete používat české znaky, tak font_spleen_8x5.h (font malinký 8x5 pixelů) a font_spleen_16x8a.h (font velký 16x8 pixelů).

Dokumentace k funkcím

Dokumentace se nachází v hlavičkovém souboru ssd1306.h
/*
MIT License

Copyright (c) 2021 David Schramm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/**
* @file ssd1306.h
*
* simple driver for ssd1306 displays
*/

#ifndef _inc_ssd1306
#define _inc_ssd1306
#include <pico/stdlib.h>
#include <hardware/i2c.h>

/**
*	@brief defines commands used in ssd1306
*/
typedef enum {
    SET_CONTRAST = 0x81,
    SET_ENTIRE_ON = 0xA4,
    SET_NORM_INV = 0xA6,
    SET_DISP = 0xAE,
    SET_MEM_ADDR = 0x20,
    SET_COL_ADDR = 0x21,
    SET_PAGE_ADDR = 0x22,
    SET_DISP_START_LINE = 0x40,
    SET_SEG_REMAP = 0xA0,
    SET_MUX_RATIO = 0xA8,
    SET_COM_OUT_DIR = 0xC0,
    SET_DISP_OFFSET = 0xD3,
    SET_COM_PIN_CFG = 0xDA,
    SET_DISP_CLK_DIV = 0xD5,
    SET_PRECHARGE = 0xD9,
    SET_VCOM_DESEL = 0xDB,
    SET_CHARGE_PUMP = 0x8D
} ssd1306_command_t;

/**
*	@brief holds the configuration
*/
typedef struct {
    uint8_t width; 		/**< width of display */
    uint8_t height; 	/**< height of display */
    uint8_t pages;		/**< stores pages of display (calculated on initialization*/
    uint8_t address; 	/**< i2c address of display*/
    i2c_inst_t *i2c_i; 	/**< i2c connection instance */
    bool external_vcc; 	/**< whether display uses external vcc */
    uint8_t *buffer;	/**< display buffer */
    size_t bufsize;		/**< buffer size */
} ssd1306_t;

/**
*	@brief initialize display
*
*	@param[in] p : pointer to instance of ssd1306_t
*	@param[in] width : width of display
*	@param[in] height : heigth of display
*	@param[in] address : i2c address of display
*	@param[in] i2c_instance : instance of i2c connection
*
* 	@return bool.
*	@retval true for Success
*	@retval false if initialization failed
*/
bool ssd1306_init(ssd1306_t *p, uint16_t width, uint16_t height, uint8_t address, i2c_inst_t *i2c_instance);

/**
*	@brief deinitialize display
*
*	@param[in] p : instance of display
*
*/
void ssd1306_deinit(ssd1306_t *p);

/**
*	@brief turn off display
*
*	@param[in] p : instance of display
*
*/
void ssd1306_poweroff(ssd1306_t *p);

/**
	@brief turn on display

	@param[in] p : instance of display

*/
void ssd1306_poweron(ssd1306_t *p);

/**
	@brief set contrast of display

	@param[in] p : instance of display
	@param[in] val : contrast

*/
void ssd1306_contrast(ssd1306_t *p, uint8_t val);

/**
	@brief set invert display

	@param[in] p : instance of display
	@param[in] inv : inv==0: disable inverting, inv!=0: invert

*/
void ssd1306_invert(ssd1306_t *p, uint8_t inv);

/**
	@brief display buffer, should be called on change

	@param[in] p : instance of display

*/
void ssd1306_show(ssd1306_t *p);

/**
	@brief clear display buffer

	@param[in] p : instance of display

*/
void ssd1306_clear(ssd1306_t *p);

/**
	@brief clear pixel on buffer

	@param[in] p : instance of display
	@param[in] x : x position
	@param[in] y : y position
*/
void ssd1306_clear_pixel(ssd1306_t *p, uint32_t x, uint32_t y);

/**
	@brief draw pixel on buffer

	@param[in] p : instance of display
	@param[in] x : x position
	@param[in] y : y position
*/
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y);

/**
	@brief draw line on buffer

	@param[in] p : instance of display
	@param[in] x1 : x position of starting point
	@param[in] y1 : y position of starting point
	@param[in] x2 : x position of end point
	@param[in] y2 : y position of end point
*/
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2);

/**
	@brief clear square at given position with given size

	@param[in] p : instance of display
	@param[in] x : x position of starting point
	@param[in] y : y position of starting point
	@param[in] width : width of square
	@param[in] height : height of square
*/
void ssd1306_clear_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);

/**
	@brief draw filled square at given position with given size

	@param[in] p : instance of display
	@param[in] x : x position of starting point
	@param[in] y : y position of starting point
	@param[in] width : width of square
	@param[in] height : height of square
*/
void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);

/**
	@brief draw empty square at given position with given size

	@param[in] p : instance of display
	@param[in] x : x position of starting point
	@param[in] y : y position of starting point
	@param[in] width : width of square
	@param[in] height : height of square
*/
void ssd1306_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);

/**
	@brief draw monochrome bitmap with offset

	@param[in] p : instance of display
	@param[in] data : image data (whole file)
	@param[in] size : size of image data in bytes
	@param[in] x_offset : offset of horizontal coordinate
	@param[in] y_offset : offset of vertical coordinate
*/
void ssd1306_bmp_show_image_with_offset(ssd1306_t *p, const uint8_t *data, const long size, uint32_t x_offset, uint32_t y_offset);

/**
	@brief draw monochrome bitmap

	@param[in] p : instance of display
	@param[in] data : image data (whole file)
	@param[in] size : size of image data in bytes
*/
void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size);

/**
	@brief draw char with given font

	@param[in] p : instance of display
	@param[in] x : x starting position of char
	@param[in] y : y starting position of char
	@param[in] scale : scale font to n times of original size (default should be 1)
	@param[in] font : pointer to font
	@param[in] c : character to draw
*/
void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c);

/**
	@brief draw char with builtin font

	@param[in] p : instance of display
	@param[in] x : x starting position of char
	@param[in] y : y starting position of char
	@param[in] scale : scale font to n times of original size (default should be 1)
	@param[in] c : character to draw
*/
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c);

/**
	@brief draw string with given font

	@param[in] p : instance of display
	@param[in] x : x starting position of text
	@param[in] y : y starting position of text
	@param[in] scale : scale font to n times of original size (default should be 1)
	@param[in] font : pointer to font
	@param[in] s : text to draw
*/
void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s );

/**
	@brief draw string with builtin font

	@param[in] p : instance of display
	@param[in] x : x starting position of text
	@param[in] y : y starting position of text
	@param[in] scale : scale font to n times of original size (default should be 1)
	@param[in] s : text to draw
*/
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s);

// for fonts 16x8 we must use unit16_t
/**
	@brief draw char with given font

	@param[in] p : instance of display
	@param[in] x : x starting position of char
	@param[in] y : y starting position of char
	@param[in] scale : scale font to n times of original size (default should be 1)
	@param[in] font : pointer to font 16x8
	@param[in] c : character to draw
*/

#endif

Tvorba českých znaků

Knihovna neobsahuje české znaky, proto jsem je doplnil. Na rozdíl od LCD displeje 16x2 s HD44780 se znaky definují po sloupcích, nikoli po řádcích.

Znaky s kódy 0x01 až 0x7f (dekadicky 127) odpovídají kódové stránce US ASCII 497, znaky s kódy 0x80 až 0xff odpovídají kové stránkce ISO-8859-2 s doplněním řeckých písmenek a baterie na volné místo od znaku 0x80 do 0x9f.

Pro tvorbu nových znaků nebo opravu stávajících je možné použít následující webové stránky, kde je možné znak naklikat myší a výsledný přepočet do hexa číslic nakopírovat do příslušného souboru fontu.

Příklad tvorby znaku 16x8 "baterie nabitá na 50%"

priklad tvorby znaku baterie50

Při tvorbě nového fontu nebo úpravě stávajícího není možné vynechávat znaky na nepoužitých pozicích (je potřeba tam napsat nuly), protože kód znaku se počítá od 1. řádku pole až do konce.

Příklad fontu 16x8 se znaky od 1 do 127:
/* Spleen font 16x8a (redukovaný)
 * (c) Jirka Chráska 2024, <jirka@lixis.cz>
 * BSD license
*/

#ifndef _inc_font_spleen_8x16a
#define _inc_font_xpleen_8x16a

/*
 * Format
 * <height>, <width>, <additional spacing per char>, <first ascii char>, <last ascii char>,
 * <data>
 */

/* data format, character encoding ISO-8859-2 with added characters.

In a column first uint8_t is lower 8 row of bit matrix, next uint8_t is higher 8 row of bit matrix.
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 0
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 1
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 2
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 3
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 4
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 5
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 6
-------------------------
|h0|h1|h2|h3|h4|h5|h6|h7| bit 7
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 0
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 1
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 2
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 3
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 4
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 5
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 6
-------------------------
|d0|d1|d2|d3|d4|d5|d6|d7| bit 7
-------------------------
*/
const uint8_t font_spleen_16x8a[] =
{
			16, 8, 1, 0x20, 0x7f,  (1)
//d0,  h0,   d1,  h1,   d2,  h2,   d3,  h3,   d4,  h4,   d5,  h5,   d6,  h6,   d7,  h7,  char code character
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x20 prázdný znak mezera
0x00,0x00, 0x00,0x00, 0x00,0x00, 0xfc,0x1b, 0xfc,0x1b, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x21 ! vykřičník
0x00,0x00, 0x1e,0x00, 0x1e,0x00, 0x00,0x00, 0x00,0x00, 0x1e,0x00, 0x1e,0x00, 0x00,0x00, // 0x22 "
0x10,0x02, 0xfc,0x0f, 0xfc,0x0f, 0x10,0x02, 0xfc,0x0f, 0xfc,0x0f, 0x10,0x02, 0x00,0x00, // 0x23 #
0x38,0x00, 0x7c,0x08, 0x44,0x08, 0xfe,0x1f, 0x44,0x08, 0xc4,0x0f, 0x84,0x07, 0x00,0x00, // 0x24 $
0x00,0x00, 0x18,0x0c, 0x18,0x0f, 0xc0,0x03, 0xf0,0x00, 0x3c,0x06, 0x0c,0x06, 0x00,0x00, // 0x25 %
0x00,0x07, 0xb8,0x0f, 0xfc,0x08, 0xc4,0x09, 0x7c,0x0f, 0x38,0x06, 0x00,0x09, 0x00,0x00, // 0x26 &
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x1e,0x00, 0x1e,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x27 '
0x00,0x00, 0xe0,0x01, 0xf8,0x07, 0x1c,0x0e, 0x06,0x18, 0x02,0x10, 0x02,0x10, 0x00,0x00, // 0x28 (
0x00,0x00, 0x02,0x10, 0x02,0x10, 0x06,0x18, 0x1c,0x0e, 0xf8,0x07, 0xe0,0x01, 0x00,0x00, // 0x29 )
0x80,0x00, 0x90,0x04, 0xb0,0x06, 0xe0,0x03, 0xe0,0x03, 0xb0,0x06, 0x90,0x04, 0x80,0x00, // 0x2a *
0x00,0x00, 0x80,0x00, 0x80,0x00, 0xe0,0x03, 0xe0,0x03, 0x80,0x00, 0x80,0x00, 0x00,0x00, // 0x2b +
0x00,0x00, 0x00,0x00, 0x00,0x10, 0x00,0x1c, 0x00,0x0c, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x2c ,
0x00,0x00, 0x40,0x00, 0x40,0x00, 0x40,0x00, 0x40,0x00, 0x40,0x00, 0x40,0x00, 0x00,0x00, // 0x2d -
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x0c, 0x00,0x0c, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x2e .
0x00,0x18, 0x00,0x1e, 0x80,0x07, 0xe0,0x01, 0x78,0x00, 0x1e,0x00, 0x06,0x00, 0x00,0x00, // 0x2f /
0xf8,0x07, 0xfc,0x0f, 0x84,0x09, 0xc4,0x08, 0x64,0x08, 0xfc,0x0f, 0xf8,0x07, 0x00,0x00, // 0x30 0
0x00,0x00, 0x30,0x08, 0x18,0x08, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x08, 0x00,0x08, 0x00,0x00, // 0x31 1
0x08,0x0c, 0x0c,0x0e, 0x04,0x0b, 0x84,0x09, 0xc4,0x08, 0x7c,0x0c, 0x38,0x0c, 0x00,0x00, // 0x32 2
0x08,0x04, 0x0c,0x0c, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xfc,0x0f, 0xb8,0x07, 0x00,0x00, // 0x33 3
0xfc,0x01, 0xfc,0x01, 0x00,0x01, 0x00,0x01, 0xf0,0x0f, 0xf0,0x0f, 0x00,0x01, 0x00,0x00, // 0x34 4
0x7c,0x04, 0x7c,0x0c, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xcc,0x0f, 0x8c,0x07, 0x00,0x00, // 0x35 5
0xf8,0x07, 0xfc,0x0f, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xcc,0x0f, 0x88,0x07, 0x00,0x00, // 0x36 6
0x0c,0x00, 0x0c,0x00, 0x04,0x0f, 0x84,0x0f, 0xc4,0x00, 0x7c,0x00, 0x3c,0x00, 0x00,0x00, // 0x37 7
0xb8,0x07, 0xfc,0x0f, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xfc,0x0f, 0xb8,0x07, 0x00,0x00, // 0x38 8
0x78,0x04, 0xfc,0x0c, 0x84,0x08, 0x84,0x08, 0x84,0x08, 0xfc,0x0f, 0xf8,0x07, 0x00,0x00, // 0x39 9
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x60,0x0c, 0x60,0x0c, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x3a :
0x00,0x00, 0x00,0x00, 0x00,0x10, 0x60,0x1c, 0x60,0x0c, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x3b ;
0x00,0x00, 0xc0,0x00, 0xe0,0x01, 0x30,0x03, 0x18,0x06, 0x0c,0x0c, 0x04,0x08, 0x00,0x00, // 0x3c <
0x00,0x00, 0x20,0x01, 0x20,0x01, 0x20,0x01, 0x20,0x01, 0x20,0x01, 0x20,0x01, 0x00,0x00, // 0x3d =
0x00,0x00, 0x04,0x08, 0x0c,0x0c, 0x18,0x06, 0x30,0x03, 0xe0,0x01, 0xc0,0x00, 0x00,0x00, // 0x3e >
0x08,0x00, 0x0c,0x00, 0x84,0x0d, 0xc4,0x0d, 0x64,0x00, 0x3c,0x00, 0x18,0x00, 0x00,0x00, // 0x3f ?
0xf0,0x07, 0xf8,0x0f, 0x08,0x08, 0xe8,0x0b, 0xe8,0x0b, 0x08,0x0a, 0xf0,0x03, 0x00,0x00, // 0x40 @
0xf8,0x0f, 0xfc,0x0f, 0x44,0x00, 0x44,0x00, 0x44,0x00, 0xfc,0x0f, 0xf8,0x0f, 0x00,0x00, // 0x41 A  LATIN CAPITAL LETTER A
0xfc,0x0f, 0xfc,0x0f, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xfc,0x0f, 0xb8,0x07, 0x00,0x00, // 0x42 B  LATIN CAPITAL LETTER B
0xf8,0x07, 0xfc,0x0f, 0x04,0x08, 0x04,0x08, 0x04,0x08, 0x04,0x08, 0x04,0x08, 0x00,0x00, // 0x43 C  LATIN CAPITAL LETTER C
0xfc,0x0f, 0xfc,0x0f, 0x04,0x08, 0x04,0x08, 0x04,0x08, 0xfc,0x0f, 0xf8,0x07, 0x00,0x00, // 0x44 D  LATIN CAPITAL LETTER D
0xf8,0x07, 0xfc,0x0f, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0x04,0x08, 0x04,0x08, 0x00,0x00, // 0x45 E  LATIN CAPITAL LETTER E
0xf8,0x0f, 0xfc,0x0f, 0x44,0x00, 0x44,0x00, 0x44,0x00, 0x04,0x00, 0x04,0x00, 0x00,0x00, // 0x46 F  LATIN CAPITAL LETTER F
0xf8,0x07, 0xfc,0x0f, 0x04,0x08, 0x44,0x08, 0x44,0x08, 0xc4,0x0f, 0xc4,0x0f, 0x00,0x00, // 0x47 G  LATIN CAPITAL LETTER G
0xfc,0x0f, 0xfc,0x0f, 0x40,0x00, 0x40,0x00, 0x40,0x00, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x00, // 0x48 H  LATIN CAPITAL LETTER H
0x00,0x00, 0x04,0x08, 0x04,0x08, 0xfc,0x0f, 0xfc,0x0f, 0x04,0x08, 0x04,0x08, 0x00,0x00, // 0x49 I  LATIN CAPITAL LETTER I
0x00,0x04, 0x04,0x0c, 0x04,0x08, 0xfc,0x0f, 0xfc,0x07, 0x04,0x00, 0x04,0x00, 0x00,0x00, // 0x4a J  LATIN CAPITAL LETTER J
0xfc,0x0f, 0xfc,0x0f, 0x40,0x00, 0xe0,0x00, 0xb0,0x01, 0x1c,0x0f, 0x0c,0x0e, 0x00,0x00, // 0x4b K  LATIN CAPITAL LETTER K
0xfc,0x0f, 0xfc,0x0f, 0x00,0x08, 0x00,0x08, 0x00,0x08, 0x00,0x08, 0x00,0x08, 0x00,0x00, // 0x4c L  LATIN CAPITAL LETTER L
0xfc,0x0f, 0xfc,0x0f, 0x18,0x00, 0x30,0x00, 0x18,0x00, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x00, // 0x4d M  LATIN CAPITAL LETTER M
0xfc,0x0f, 0xfc,0x0f, 0x30,0x00, 0xc0,0x00, 0x00,0x03, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x00, // 0x4e N  LATIN CAPITAL LETTER N
0xf8,0x07, 0xfc,0x0f, 0x04,0x08, 0x04,0x08, 0x04,0x08, 0xfc,0x0f, 0xf8,0x07, 0x00,0x00, // 0x4f O  LATIN CAPITAL LETTER O
0xfc,0x0f, 0xfc,0x0f, 0x44,0x00, 0x44,0x00, 0x44,0x00, 0x7c,0x00, 0x38,0x00, 0x00,0x00, // 0x50 P  LATIN CAPITAL LETTER P
0xf8,0x07, 0xfc,0x0f, 0x04,0x08, 0x04,0x1e, 0x04,0x38, 0xfc,0x2f, 0xf8,0x07, 0x00,0x00, // 0x51 Q  LATIN CAPITAL LETTER Q
0xfc,0x0f, 0xfc,0x0f, 0x44,0x00, 0x44,0x00, 0x44,0x00, 0xfc,0x0f, 0xb8,0x0f, 0x00,0x00, // 0x52 R  LATIN CAPITAL LETTER R
0x38,0x08, 0x7c,0x08, 0x44,0x08, 0x44,0x08, 0x44,0x08, 0xc4,0x0f, 0x84,0x07, 0x00,0x00, // 0x53 S  LATIN CAPITAL LETTER S
0x04,0x00, 0x04,0x00, 0x04,0x00, 0xfc,0x0f, 0xfc,0x0f, 0x04,0x00, 0x04,0x00, 0x04,0x00, // 0x54 T  LATIN CAPITAL LETTER T
0xfc,0x07, 0xfc,0x0f, 0x00,0x08, 0x00,0x08, 0x00,0x08, 0xfc,0x0f, 0xfc,0x07, 0x00,0x00, // 0x55 U  LATIN CAPITAL LETTER U
0xfc,0x01, 0xfc,0x03, 0x00,0x06, 0x00,0x0c, 0x00,0x06, 0xfc,0x03, 0xfc,0x01, 0x00,0x00, // 0x56 V  LATIN CAPITAL LETTER V
0xfc,0x0f, 0xfc,0x0f, 0x00,0x06, 0x00,0x03, 0x00,0x06, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x00, // 0x57 W  LATIN CAPITAL LETTER W
0x1c,0x0f, 0xbc,0x0f, 0xe0,0x00, 0x40,0x00, 0xe0,0x00, 0xbc,0x0f, 0x1c,0x0f, 0x00,0x00, // 0x58 X  LATIN CAPITAL LETTER X
0x3c,0x08, 0x7c,0x08, 0x40,0x08, 0x40,0x08, 0x40,0x08, 0xfc,0x0f, 0xfc,0x07, 0x00,0x00, // 0x59 Y  LATIN CAPITAL LETTER Y
0x04,0x0e, 0x04,0x0f, 0x84,0x09, 0xc4,0x08, 0x64,0x08, 0x3c,0x08, 0x1c,0x08, 0x00,0x00, // 0x5a Z  LATIN CAPITAL LETTER Z
0x00,0x00, 0x00,0x00, 0xfe,0x1f, 0xfe,0x1f, 0x02,0x10, 0x02,0x10, 0x02,0x10, 0x00,0x00, // 0x5b [
0x06,0x00, 0x1e,0x00, 0x78,0x00, 0xe0,0x01, 0x80,0x07, 0x00,0x1e, 0x00,0x18, 0x00,0x00, // 0x5c "\"
0x00,0x00, 0x02,0x10, 0x02,0x10, 0x02,0x10, 0xfe,0x1f, 0xfe,0x1f, 0x00,0x00, 0x00,0x00, // 0x5d ]
0x10,0x00, 0x18,0x00, 0x0c,0x00, 0x06,0x00, 0x0c,0x00, 0x18,0x00, 0x10,0x00, 0x00,0x00, // 0x5e ^
0x00,0x40, 0x00,0x40, 0x00,0x40, 0x00,0x40, 0x00,0x40, 0x00,0x40, 0x00,0x40, 0x00,0x00, // 0x5f _ podtržítko
0x00,0x00, 0x00,0x00, 0x02,0x00, 0x06,0x00, 0x0c,0x00, 0x08,0x00, 0x00,0x00, 0x00,0x00, // 0x60 `
0x00,0x07, 0xa0,0x0f, 0xa0,0x08, 0xa0,0x08, 0xa0,0x08, 0xe0,0x0f, 0xc0,0x0f, 0x00,0x00, // 0x61 a  LATIN SMALL LETTER a
0xfc,0x0f, 0xfc,0x0f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0xe0,0x0f, 0xc0,0x07, 0x00,0x00, // 0x62 b  LATIN SMALL LETTER b
0xc0,0x07, 0xe0,0x0f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0x00,0x00, // 0x63 c  LATIN SMALL LETTER c
0xc0,0x07, 0xe0,0x0f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0xfc,0x0f, 0xfc,0x0f, 0x00,0x00, // 0x64 d  LATIN SMALL LETTER d
0xc0,0x07, 0xe0,0x0f, 0x20,0x09, 0x20,0x09, 0x20,0x09, 0xe0,0x09, 0xe0,0x09, 0x00,0x00, // 0x65 e  LATIN SMALL LETTER e
0x00,0x00, 0x40,0x00, 0xf8,0x0f, 0xfc,0x0f, 0x44,0x00, 0x44,0x00, 0x04,0x00, 0x00,0x00, // 0x66 f  LATIN SMALL LETTER f
0xc0,0x47, 0xe0,0x4f, 0x20,0x48, 0x20,0x48, 0x20,0x48, 0xe0,0x7f, 0xc0,0x37, 0x00,0x00, // 0x67 g  LATIN SMALL LETTER g
0xfc,0x0f, 0xfc,0x0f, 0x20,0x00, 0x20,0x00, 0x20,0x00, 0xe0,0x0f, 0xc0,0x0f, 0x00,0x00, // 0x68 h  LATIN SMALL LETTER h
0x00,0x00, 0x00,0x00, 0x20,0x00, 0xec,0x0f, 0xec,0x0f, 0x00,0x08, 0x00,0x00, 0x00,0x00, // 0x69 i  LATIN SMALL LETTER i
0x00,0x00, 0x00,0x40, 0x00,0x40, 0xec,0x7f, 0xec,0x3f, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x6a j  LATIN SMALL LETTER j
0xfc,0x0f, 0xfc,0x0f, 0x80,0x01, 0xc0,0x03, 0x60,0x06, 0x20,0x0c, 0x00,0x08, 0x00,0x00, // 0x6b k  LATIN SMALL LETTER k
0x00,0x00, 0x00,0x00, 0xfc,0x07, 0xfc,0x0f, 0x00,0x08, 0x00,0x08, 0x00,0x00, 0x00,0x00, // 0x6c l  LATIN SMALL LETTER l
0xe0,0x0f, 0xe0,0x0f, 0x20,0x00, 0xc0,0x03, 0x20,0x00, 0xe0,0x0f, 0xc0,0x0f, 0x00,0x00, // 0x6d m  LATIN SMALL LETTER m
0xe0,0x0f, 0xe0,0x0f, 0x20,0x00, 0x20,0x00, 0x20,0x00, 0xe0,0x0f, 0xc0,0x0f, 0x00,0x00, // 0x6e n  LATIN SMALL LETTER n
0xc0,0x07, 0xe0,0x0f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0xe0,0x0f, 0xc0,0x07, 0x00,0x00, // 0x6f o  LATIN SMALL LETTER o
0xe0,0x7f, 0xe0,0x7f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0xe0,0x0f, 0xc0,0x07, 0x00,0x00, // 0x70 p  LATIN SMALL LETTER p
0xc0,0x07, 0xe0,0x0f, 0x20,0x08, 0x20,0x08, 0x20,0x08, 0xe0,0x7f, 0xe0,0x7f, 0x00,0x00, // 0x71 q  LATIN SMALL LETTER q
0xc0,0x0f, 0xe0,0x0f, 0x20,0x00, 0x20,0x00, 0x20,0x00, 0x60,0x00, 0x60,0x00, 0x00,0x00, // 0x72 r  LATIN SMALL LETTER r
0xc0,0x08, 0xe0,0x09, 0x20,0x09, 0x20,0x09, 0x20,0x09, 0x20,0x0f, 0x20,0x06, 0x00,0x00, // 0x73 s  LATIN SMALL LETTER s
0x00,0x00, 0x20,0x00, 0xfc,0x07, 0xfc,0x0f, 0x20,0x08, 0x20,0x08, 0x00,0x08, 0x00,0x00, // 0x74 t  LATIN SMALL LETTER t
0xe0,0x07, 0xe0,0x0f, 0x00,0x08, 0x00,0x08, 0x00,0x08, 0xe0,0x0f, 0xe0,0x0f, 0x00,0x00, // 0x75 u  LATIN SMALL LETTER u
0xe0,0x01, 0xe0,0x03, 0x00,0x06, 0x00,0x0c, 0x00,0x06, 0xe0,0x03, 0xe0,0x01, 0x00,0x00, // 0x76 v  LATIN SMALL LETTER v
0xe0,0x07, 0xe0,0x0f, 0x00,0x08, 0x80,0x07, 0x00,0x08, 0xe0,0x0f, 0xe0,0x0f, 0x00,0x00, // 0x77 w  LATIN SMALL LETTER w
0x20,0x0c, 0x60,0x0e, 0xc0,0x03, 0x80,0x01, 0xc0,0x03, 0x60,0x0e, 0x20,0x0c, 0x00,0x00, // 0x78 x  LATIN SMALL LETTER x
0xe0,0x47, 0xe0,0x4f, 0x00,0x48, 0x00,0x48, 0x00,0x48, 0xe0,0x7f, 0xe0,0x3f, 0x00,0x00, // 0x79 y  LATIN SMALL LETTER y
0x20,0x08, 0x20,0x0c, 0x20,0x0e, 0x20,0x0b, 0xa0,0x09, 0xe0,0x08, 0x60,0x08, 0x00,0x00, // 0x7a z  LATIN SMALL LETTER z
0x00,0x00, 0xc0,0x00, 0xc0,0x00, 0xfc,0x0f, 0x3e,0x1f, 0x02,0x10, 0x02,0x10, 0x00,0x00, // 0x7b {  LEFT CURLY BRACKET
0x00,0x00, 0x00,0x00, 0x00,0x00, 0xfe,0x1f, 0xfe,0x1f, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x7c |  VERTICAL LINE
0x00,0x00, 0x02,0x10, 0x02,0x10, 0x3e,0x1f, 0xfc,0x0f, 0xc0,0x00, 0xc0,0x00, 0x00,0x00, // 0x7d }  RIGHT CURLY BRACKER
0x00,0x00, 0x80,0x01, 0xc0,0x00, 0xc0,0x00, 0x80,0x01, 0x80,0x01, 0xc0,0x00, 0x00,0x00, // 0x7e ~  TILDE
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, // 0x7f nezlomitelná mezera
};
1 číslo 16 znamená výšku fontu, číslo 8 znamená šířku fontu, číslo 1 znamená vynechávej mezi znaky 1 sloupeček, číslo 0x20 značí že font začíná od pozice 0x20 (32 dekadicky), a číslo 0x7f namená že font končí na znaku s kódem 0x7f (127 dekadicky).

Testování

example2.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"

#include "ssd1306.h"
#include "image.h"
#include "font_spleen_8x5.h"
#include "font_spleen_16x8a.h"

const uint8_t num_chars_per_disp[]={20,20,20,20,20};
const uint8_t *fonts[2]= {font_spleen_8x5, font_spleen_16x8a};

#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 32
#define I2C_ADDRESS 0x3C
#define I2C_FREQ 400000
#define SLEEPTIME 55

void setup_gpios(void);
void animation(void);

int main() {
    stdio_init_all();

    printf("konfigurace pinů...\n");
    setup_gpios();

    printf("jedeme animovat...\n");
    animation();

    return 0;
}


void setup_gpios(void) {
    i2c_init(i2c_default, I2C_FREQ);
    gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
    gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
    gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
    gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
}


void animation(void) {
    const char *words[]= {"SSD1306", "DISPLAY", "DRIVER"};

    ssd1306_t disp;
    disp.external_vcc = false;
    ssd1306_init(&disp, DISPLAY_WIDTH, DISPLAY_HEIGHT, I2C_ADDRESS, i2c_default);
    ssd1306_clear(&disp);

    printf("ANIMATION!\n");

    char buf[128];

    for(;;) {

        // testování fontů spleen 8x5 a 16x8
        ssd1306_clear(&disp);
        sprintf(buf,"%s","(c) Jiří Chráska 2024");
        ssd1306_draw_string_with_font(&disp, 0, 1, 1, font_spleen_8x5, buf);
        ssd1306_draw_line(&disp, 0, 13, 127, 13);
        sprintf(buf,"%s","jirka@lixis.cz");
        ssd1306_draw_string_with_font(&disp, 0, 15, 1, font_spleen_8x5, buf);
        ssd1306_show(&disp);
        sleep_ms(4000);

        ssd1306_clear(&disp);
        ssd1306_draw_string_with_font(&disp, 0,  0, 1, font_spleen_8x5, "Příliš žluťoučký");
        ssd1306_draw_string_with_font(&disp, 0, 16, 1, font_spleen_8x5, "kůň pěl ďábelské ódy.");
        ssd1306_show(&disp);
        sleep_ms(2000);

        // nabíjení baterie
        for(int i=0; i<10; i++) {
            ssd1306_clear(&disp);
            ssd1306_draw_string_with_font(&disp, 0,  0, 1, font_spleen_16x8a, "Nabíjení");
            ssd1306_draw_string_with_font(&disp, 0, 16, 1, font_spleen_16x8a, "akumulátoru");
            for(uint8_t b=0x80; b<0x86; b++) {
                ssd1306_draw_char_with_font(&disp, 120, 0, 1, font_spleen_16x8a, b);
                ssd1306_show(&disp);
                sleep_ms(400);
                }
            }

        ssd1306_clear(&disp);
        ssd1306_draw_string_with_font(&disp, 0,  0, 1, font_spleen_16x8a, "Maličký");
        ssd1306_draw_string_with_font(&disp, 0, 16, 1, font_spleen_16x8a, "ježeček");
        ssd1306_show(&disp);
        sleep_ms(2000);


        // kreslení čar
        ssd1306_clear(&disp);

        for(int y=0; y<31; ++y) {
            ssd1306_draw_line(&disp, 0, y, 127, y);
            ssd1306_show(&disp);
            sleep_ms(SLEEPTIME);
            ssd1306_clear(&disp);
        }

        for(int y=0, i=1; y>=0; y+=i) {
            ssd1306_draw_line(&disp, 0, 31-y, 127, 31+y);
            ssd1306_draw_line(&disp, 0, 31+y, 127, 31-y);
            ssd1306_show(&disp);
            sleep_ms(SLEEPTIME);
            ssd1306_clear(&disp);
            if(y==32) i=-1;
        }

        for(int i=0; i<sizeof(words)/sizeof(char *); ++i) {
            ssd1306_draw_string(&disp, 8, 12, 2, words[i]);
            ssd1306_show(&disp);
            sleep_ms(800);
            ssd1306_clear(&disp);
        }

        for(int y=31; y<63; ++y) {
            ssd1306_draw_line(&disp, 0, y, 127, y);
            ssd1306_show(&disp);
            sleep_ms(SLEEPTIME);
            ssd1306_clear(&disp);
        }

        // mapa znaků spleen 8x5
//        for( int i=32; i<255; i++) {
//            ssd1306_clear(&disp);
//            sprintf(buf,"8x5 0x%02x:  ",i);
//            ssd1306_draw_string(&disp,0,0,1,buf);
//            ssd1306_draw_char_with_font(&disp, 60, 0, 2, font_spleen_8x5, (char) i);
//            ssd1306_show(&disp);
//            sleep_ms(800);
//        }
        // mapa znaků spleen 16x8a
        for( int i=1; i<255; i++) {
            ssd1306_clear(&disp);
            ssd1306_draw_string_with_font(&disp,0,0,1, font_spleen_8x5, "Mapa znaků 16x8a");
            sprintf(buf,"znak 0x%02x, %02d: ",i,i);
            ssd1306_draw_string(&disp,0,10,1,buf);
            ssd1306_draw_string_with_font(&disp,0,20,1, font_spleen_8x5, "(zvětšení 2x)");
            ssd1306_draw_char_with_font(&disp, 110, 0, 2, font_spleen_16x8a, (char) i);
            ssd1306_show(&disp);
            sleep_ms(500);
        }

        // kreslení BMP obrázku
        ssd1306_clear(&disp);
        ssd1306_bmp_show_image(&disp, image_data, image_size);
        ssd1306_show(&disp);
        sleep_ms(2000);

        ssd1306_clear(&disp);
        ssd1306_draw_string_with_font(&disp, 0,  0, 1, font_spleen_16x8a, "PMP na SŠPVC");
        ssd1306_draw_string_with_font(&disp, 0, 16, 1, font_spleen_16x8a, "Dobruška");
        ssd1306_show(&disp);
        sleep_ms(4000);

        // létací čára
        for(int i=0; i<10; i++) {
            ssd1306_clear(&disp);
            for(int x=0; x<128; x++) {
                ssd1306_draw_line(&disp, x, 0, x, 31);
                ssd1306_show(&disp);
                sleep_ms(11-i);
            }
        }
        ssd1306_clear(&disp);

    }
}
Výsledky testování
Video jsem musel otočit pomocí příkazu
ffmpeg -i VID_20240127_003457.mp4 -vf "transpose=2" -acodec copy vysledky_testu.mp4
CmakeLists.txt
cmake_minimum_required(VERSION 3.13)

# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(ssd1306-example)

set(CMAKE_C_STANDARD 11)

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# rest of your project

add_executable(ssd1306-example
	example2.c ssd1306.c
)

target_include_directories(ssd1306-example
    PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/../
)

target_link_libraries(ssd1306-example pico_stdlib hardware_i2c)

pico_enable_stdio_usb(ssd1306-example 1)
pico_enable_stdio_uart(ssd1306-example 0)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(ssd1306-example)

Knihovnu včetně fontů můžete používat ve svých projektech.

Přeložený příklad z videa ssd1306_example.uf2

Zdroje a odkazy