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:21] – 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 70: | Line 69: | ||
</ | </ | ||
=== Step 1 === | === Step 1 === | ||
- | //Describe activities done in Step 1.// | + | Include necessary libraries: |
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | //Fonts | ||
+ | #include < | ||
+ | </ | ||
+ | |||
+ | 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 | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | === 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): | ||
+ | <code c> | ||
+ | //Test configuration of the SPI | ||
+ | #define OLED_SPI_MOSI_PIN 15 //DIN | ||
+ | #define OLED_SPI_SCLK_PIN 18 //CLK | ||
+ | #define OLED_SPI_CS_PIN 11 | ||
+ | #define OLED_SPI_DC_PIN 13 | ||
+ | #define OLED_SPI_RST_PIN 12 | ||
+ | #define SCREEN_WIDTH 128 | ||
+ | #define SCREEN_HEIGHT 128 | ||
+ | |||
+ | // Color definitions | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | #define CYAN 0x07FF | ||
+ | #define MAGENTA | ||
+ | #define YELLOW | ||
+ | #define WHITE | ||
+ | </ | ||
+ | |||
+ | === 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> | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | tft.begin(); | ||
+ | | ||
+ | | ||
+ | </code> | ||
+ | |||
+ | === 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 81: | 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 103: | Line 230: | ||
{{: | {{: | ||
</ | </ | ||
- | + | </ | |
- | + |