📜 ⬆️ ⬇️

STM32 Nucleo. We connect TFT LCD based on ILI9341 chip

image
On Habré there are already two publications about the STM32 Nucleo platform and development in the mbed.org environment. This is a “platform overview” and “quick start” . I will tell you in this publication how to quickly connect an inexpensive TFT LCD module based on the ILI9341 chip. The article will be useful and Arduino lovers who want to go to a more modern and powerful microcontrollers, using the already gained knowledge.

You can get acquainted with the prices on the display, for example, on Ebay .
I will use the NUCLEO-F401RE board , you can use any of this line.

So, you have already read the two previous articles, so get down to business right away.

Open our on-line compiler . Create a new program.
')


Let's call it, for example, ili9341_display_test.



We import the official mbed library into our project.



We find and import.



Checking what is imported to our project.



In the same way we import the graphic library for our display.

In the search for "ili9341" we find the library from Peter Drescher.



We also need fonts, importing the same, on request in the search for "TFT_fonts".



Those who want to use any other font or develop their own, there is a program to help GLCD font creator . The program is free, but for correct import you have to shaman, and this is another topic.

Now we will create the main file, which will be our program.



Let's call it main.cpp.



Now we have a project with two libraries, a set of fonts and the main file of the program.
Click the mouse on main.cpp and write and paste our code.



And here is the code.

#include "mbed.h" //   mbed #include "SPI_TFT_ILI9341.h" //      ili9341 #include "Arial28x28.h" //   SPI_TFT_ILI9341 TFT(D11, D12, D13, D8, D9, D10,"TFT"); // (mosi, miso, sck, cs, reset, dc) int main() { TFT.set_orientation(3); //    TFT.background(Blue); //    ( ) TFT.foreground(0xFFFF); //    (   rgb565) TFT.cls(); //     TFT.set_font((unsigned char*) Arial28x28); //    TFT.locate(30, 100); //    (, ) TFT.printf("Hello habrahabr.ru"); //    } 


How to connect the display? Yes, very simple!
Go to the page of our board (I have this ST-Nucleo-F401RE ).
Find a picture of Arduino-compatible Headers.



This is pinout of our board with the pin names so familiar to all Arduino-lovers.
Find the SPI interface pins.
SCK - D13
MISO - D12
MOSI - D11
We also need contacts CS, reset, DC, I used respectively D8, D9, D10.
In our program, this is indicated as a string:

 SPI_TFT_ILI9341 TFT(D11, D12, D13, D8, D9, D10,"TFT"); // (mosi, miso, sck, cs, reset, dc) 

We connect them to the corresponding contacts on our display.
Also, the display must be connected to the power supply.
I used VCC - + 5v (there is a 3.3 volt stabilizer on the display board, if you close it with the provided jumper, you can use 3.3 volts).
GND - GND
LED - backlight, designed for 3.3 volts, so connect to the contact + 3.3v.
The display logic works from 3.3 volts, like our microcontroller, so we will not need to use a logic level converter, as is the case with the arduino uno.

Now you can compile our program. To do this, click the Compile button in the online compiler and save the resulting file directly to our board (when the board is connected, we have “NUCLEO” removable media).
If everything is done correctly, then we will see on the screen the inscription “Hello habrahabr.ru”.

useful links

Here you will find examples of code and usage, this is the official page of the SPI_TFT_ILI9341 library.
Here functions of work with this library, such as construction of lines, squares and other are described.
There is a lot of useful information on mbed.

Have fun!

Source: https://habr.com/ru/post/241409/


All Articles