|
1 |
| -[](https://github.com/ThingPulse/esp8266-oled-ssd1306/actions) |
2 |
| - |
3 | 1 | # ThingPulse OLED SSD1306 (ESP8266/ESP32/Mbed-OS)
|
4 | 2 |
|
5 |
| -This is a driver for SSD1306 128x64, 128x32, 64x48 and 64x32 OLED displays running on the Arduino/ESP8266 & ESP32 and mbed-os platforms. |
| 3 | +[](https://registry.platformio.org/libraries/thingpulse/ESP8266%20and%20ESP32%20OLED%20driver%20for%20SSD1306%20displays) |
| 4 | +[](https://github.com/ThingPulse/esp8266-oled-ssd1306/actions) |
| 5 | + |
| 6 | +This is a driver for SSD1306 and SH1106 128x64, 128x32, 64x48 and 64x32 OLED displays running on the Arduino/ESP8266 & ESP32 and mbed-os platforms. |
6 | 7 | Can be used with either the I2C or SPI version of the display.
|
7 | 8 |
|
8 | 9 | This library drives the OLED display included in the [ThingPulse IoT starter kit](https://thingpulse.com/product/esp8266-iot-electronics-starter-kit-weatherstation-planespotter-worldclock/) aka classic kit aka weather station kit.
|
@@ -261,6 +262,27 @@ void setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment);
|
261 | 262 | void setFont(const uint8_t* fontData);
|
262 | 263 | ```
|
263 | 264 |
|
| 265 | +## Arduino `Print` functionality |
| 266 | +
|
| 267 | +Because this class has been "derived" from Arduino's `Print` class, you can use the functions it provides. In plain language, this means that you can use `print`, `println` and `printf` to the display. Internally, a buffer holds the text that was printed to the display previously (that would still fit on the display) and every time you print something, this buffer is put on the screen, using the functions from the previous section. |
| 268 | +
|
| 269 | +What that means is that printing using `print` and "manually" putting things on the display are somewhat mutually exclusive: as soon as you print, everything that was on the display already is gone and only what you put there before with `print`, `println` or `printf` remains. Still, using `print` is a very simple way to put something on the display quickly. |
| 270 | +
|
| 271 | +One extra function is provided: `cls()` |
| 272 | +```cpp |
| 273 | +// cls() will clear the display immediately and empty the logBuffer, meaning |
| 274 | +// the next print statement will print at the top of the display again. |
| 275 | +// cls() should not be confused with clear(), which only clears the internal |
| 276 | +// graphics buffer, which can then be shown on the display with display(). |
| 277 | +void cls(); |
| 278 | +
|
| 279 | +> _Note that printing to the display, contrary to what you might expect, does not wrap your lines, so everything on a line that doesn't fit on the screen is cut off._ |
| 280 | +``` |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | +<hr> |
| 285 | + |
264 | 286 | ## Ui Library (OLEDDisplayUi)
|
265 | 287 |
|
266 | 288 | The Ui Library is used to provide a basic set of user interface elements called `Frames` and `Overlays`. A `Frame` is used to provide
|
@@ -401,6 +423,33 @@ OLEDDisplayUiState* getUiState();
|
401 | 423 | int8_t update();
|
402 | 424 | ```
|
403 | 425 |
|
| 426 | +## Creating and using XBM bitmaps |
| 427 | +
|
| 428 | +If you want to display your own images with this library, the best way to do this is using a bitmap. |
| 429 | +
|
| 430 | +There are two options to convert an image to a compatible bitmap: |
| 431 | +1. **Using Gimp.** |
| 432 | + In this case exporting the bitmap in an 1-bit XBM format is sufficient. |
| 433 | +2. **Using a converter website.** |
| 434 | + You could also use online converter services like e.g. [https://javl.github.io/image2cpp/](https://javl.github.io/image2cpp/). The uploaded image should have the same dimension as the screen (e.g. 128x64). The following output settings should be set: |
| 435 | + - Draw Mode: Horizontal - 1 bit per pixel |
| 436 | + - Swap bits in byte: swap checkbox should be checked. |
| 437 | +
|
| 438 | +The resulting bitmap can be put into a header file: |
| 439 | +```C++ |
| 440 | +const unsigned char epd_example [] PROGMEM = { |
| 441 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ... |
| 442 | + ... |
| 443 | +}; |
| 444 | +``` |
| 445 | + |
| 446 | +Subsequently, it can be used like this: |
| 447 | +```C++ |
| 448 | +display.clear(); |
| 449 | +display.drawXbm(0, 0, 128, 64, epd_example); // assuming your bitmap is 128x64 |
| 450 | +display.display(); |
| 451 | +``` |
| 452 | + |
404 | 453 | ## Example: SSD1306Demo
|
405 | 454 |
|
406 | 455 | ### Frame 1
|
|
0 commit comments