This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb7_1 [2024/04/20 15:06] – created ktokarz | en:iot-open:practical:hardware:sut:stm32:emb7_1 [2024/04/25 19:17] (current) – [STM_7: Using OLED display in STM32WB55] ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== STM_7: Using OLED display | + | ====== STM_7: Using OLED display ===== |
This scenario presents how to use the OLED display connected to the STM32WB55 SoC. Our OLED display is an RGB (16bit colour, 64k colours) 1.5in, 128x128 pixels. The OLED chip is SSD1351, and it is controlled over the SPI interface using the pin configuration as described in STM32 node Hardware Reference in Table 1 STM32WB55 Node Hardware Details. | This scenario presents how to use the OLED display connected to the STM32WB55 SoC. Our OLED display is an RGB (16bit colour, 64k colours) 1.5in, 128x128 pixels. The OLED chip is SSD1351, and it is controlled over the SPI interface using the pin configuration as described in STM32 node Hardware Reference in Table 1 STM32WB55 Node Hardware Details. | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
- | There is no need to program SPI directly; instead, it should be handled by a library | + | There is no need to program |
<code ini> | <code ini> | ||
lib_deps = | lib_deps = | ||
adafruit/ | adafruit/ | ||
+ | adafruit/ | ||
</ | </ | ||
- | Note that the graphics abstraction library (Adafruit GFX) is loaded automatically | + | Note that the graphics abstraction library (Adafruit GFX) can be loaded automatically |
- | <code ini> | + | <code ini> |
- | <code ini> | + | |
- | lib_deps = | + | |
- | adafruit/ | + | |
- | adafruit/ | + | |
- | </ | + | |
===== Suggested Readings and Knowledge Resources ===== | ===== Suggested Readings and Knowledge Resources ===== | ||
Line 39: | Line 35: | ||
Sample project favicon you can use is present in Figure {{ref> | Sample project favicon you can use is present in Figure {{ref> | ||
<figure iotopenfavicon> | <figure iotopenfavicon> | ||
- | {{ : | + | {{ : |
< | < | ||
</ | </ | ||
==== Steps ==== | ==== Steps ==== | ||
Remember to include the source array in the code when drawing an image. | Remember to include the source array in the code when drawing an image. | ||
- | The corresponding generated C array for the logo in Figure {{ref> | + | The corresponding generated C array for the logo in Figure {{ref> |
<code c> | <code c> | ||
- | const uint16_t | + | const uint16_t |
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, | 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, | ||
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf7be, 0xbdd7, 0x8430, 0x5aeb, 0x39c7, 0x2104, 0x1082, 0x0020, 0x0020, 0x1082, | 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf7be, 0xbdd7, 0x8430, 0x5aeb, 0x39c7, 0x2104, 0x1082, 0x0020, 0x0020, 0x1082, | ||
Line 54: | Line 50: | ||
.... | .... | ||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 | ||
- | }; | ||
- | |||
- | // Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 3616) | ||
- | const int epd_bitmap_allArray_LEN = 1; | ||
- | const uint16_t* epd_bitmap_allArray[1] = { | ||
- | epd_bitmap_logo_60 | ||
}; | }; | ||
</ | </ | ||
Line 65: | Line 55: | ||
Include necessary libraries: | Include necessary libraries: | ||
<code c> | <code c> | ||
+ | // Libraries | ||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include < | + | |
- | //Fonts | + | // Fonts |
#include < | #include < | ||
+ | |||
+ | // Here you can also include the file with the picture | ||
+ | #include " | ||
</ | </ | ||
Line 128: | Line 122: | ||
Add declarations for GPIOs, colours (to ease programming and use names instead of hexadecimal values) and screen height and width. To recall, the OLED display in our lab is square: 128x128 pixels, 16k colours (16-bit 565: RRRRRGGGGGGBBBBB colour model): | Add declarations for GPIOs, colours (to ease programming and use names instead of hexadecimal values) and screen height and width. To recall, the OLED display in our lab is square: 128x128 pixels, 16k colours (16-bit 565: RRRRRGGGGGGBBBBB colour model): | ||
<code c> | <code c> | ||
- | //Test configuration of the SPI | + | // Pins definition for OLED |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | #define SCREEN_HEIGHT 128 | + | |
- | // Color definitions | + | // Colours |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | # | + | # |
- | #define CYAN 0x07FF | + | #define CYAN 0x07FF |
- | #define MAGENTA | + | #define MAGENTA |
- | #define YELLOW | + | #define YELLOW |
- | #define WHITE | + | #define WHITE |
+ | |||
+ | // Screen dimensions | ||
+ | #define SCREEN_WIDTH | ||
+ | #define SCREEN_HEIGHT 128 | ||
</ | </ | ||
=== Step 3 === | === Step 3 === | ||
- | Declare an SPI communication and OLED controller objects: | + | Declare an OLED controller objects: |
<code c> | <code c> | ||
- | static SPIClass hspi(HSPI); | + | Adafruit_SSD1351 |
- | static | + | |
</ | </ | ||
=== Step 4 === | === Step 4 === | ||
- | Initialise | + | Initialise the OLED controller object. Then clear the screen (write all black): |
<code c> | <code c> | ||
- | pinMode(OLED_SPI_CS_PIN, OUTPUT); | + | |
- | hspi.begin(OLED_SPI_SCLK_PIN, -1, OLED_SPI_MOSI_PIN, | + | |
- | delay(50); | + | oled.begin(); |
- | | + | oled.fillRect(0, 0, 128, 128, BLACK); |
- | tft.begin(); | + | |
- | delay(100); | + | |
- | tft.fillScreen(BLACK); | + | |
</ | </ | ||
=== Step 5 === | === Step 5 === | ||
- | Draw a bitmap | + | Draw a bitmap |
<code c> | <code c> | ||
- | | + | |
</ | </ | ||
=== Step 6 === | === Step 6 === | ||
- | Drop some additional text on the screen: | + | Write some additional text in the middle of the screen: |
<code c> | <code c> | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
</ | </ | ||
Some remarks regarding coordinates: | Some remarks regarding coordinates: | ||
Line 204: | Line 197: | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | **The screen is black even if I write to it. What to do?**: Check if you have initialised an SPI communication object and pulled | + | **The screen is black even if I write to it. What to do?**: Check if you have done all the steps shown in the example. Check if you used proper GPIOs to control the OLED display. Follow |