This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb7_1 [2024/04/20 16:45] – 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. | ||
Line 55: | 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 118: | 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 194: | 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 |