Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:stm32:emb7_1 [2024/04/20 16:45] ktokarzen: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 in STM32WB55 =====+====== 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 <Arduino.h> #include <Arduino.h>
 #include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
 #include <Adafruit_SSD1351.h> #include <Adafruit_SSD1351.h>
-#include <SPI.h> + 
-//Fonts+// Fonts
 #include <Fonts/FreeMono9pt7b.h> #include <Fonts/FreeMono9pt7b.h>
 +
 +// Here you can also include the file with the picture
 +#include "epd_bitmap_logo64.cpp"
 </code> </code>
  
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 OLED_SPI_MOSI_PIN 15  //DIN +#define SCLK_PIN     D13 // It also works with STM numbering style PB_13 
-#define OLED_SPI_SCLK_PIN 18  //CLK +#define MOSI_PIN     D11 // It also works with STM numbering style PB_15 
-#define OLED_SPI_CS_PIN 11  +#define MISO_PIN     D12 // It also works with STM numbering style PB_14 
-#define OLED_SPI_DC_PIN 13 +#define OLED_DC_PIN  D4 
-#define OLED_SPI_RST_PIN 12 +#define OLED_CS_PIN  D2  // Doesn't work with STM numbering style 
-#define SCREEN_WIDTH 128 +#define OLED_RST_PIN D10 //
-#define SCREEN_HEIGHT 128+
  
-// Color definitions +// Colours definitions 
-#define BLACK           0x0000 +#define BLACK         0x0000 
-#define BLUE            0x001F +#define BLUE          0x001F 
-#define RED             0xF800 +#define RED           0xF800 
-#define GREEN           0x07E0 +#define GREEN         0x07E0 
-#define CYAN            0x07FF +#define CYAN          0x07FF 
-#define MAGENTA         0xF81F +#define MAGENTA       0xF81F 
-#define YELLOW          0xFFE0   +#define YELLOW        0xFFE0   
-#define WHITE           0xFFFF+#define WHITE         0xFFFF 
 + 
 +// Screen dimensions 
 +#define SCREEN_WIDTH  128 
 +#define SCREEN_HEIGHT 128
 </code> </code>
  
 === 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 oled = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPIOLED_CS_PINOLED_DC_PINOLED_RST_PIN);
-static Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &hspiOLED_SPI_CS_PINOLED_SPI_DC_PINOLED_SPI_RST_PIN);+
 </code> </code>
  
 === Step 4 === === Step 4 ===
-Initialise the SPI communication object and the OLED controller object. Then clear the screen (write all black):+Initialise the OLED controller object. Then clear the screen (write all black):
 <code c> <code c>
-   pinMode(OLED_SPI_CS_PIN, OUTPUT); +  pinMode(OLED_CS_PIN, OUTPUT); 
-   hspi.begin(OLED_SPI_SCLK_PIN-1, OLED_SPI_MOSI_PIN, -1); +  pinMode(OLED_RST_PINOUTPUT); 
-   delay(50); +  oled.begin(); 
-   digitalWrite(OLED_SPI_CS_PIN,LOW); +  oled.fillRect(0, 0, 128, 128, BLACK);
-   tft.begin(); +
-   delay(100); +
-   tft.fillScreen(BLACK);+
 </code> </code>
  
 === Step 5 === === Step 5 ===
-Draw a bitmap around the centre part of the screen (screen is 128x128px); please mind that ''OLED_SPI_CS_PIN'' must be ''LOW'' (OLED SPI device controller selected) before executing the following code:+Draw a bitmap in the left top corner of the screen (screen is 128x128px). The OLED library handles the ''OLED_CS_PIN'' automatically.
 <code c> <code c>
-  tft.drawRGBBitmap(48,48epd_bitmap_logo_606060);+  oled.drawRGBBitmap(0,0epd_bitmap_logo646464);
 </code> </code>
 === 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>
-  tft.setFont(&FreeMono9pt7b); +  oled.setFont(&FreeMono9pt7b); 
-  tft.setTextSize(1); +  oled.setTextSize(1); 
-  tft.setTextColor(WHITE); +  oled.setTextColor(WHITE); 
-  tft.setCursor(0,10); +  oled.setCursor(10,80); 
-  tft.println("Hello IoT");+  oled.println("Hello IoT");
 </code> </code>
 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 "chip select" GPIO down to LOW before drawing. Follow the code example in this manual: it does work!+**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 carefully the code example in this manual: it does work!
  
  
en/iot-open/practical/hardware/sut/stm32/emb7_1.1713631508.txt.gz · Last modified: 2024/04/20 16:45 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0