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:esp32:emb7_1 [2024/04/05 10:41] – [Steps] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb7_1 [2024/06/29 15:54] (current) – [Prerequisites] pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <todo @pczekalski> | ||
====== EMB7: Using OLED display ===== | ====== EMB7: Using OLED display ===== | ||
This scenario presents how to use the OLED display. 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 following pin configuration: | This scenario presents how to use the OLED display. 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 following pin configuration: | ||
Line 17: | Line 16: | ||
<code ini> | <code ini> | ||
lib_deps = | lib_deps = | ||
- | adafruit/ | + | adafruit/ |
adafruit/ | adafruit/ | ||
</ | </ | ||
Line 72: | Line 71: | ||
Include necessary libraries: | Include necessary libraries: | ||
<code c> | <code c> | ||
- | # | + | # |
- | # | + | #include <Adafruit_GFX.h> |
- | # | + | # |
+ | # | ||
//Fonts | //Fonts | ||
- | #include <Fonts/FreeMonoBold12pt7b.h> | + | #include <Fonts/FreeMono9pt7b.h> |
</ | </ | ||
+ | |||
+ | The code above also includes a font to draw text on the OLED Display. There are many fonts one can use, and a non-exhaustive list is present below (files are located in the '' | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
=== Step 2 === | === Step 2 === | ||
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): | ||
Line 101: | Line 154: | ||
</ | </ | ||
+ | === Step 3 === | ||
+ | Declare an SPI communication and OLED controller objects: | ||
+ | <code c> | ||
+ | static SPIClass hspi(HSPI); | ||
+ | static Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, | ||
+ | </ | ||
+ | |||
+ | === Step 4 === | ||
+ | Initialise the SPI communication object and the OLED controller object. Then clear the screen (write all black): | ||
+ | <code c> | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | === Step 5 === | ||
+ | Draw a bitmap around the centre part of the screen (screen is 128x128px); please mind that '' | ||
+ | <code c> | ||
+ | tft.drawRGBBitmap(48, | ||
+ | </ | ||
+ | === Step 6 === | ||
+ | Drop some additional text on the screen: | ||
+ | <code c> | ||
+ | tft.setFont(& | ||
+ | tft.setTextSize(1); | ||
+ | tft.setTextColor(WHITE); | ||
+ | tft.setCursor(0, | ||
+ | tft.println(" | ||
+ | </ | ||
+ | Some remarks regarding coordinates: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | <note tip>To speed up screen updating and avoid flickering, you may use a trick to clear the afore-written text: instead of clearing the whole or partial screen, write the same text in the same location but in the background colour.</ | ||
+ | |||
+ | <note tip> | ||
+ | |||
+ | Besides the functions presented above, the controller class has several other handy functions (among others): | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
- | === Step n === | ||
- | //Describe activities done in Step n.// | ||
==== Result validation ==== | ==== Result validation ==== | ||
Line 109: | Line 210: | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | This section | + | **The screen |
- | When using the printed version of this manual, please refer to the latest online version of this document | + | |
- | //Provide some FAQs in the following form:\\ | + | |
- | **Question? | + | |
- | // | + | |
+ | <WRAP noprint> | ||
===== Project information ===== | ===== Project information ===== | ||
{{: | {{: | ||
Line 131: | Line 230: | ||
{{: | {{: | ||
</ | </ | ||
- | + | </ | |
- | + |