- Name : SSD1306_OLED_RPI
- Description :
- Library to support the I2C OLED Display Module driven by the SSD1306 controller for the Raspberry PI PICO rp2040
- Invert color, rotate, sleep, scroll and contrast control.
- 10 fonts included, fonts can easily be added or removed.
- Graphics class included.
- Bitmaps supported.
- Can support both I2C ports. IC20 or IC21 selected by user.
- Tested on 128X64 & 128X32 display size. Should work for 96X16 display size.
- Polymorphic print class included to print many data types.
-
Author: Gavin Lyons
-
Developed on Toolchain:
- Raspberry pi PICO RP2040
- SDK(1.4.0) C++20
- compiler G++ for arm-none-eabi((15:10.3-2021.07-4)
- CMAKE(VERSION 3.18) , VScode(1.84.2)
- Linux Mint 22.1
There are 9 example files included. User picks the one they want by editing the CMakeLists.txt :: add_executable(${PROJECT_NAME} section. Comment in one path and one path only.
Filename | File Function | Screen Size |
---|---|---|
HELLO | Basic use case | 128x64 |
HELLO_128_32 | Basic use case | 128x32 |
BITMAP | Shows use of bitmaps | 128x64 |
CLOCK_DEMO | A basic clock Demo | 128x64 |
FUNCTIONS | Test OLED functionality: scroll, rotate etc | 128x64 |
SPEED_TEST | Frame rate per second test | 128x64 |
TEXT | Tests Text & fonts | 128x64 |
GRAPHICS | Tests graphics | 128x64 |
I2C_TEST | I2C interface testing | 128x64 |
The API (application programming interface) documentation is at link hosted on github pages and generated by Doxygen software. Lots of information on the software.
Hardware I2C.
-
I2C Address is set by default to 0x3C(your module could be different, user can change argument passed into "OLEDbegin" method).
-
Can support both I2C ports. IC20 or IC21 selected by user.
-
I2C Clock rate can be a passed into in the "OLEDbegin" method as a argument in Kilo hertz.
Frame rate per second example file results | I2C clock rate KiloHetrz |
---|---|
5 | 100 |
12 | 400 |
- The user must also specify the data and clk lines which are linked to the interface used
In all the examples the I2C is set up for :: Address 0x3C , Interface I2C1 , Clock speed 100Khz, Data pin GPIO 18, Clock pin GPIO 19 .
There are 10 fonts packaged with library. Fonts can be easily added or removed by user. All the Font data is in file SSD1306_OLED_font.cpp and SSD1306_OLED_font.hpp
Font data table:
num | Font pointer name | character size XxY | ASCII range | Size in bytes |
---|---|---|---|---|
1 | pFontDefault | 6x8 | 0 - 0xFE, Full Extended | 1534 |
2 | pFontWide | 9x8 | 0x20 - 0x5A, NO lowercase letters | 535 |
3 | pFontPico | 4x6 | 0x20 - 0x7E | 289 |
4 | pFontSinclairS | 8x8 | 0x20 - 0x7E | 764 |
5 | pFontMega | 16x16 | 0x20 - 0x7E | 3044 |
6 | pFontArialBold | 16x16 | 0x20 - 0x7E | 3044 |
7 | pFontHallfetica | 16x16 | 0x20 - 0x7E | 3044 |
8 | pFontArialRound | 16x24 | 0x20 - 0x7E | 4564 |
9 | pFontGroTesk | 16x32 | 0x20 - 0x7A | 5828 |
10 | pFontSixteenSeg | 32x48 | 0x2D-0x3A , 0-10 : . / - only | 2692 |
Font size in bytes = ((X * (Y/8)) * numberOfCharacters) + (4*ControlByte)
Font class Function | Notes |
---|---|
writeChar | draws single character |
writeCharString | draws character array |
Polymorphic print class which will print out many data types |
These methods return an error code in event of an error.
Remove a font
To remove an unwanted font from project simply comment out or delete.
- The Font data in SSD1306_OLED_font.cpp file
- The span to font at middle of SSD1306_OLED_font.cpp file
- The associated extern declaration in the SSD1306_OLED_font.hpp file
Adding a new font
- Add the Font data in SSD1306_OLED_font.cpp file
- Add a span to font at bottom of SSD1306_OLED_font.cpp file
- Add an associated extern declaration in the SSD1306_OLED_font.hpp file
The new ASCII font must have following font structure. First 4 bytes are control bytes followed by vertically addressed font data.
// An 4 by 8 character size font starting at
// ASCII offset 0x30 in ASCII table with 0x02 characters in font.
// 0 and 1
static const std::array<uint8_t, 12>FontBinaryExample[] =
{
0x04, 0x08, 0x30, 0x02, // x-size, y-size, offset, total characters
(data),(data),(data),(data) // font data '0'
(data),(data),(data),(data) // font data '1'
}
Some of the fonts packaged with library came from URL.
OLEDBitmap function will return an error code in event of an error. A horizontal addressed Bitmap's width MUST be divisible by 8. eg, for a bitmap with width=88 and height=48. Bitmap excepted size = (88/8) * 48 = 528 bytes.
Bitmaps can be turned to data here at link See example file "_BITMAP" for more details.