60fps on an SPI display using the Raspberry Pi and fbcp-ili9341 (includes fix for 320x240 ST7789)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another video today I'm going to be showing you how to get an SPI screen at home running at 60 frames a second from a Raspberry Pi so that we can use it with retropie to play games in order to achieve these seemingly impossible frame rates over SPI I'll be using the FBC P - I align 9341 library by Jewess juj and I'm extremely thankful to him not only for having written this library but it's also so well documented before you attempt to do this yourself I strongly recommend reading through the readme file on his github page which I've linked in the description below I'm using a recipe by three plus and one of these cheap wireless controllers along with this two inch TFT from Adafruit now it turns out that using this particular screen made it far more complicated that it needed to be most displays that use the st7 seven eight-nine driver are 240 by 240 resolution but this one is 320 by 240 and so will actually need to make some changes to the FB CPI align 9341 library to make this work if you have any other screen you probably have won't have to make these changes and so you can just skip that part of the video the build options for getting your screen working will differ from mine but hopefully you can get some idea on how to do this I'll begin by assuming that you've set up your set of raspbian or retropie on your SD card and that you can SSH into your PI as we go through this if you have any questions feel free to leave them in the comments below and I'll do my best to get back to you but be warned I'm no expert on this and I'm learning along with you guys anyway let's get going we'll start off by having a look at some of the hardware connections here there are quite a few connections that need to be made most of these are not negotiable so the library actually uses the hardware SPI zero pins on the Raspberry Pi so we've got a clock here master in slave out master out slave in and chip enable or chip select their predefined so you can't actually change those they must go on two pins number 23 21 19 and 24 V in here is just be providing 3.3 volts from one of the pins on the GPIO s here you can ignore this purple connection just here this is simply because I'm using a ribbon cable to connect by TFT to the Raspberry Pi and to save having one hanging on its own out here the V and pin I just left that on the on the ribbon cable but I'm not actually connected it these two pins down here so reset and the data control lines you can change those so here I've put the resets on pin 31 and the data control line on pin 29 and if you're going to move those what you need to do is make sure you look up the Broadcom pin numbers so if you look at her general raspberry pi pin out it will give you the raspberry pi pick numbers sort of like 24 31 29 here but it'll also give you us called the BCM pin numbers so I've got the reset line tight at BCM 6 which is GPIO 31 and the data control line on pin 29 which is the Broadcom pin number 5 and that's going to be important a little bit later on so once you've got that all set up we need to get onward to the software now as I mentioned before at this point you should have your PI setup with the hardware connections made your PI should be running some kind of this beauty distribution whether that's raspbian or in my case I'm actually running retro pipe because I want to make this into a little games console at some point so you to log in via SSH there's plenty of guides on how to set up these various distributions or how to set up SSH so I'm not going to go into that here you can find tutorials online easily to to do that so the first thing you need to do is you need to make sure C make is installed and pretty sure it is on this machine but just to be on the safe side that's sort of out yes you already have the newest version that's that's good next thing we need to do is we need to clone the git repository from the the library they've linked in the description below so if I to do that let's clone it in we're done and then we need to build this software now before we do that I've actually got a bit of a weird TFT screen here so this library isn't set up for some reason to deal with to 320 by 240 panels that run on the esti seven seven eight nine driver chip if yours is in the list if your your panel is in the list of tested devices you can actually skip over the whole of this next bit I'll put a timestamp on the screen at the moment to show you were to go to but if like me you've got the 320 by 240 st 7 7 8 9 TFT device then we'll have to make some edits to the report the repository before we actually build this software so they make there's that it's what we need to do is we need to change the directory into the one thing we just downloaded we need to make some edits to a couple of files here so if we using nano so we need to edit st 7735 r dot h we're going to use a nano to do that and what we need to do is need to scroll down here we to find the line that says display native width and display native height and at the moment that sets a 240 by 240 now due to a weird bug in how this LCD actually works instead of changing the width to 320 which would seem correct we're actually going to change the height to 320 instead now if you haven't used nano before in order to save a file we use control hope to write the file out and then press enter and then we press control X to exit now there's another file we need to change as well so this time we're going to change st 77035 r dot cpp so we load that up and we need to try to find a line it's down here somewhere what we're looking for is this line here where it says SPI transfer 0 X 37 V SC SAT vertical scroll straw Beauvoir now this has been added in this line because most of the LCDs that work on the st 77089 actually only have a 240 by 240 part of the screen that can be used however this one doesn't so we need to change this line here so what i'm going to do just comment out the line and let's let's write it out again say the same as before 0 x and this time we're going to put zero-zero difficut the semicolon to the end of the line just that let's say we have to do this we have to do this because we don't want to shift the display by 80 pixels which is what's actually happening by default so we need to make this change remember all of these changes are only necessary if you have the 320 by 240 version of this panel so should be SPI transfer from brackets 0 X 3 7 comma 0 comma 0 close brackets and semicolon at the end so again ctrl o to write that file out and press ENTER and then ctrl X to exit those of you who have skipped ahead to here welcome back we just made a couple of edits to the files you can see above st7 735 as I say these aren't relevant unless you have this very particular panel now the next thing we need to do is we need to build this software so we're in the right directory at the moment so first we're going to make a directory called build and then we're going to go into that directory and they were actually going to make the software now there are multiple different options we can use so this line seems to have worked fairly well for me I was just trying to explain what each one of these bits means so first of all we are going to build this software so I my TFT is using a 7 7 8 SZ 7 7 8 9 drivers so it's gonna be - TST 7 7 8 9 equals on and then we can put in which lines we've used for our data control and I'll reset pin I remember 5 & 6 here these are the BCM of the Broadcom port numbers not the normal raspberry pi port number so got TFT data control equals 5 and TFT reset pin equals 6 then we need we've got d spi bus clock divisor equals 8 now what this does is this determines how quick how fast the SPI bus can push data to the display when you are doing this for the first time it might be a good idea to start off with this divisor said a bit higher it has to be an even number a safe number to start with is maybe 30 and presuming that works presuming your display responds you can then start to reduce that I found a value of 8 seems to work fairly well with this or well enough with this this display I'm easily getting 60 frames second on anything I need the final thing here is you've got these statistics equals zero now by default again when you build this you actually get a little display on the screen which tells you your frames per second and a few other interesting bits and pieces you might want to not put this part in for now but when you finally build it you probably don't want that display on top of your image so I'm going to switch that off for the moment so let's build that okay we're then gonna make it now there are a couple of other things we need to do here as well and one of them is to change the resolution of the output so by default what will happen is your your IQ my port will probably be outputting something like 1080p of course your CD can't display that so this library will actually downsize it but of course it won't change the aspect ratio as well so what we're going to do is force the output into the display ratio or display settings that our screen can actually take so to do that we're going to go to going to type in sudo nano boot convict xed all we need to do is scroll down here a little bit so this section just here and we're gonna uncomment these lines here now if these lines aren't written exactly as they are here make sure you edit them so I've put in here three twenty two forty and sixty so that's your width your height and your FPS that you're targeting so make sure that's all written as it is there and again like before control o to write out the file and then control X to escape we probably also want to start the SPI driver and every time the Raspberry Pi boots as well so again we get a sudo nano and this time we're going into cetera RC vocal and make sure that before it says exit zero here you've got this line so sudo slash home slash PI slash F PCP - I aligned nine through four one slash build slash bow and don't forget to put this ampersand at the end as well that's a really important thing won't work again once you've done that ctrl o + Enter to write the file out and then ctrl X to exit at this point you're ready to reboot your Raspberry Pi and see if the screen actually works so you can see it's beat it up in to emulation station and retropie just hit so let's select again let's let's play sonic to see if this runs so remember we're trying to get to 60 frames a second here should be absolutely fine sorry about the focus thing here my camera is not amazing this brilliant sir looks pretty smooth let's go into the demo here a second see what that looks like okay so user that's running pretty well there's no graphical artifacts the screen seems to updating relatively quickly however it's not just it's just not Sonic is it without the the tune in the background so let's sort the the sound out to change the sound output from the HDMI to the three-and-a-half millimeter headphone jack quite easy to do there are a few different ways of doing this you type in sudo Raz PI dash config and if we go down to Advanced Options and then to audio we can set it to for 3.5 millimeter headphone jack I'm going to finish and that should now be set to the 3.5 millimeter jack instead of the HTML sound output if your display doesn't work for one reason or another it's not too hard to rebuild the the software so to do that we're going to go into the FPC P directory and we're going to remove the build folder that we made earlier we're then gonna make a little folder again build directory CD into that and then just like before we can use the C maker command again just check the details you've got here so first of all make sure that you've got the right chipset selected so mine runs on s two seven seven eight nine so that's correct make sure your data control and reset pins are correct remember these need to be the BCM pin numbers of the Broadcom pin numbers not the raspberry pi ones if you're having issues with many buddies so sort of works but not quite then make sure you change your o'clock divisor here start with a much higher number thirty forty fifty something along those lines it has to be an even number and try and make that again hopefully this will work like it did before blimp and then and once that's done we can now we can reboot him we can try that again okay let's have another go hopefully with the sound enabled this time [Music] [Music] okay that's much better well hope you enjoyed that video or found it useful if you have any questions so please leave them in the comments below and I'll see you next time [Music]
Info
Channel: Scott Marley
Views: 49,898
Rating: undefined out of 5
Keywords: Raspberry Pi, SPI, TFT, Adafruit, 60fps, 320x240, spi display
Id: KciKqGX8g94
Channel Id: undefined
Length: 14min 44sec (884 seconds)
Published: Thu Jan 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.