Driving 2 screens with the ESP32 (ili9341 driver, tft_espi library)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you've ever wondered how to get two screens doing two different things at once on a microcontroller in this case the sb32 then stick around roll those titles is that it [Music] okay some prerequisites we're using rli9341 driver screens although these are two different sizes they both use the same driver so that's essential we're also using the tft espi library by bodmer now a bit of a caveat with that it was never designed to run two screens saw it's a bit of a clutch what we'll be doing to get this to work but it's not a big clutch i'll hold your hand all the way as long as you've washed it and you'll see that actually the work required is is quite minimal and we're only going to look at the basic wiring for two screens if you want to look in detail about wiring up a single screen and in fact installing the tft espi library then see this video which we'll put a link up somewhere around about here to be a link down below as well i would suggest if you've not got your esp32 wired up to a single screen yet then you do need to do that video get it all working with one screen first and then come back and look at this one the sbi bus is as the name suggests it's a bus why is that are designed to have multiple devices connected to them to exchange information to whatever device deals with that data but you can't have more than one device using the bus at once so the bus master or more more usually the cpu the mpu the micro control that we're using controls which device has access to that bus or listens on that bus at any one time to do this every spi device has a chip select pin or perhaps a more accurate name in this scenario would be device select whichever when this pin is set to law then the device can use the bus if high then it cannot use a bus looking at the diagram when the cpu wants to send data to screen 1 it makes the chip select on io 10 could have been any io but use 10 in this case sets that to low and ensures that i or 11 the select for screen 2 is high we can now send whatever we want to screen 1 and screen 2 will happily ignore it if we want to write screen 2 then we would set pin 11 law and set 10 high etc now with these screens because they only ever passively listen to the bus we could actually send the same data to both screens at once and get them to both display that same data whatever it may be however there is some trouble as i mentioned earlier with the tft esbi library it requires you to set which pin is the chip select pin in a settings header file which if you've watched the other video i'll link to earlier you'll be aware of library will then set and unset this pin as it sees fit when it's right in there to the screen so as much as you might want to use this pin for one of the screens you can't as you need to explicitly control when it is low or high and unfortunately the library will ignore you and set this pin itself no matter what you might want it to be so we still need to tell the library to use a certain pin but we will then ignore this pin or connect it to anything not use it in any way whatsoever and we'll use whatever the pins we want to to use for the chip select so that we control them explicitly generally the default for the library is pin five on an esp32 so we'll leave that as it is this means that pin five cannot be used for anything else whether it's with the screens with another sensor whatever you gotta leave it alone because that library's gonna fiddle with it i've covered connected these screens as i mentioned before in a video and an article linked to my website so i won't go into much detail refer to the circuit diagram and the picture of the breadboard circuit power ground and led backlight are connected as you expect the screen resets are both connected together and go to pin d4 on the sp-32 the dc's are connected together also and go to pin d2 i think i think this stands for data control could be wrong i've not really been bothered to look it up but that seems to make sense it basically tells the screen if the data arriving for it is for the registers to set up various parameters for this display screen or the actual screen display data itself you know for graphics and images and whatever the mossy mosey whatever connection of the sbi bus is the connection that the screen uses to receive data we can tie these together too it is a bus things are designed to be connected together on that same bus and we connect those to d23 the clocks sck are also obviously tied together because it's of us they will be connected together for all screens and and then we'll go to pin d18 so here we are at the most important pins for our task the chip selects of the two screens screen 1 goes to d22 and screen 2 to d21 notice that pin 5 is not connected to anything that we said because it will be used by the library and so we cannot use it for any purpose forget it's there ignore it so by changing pins 21 and 22 we can control which screen our chord and thus the library talks to let's look at some examples so this is a really simple piece chord simple intro where we just write the same data to both screens at once so we can control two screens same data at once so we've been good little boys and girls and we've used variable names for our pin numbers so you can see large screen is set to pin 21 as we mentioned earlier small screen pin 22 in the setup we are setting both 2b output pins for those two because it's the chip select and we're going to control those chip selects so they need to be outputs and then in these next two lines we just send them both floor that's it because we're going to ride to both at the same time we want them both to listen to that data bus we set the rotation so the ori the rotation so the orientation is how we want it we initialize tft remember these are both all these commands are going to be going to both the screens simultaneously and then rather uninspiringly we're out that sentence let's uh have a quick look at that in action we'll bring that up on the screen and uh yeah you'd say it was exciting tonight but there you go if you want to do two screens at once which you might want for some uh some scenario you can basically just tie the chip selects together if you wanted to and just run your normal chord and that would power two screens at once obviously we want to do something a little bit more advanced that and i do two different things on two screens at once and that's what we'll move on to next so in this one we're going to write two different things to each screen initially the start is are set and we're actually enabling both screens here to listen to the on the spi bus so we're going to set both the same rotation and we're going to initialize both screens the same they've both been initializing set up the same with that chord but here by raising the small screen pin chip select high using that one there we're effectively switching it off from the spi bus it's not going to listen anymore so then we do this write the phrase large screen which means at the moment only the large screens chip select is law so that will listen and that screen will print the words our screen on it and we have a small delay and then we lower the chip select for the small screen so that in the small screen is listening but we only want the small screen to listen we don't want the large screen to listen so on the next line we raise its chip selector hi so now only the small screen is listening and we say enter small draw you know produce that screen right that straight string to the screen and in essence that's it that's all you need to do whether it's two screens or several just control the cs lines chip select lines as appropriate make sure you don't use the cs line assigned to be used by the library for anything in our case pin five you can use any as far as i've tested routines in the library and all should be good we'll now move on to the advanced demo now all these demos all these examples have shown are available on my website there's a page dedicated to this video you'll find a link down below to the actual website all the cord is available on there in particular the more advanced demo i'm just going to show you here is available to download via link i'm not listed the source code at all because it is quite lengthy as you can see so due to that i will be going through it here it is rather complicated because it's actually two of the examples that come with the tfts tft sbi library join together so there's like a bowling ball example and a cube that's spinning rotating in space example and i've merged them together so we've got one on one screen one on the other now this was actually relatively complicated not because of anything in particular from what we've done already nothing digresses from the fact it's just a simple switch of the chip select pin it was just the fact that the chord was written with some variables have the same name and little icky things like that oops little icky things like that that i had to just sort out so nothing technical just you know when you're mangling two pieces of cord that were never designed to put together was a problem but in principle it's just the same if you look at the loop here you can see that i call ignore the start right and then right you can see that i call the boiling ball chord then i call the bouncing cube chord once per time around this loop so it's updating those both chords and if we go to this example of the bouncing cube chord here you can see that when i call the bouncing cube call of bouncing cube chord the first thing i do is turn on the large screen and then go down to the end of this chord the last thing i do is turn off that screen so all of that screen is on when we're doing that chord and then at the end of it turns it off and then if we try and find the bouncy ball a quick blind ball there you go same thing i turn on just a small screen and at the end of that chord i will turn off the small screen and then of course it will repeat and we'll go right around again basically writing that chord for whatever it's the rotating cube or the blind ball to its appropriate screen but of course you don't get something for nothing if you think you're going to write a dual screen game maybe a remake of donkey kong game and watch then beware you are now writing twice as much data to the screens so basically half the speed course depending on how you design your chord this might not be a problem careful and clever coding only updating what is strictly necessary can make a tremendous difference but that's for you to discover as you go along hope this has been helpful if it has please consider subscribing supporting the channel in the usual ways that everybody says the links you'll find them all below really appreciate the people that do amazing it's such a big thank you i've also found that new i think it's called super thanks or something i don't know you'll find a clicky link under the video somewhere if you want to use that nobody's use that yet if you feel like doing that thanks very much in advance but as we know for the entire world things are a bit tight with money at the moment so yeah don't worry if you you don't you don't want to just yeah you just look after yourselves i think he's a tough at the moment so anyway so until next time see you later and thanks very much for watching [Music]
Info
Channel: XTronical
Views: 5,550
Rating: undefined out of 5
Keywords:
Id: NUtP28HTYLQ
Channel Id: undefined
Length: 13min 42sec (822 seconds)
Published: Wed Sep 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.