Using ESP32 With LCD ILI9341, TOUCH XPT2046 & SPI SD Card

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i've got in the sp 32 here but this video is about using the csp32 with this lcd touch screen and sd card interface so i'm going to go over the features of the things which i've programmed and have on this display here and then i'll go over an overview of how i've constructed my application and i'm going to use it as a template for future applications as well and at the end of the video i'll show you some of the key parts of the software which you use to actually interface with the lcd display touchscreen and sd card off of one spi port so the application i've got here that i've written uh just as a template and there's still plenty i need to do before the template's complete but i've got a display where i've got some icons for an application and if i press one of the icons it goes into uh the feature that that icon would represent but here i've just got um just for testing my drawing circles and squares and lines and within a window and making sure that the clipping works around the window so that was just really a test screen at the minute uh and also what something i've got to do is compress the image files on the sd card because reading from the sd card over spi isn't particularly fast so i'm going to need to compress because i'm just storing bitmap files and i really need to compress them to speed up the reading back of them off the sd card so another display i've done is the system information uh this is a great thing about the sp32 is that it has performance monitoring built into it uh and there's lots of great example code which comes with the ide and i've used quite a bit of the uh example example coding some of the coding that i've been doing uh and this task manager um task monitor is one of the pieces of example code which i've taken from the examples and it shows that actually most so i've got two cores on the sp 32 and it's mostly uh idle and to to actually um measure every second the uh performance of the tasks and display them on the sd on the s on the lcd display only takes up about two percent of a second uh to actually do that uh and the reason for that i think mainly is because although it's a reflection refreshing the whole display here it actually does it over gma so the cpu doesn't actually do much to the uh displaying of the um of the communication of the spi and to the lcd display which is the slowest part so all it does is it prepares the data says to the dma controller okay send this data to across the spi to the display and so the cpu doesn't do that it's the dma that does that and it helps a lot and that's one of the fantastic things about the esp32 the more i use it the more i see how fantastic this device is and then if i go back again to the icon display i've just got one more icon which i've programmed at the minute and that's info so i'm just displaying information about the application the idf version of the sp 32 development environment i'm using and information taken from all in functions within the id to test what kind of especially it i've got and it's got two cores it's a rev one with wi-fi bluetooth from bl bluetooth flow in energy i've got four megabytes of external flash and last time it was reset it was on a power on so to go for an overview of the way the system is currently set up to work so you've got the esp32 dev kit there and when it boots up uh it starts the main thread of execution as usual like the function main and function main just starts off a series of four other threads of execution which are required in the application uh and then the the the main up the main application then terminates and uh the main thread of execution uh no longer exists and you're just left with the four threads of execution down here and then one of the really good things about a friatos which come which is integrated within the ide or the idf sorry um is that you can actually pin threads to cores of the esp32 so i've pinned three of my threads here to call one and then my application thread i've dedicated to chord two i've done that deliberately because the application that i'm gonna be working on i want to make sure that that gets interrupted as little as possible and has as little chance of failing as possible so therefore if i call the user interface stub on call one and just the application stuff on court two and i'm very careful how i interact with each other um hopefully that'll reduce the risk of anything untoward happening uh to the main application but as far as my threads go i've got a user thread and all this what this handles is user interactions uh so for example from touch screen when someone touches the screen this has to react to that and perform whatever user interaction is required uh maybe in the future i might add some switches physical switches to the project and this would then have to deal with the physical switches but it handles the gpio stuff which is only user interactions not not any other gpo stuff and then i've got an lcd thread and this is dedicated to updating the lcd display so other parts of the application tell this when it when they want to put something onto the display and then this handles if it's the right moment to put on display and and how it gets put on display i have a monitoring thread this is kind of a debugger monitoring thread um for just just kind of background um stuff to make sure that the application's working okay so even in uh the run runtime environment not just the development environment when i get out into the field there's some things i can diagnose if something doesn't look like it's working properly and then of course the application thread which i've talked about before which is going to be dedicated to just running the application so um when it comes to the hardware so i mean i've got the sd card reader i've got touch screen and the lsd display now they're on the same pcb but they're three separate interfaces uh they each have their own pins for spi so the the lcd display has its spi pins the touch screen has spi pins sd card reader has its own spi pins as well a touch screen also has an interrupt pin in addition the lcd display also has some additional pins such as backlight and command and data as it has been to switch between command and data mode so there's a few additional gpu pins as well but because i'm connecting them all to the same spi port on the sp32 so i'm connecting to the fp4 spi port called hspi so there's an hsbn and a vspi but i just want to tile these to hsbi and then if i ever need another spi port i don't have to worry about this port i can just use the vspi uh and not interrupt any way that this works but in order to get access because um because i've got multiple threads so things have to be thread safe so for example the user thread might want to access the sd card but while that's happening the lcd thread might want to access the display to update the display but they can't communicate at the same time because they'll because they're using the same spi port so what you need is some way of locking it so you created like a virtual lock with this uh free rtos operating system 74 so again another fantastic way that the uh is integrated with um the friatos stuff and what would happen is if the user application the user thread wants to access the sd card it would say to this m4 uh give me a lock so that i can access the uh sd card and the seminar forward might say well actually it's a bit busy in a minute because the lcd uh displays or uh the osd threads already got a lock on it because it's updating the display uh at which point the user thread can either it can request it it can say well if it fails just um let me know and i'll continue doing something else and i'll come back later or i can say if it fails then just wait and when it's got a lock then we'll continue execution so we'll just wait until it gets execution uh gets a lock and then it just um uses the uh port from there on uh and that's the way that access to any any of these devices is achieved so whatever needs to access the device uh has to get locked first and then it can access the device once once the device so once it's got a lock so say the user has a lock on there in order to use the sd card it doesn't have to release that lock if it wants to do something with the display as well although in this case it wouldn't because it's only the lcd thread but if you wanted to access multiple ones of these devices it could do that with the same lock because the lock locks all three items because they're all on the same spi port so if i come down now to the touch screen the touchscreen like i said earlier has an interrupt so when someone touches the the screen it only it'll generate an interrupt then so you don't have to pull the screen you don't have to keep saying the screen is saying you can touch it and there's anyone touching anyone touching you can do a very efficient thing where the screen says okay someone's touched it and what that will do is it will put into a message for the user in a user message queue and this is another feature of uh the free rts um operating system integration is that you can create these cues and you so i've created one for user i've also created one for the lcd so any user interface so if i had um switches here i could or i could generate an interrupt on a switch and then that could send the message to the user queue as well and all that happens with the user queue is um it'll cue up the items of messages uh for the user thread and when the user thread gets time it will say okay what what's the next thing i need to do and ask for the next message and i'll go through the messages which um are queued up foreign will handle what it needs to do for each of those messages and same again for the lcd display so when things have got things to display they'll cue them up in the lcd display queue but this is actually handles it quite well because what happens is it will not put the message in there but within that message it will put a pointer to the data which actually has to be displayed uh so it can show up a bunch of data which needs to be displayed and when the lcd thread gets time it gets to the message and it says okay what do i need to do and if if the data is relevant to what's currently being displayed then you say okay well i'll take that i'll actually put on display but if it's not if it's for some some other display which isn't being displayed then it can say well i don't need this i'll ignore it um and what the thread will do is it will take the data it'll put it on the display and then because the data is no longer acquired the the lcd thread will free up the memory which the data occupied so you don't get any memory leaks and that's the basic overview of how how it currently operates i can go through a few other bits of code to do with the free rtos integration um into the uh into the esp32 stuff so first we'll send you the message so we just construct a variable which you want to send and when you create message queue you tell it how big the variable you're gonna send is uh and then you just call a function like this uh so this one has got from i interrupt service routine uh but you can have it uh without the interrupt service routine um if you're not sending it from inside the truck service routine um you tell it what the queue handle is so you when you create you you get a cue handle back and then you just pass a reference to the uh to the actual message you're sending and that will go into the queue and then you can uh go into a loop which i'll show you up the top here so this is a message leave so in the receiving part we just you do you do a loop um which goes through uh receiving messages from the queue and then each time around the loop you can check what what the message is so in this case a message for a touch event from an interrupt is being detected and then it just so happens i'm using the 74 to lock the spi device because i'm about to access the touch touch device here so um so i power on the lcd the touchpad on the lcd display i get the x y and z um locations of where the touch was and then i power off the touchpad on the lcd display and then i can do whatever i need to do with those coordinates and then at the end you must you've got to make sure that you would um free up the 74 that you took to lock the spi device otherwise nothing else will be able to access it and things will just lock up so after you've used your sbi device free up to 74 and then you can continue like that
Info
Channel: Develop IT
Views: 20,045
Rating: undefined out of 5
Keywords: ESP32, DEVKIT, LCD, ILI9341, Toch Screen, XPT2046, SD Card, IDF, Free RTOS, SPI, RTOS, Threads, Example, Source Code
Id: 8BU07bUQKvg
Channel Id: undefined
Length: 13min 40sec (820 seconds)
Published: Fri Nov 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.