Rotary Display Menu for Raspberry Pi Pico in MicroPython

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey robot makers do you want to add a display and the rotary encoder to your projects to create a rotary menu display then watch this video so what we want to create is a little menu system turning the encoder left and right we'll move the display selector up and down the list and if we press the button it will select the program that we've currently got listed and then run that program so let's take a look at what we need so obviously a raspberry pi pico a rotary encoder i'm using the ssd 1306 ole display um you can use other displays this is just the one i'm familiar with couple of dupont cables and i'm using two breadboards there just to hold everything in place so wiring up is quite straightforward the display uses i squared c so we just need to wire up the ground the voltage the data from the clock to the raspberry pi pico and the data is on pin zero the clock is on pin one and the voltage goes to the 3.3 voltage out on the pico and then for the rotary encoder it's the button pin the direction step and there is two grounds as well so they're going to pin 16 17 18 and the ground that's in between those so let's have a look how this display is going to work so the display itself is made up of 64 pixels by 128 pixels wide and that means that if the line height of the text is about 10 pixels we've got about six lines to play with the total number of lines there is a variable we're going to store six in that and that can change if we have a different size display the width is 128 the height is 64. and then the line height is the 10 pixels per line so next up there's a rectangle function that we can use within the frame buffer function and it starts at the top left with zero zeros the x and y and then there's two other parameters we need width and the height and then finally the color which on our cases are the black or white zero or one and we're going to use that filled rectangle to actually highlight the line that is the current selection so on this presentation here you can see line one is the currently selected item that's got the highlight and it has a little chevron little arrow next to it as well so the variables that we've looked at before we've also got the highlight which is set to one and that's line number one so it's going to be one of six lines in our case so next up if we were to display more than six items on our list what we need to do is kind of have a window that we can move around i'm calling the the thing that's going to point to the top of that window is going to be our shift and it's the shift from the very top of the list and the entire list itself is called the menu the currently selected list is called the shortlist and what we're going to do is just adjust what is in the short list based on the shift value so it's quite a simple function that we can create to do that so if we want to get a list of files that are currently on our raspberry pi p code we can use the os list directory function that will return a list of all the files in the current working directory which is the root by default and we want to just filter out anything that's just a python file so that's actually very simple to do we can just grab that files list from the os list directory and then for each file in that files list because it's a dictionary we can say if that file ends with dot pi you can then append that to another dictionary that we're calling menu and that menu will be the full list of all the files that we want to be able to run from our menu system so how do we actually run a python file well this is quite simple as well we just use the exact function so if we say exec open file name dot read it will actually open up that file and then execute the contents of that file once it's finished executing the contents of that file it will actually return back to the calling function that's going to be our menu once we've launched something it'll run that program and if that program hasn't got kind of an infinite loop in it it will return back to our menu system so that's quite a useful way of being able to manage which programs we want to run so previously on another video we looked at the ssd 1306 display we're actually going to pinch that entire code and just load it into visual studio and then we're going to load that onto the raspberry pi pico as well so it's got that as a library function it can call and we're also going to take the code that we built for the rotary encoder so over on my desk there i've got a number of files actually loaded onto this raspberry pi pico we've got test files one to five there is the library file for the ssd 1306 and there is also the rotary encoder program itself so as i turn this knob let me just uh get there we should be able to see that the menu item there moves down and if i click on one of these if i select test one and i press the button we can see there it says launching test one and test one simply just displays the text test one so we can see that that's worked and then we can also see that it's just returned back to the menu program so if i scroll further down watch the very top item there which is rotary display.pi that's going to scroll off the top as i scroll to the very next item on the list there so i'm now on test five and then as i scroll back up i'm turning the menu item back there we shall see that we then get that rotary.pie back on the top list there so if you enjoyed this video why not consider subscribing to the channel you can also give me a like if you like the video you can comment that also helps with the algorithm and if you hit the bell you get notified next time i do a video you can also check out smartphone.com which is a website that i host uh full of tutorials about small robots uh there's guides there's code there is videos and there's a smart learning platform as well which shows you how to get started with python how to get started with robotic and there's two tutorials on how to build robots and how to build the quad robot as well [Music] i do go live every sunday at 7 00 p.m british summer time or grenache mean time whichever we're currently in the uk and the different time zones are displayed on the screen there so the americas and canada on the left we have the european zone in the middle and we have uh china and australia on the hand side if you want to help out the channel you can always go to buy me a coffee dot com slash kevin mcclaire and buy me a coffee which will help pay for putting this show together and keep it running for another year i do have three levels of membership that you might be interested in there is a bronze silver and gold and you can choose which suits you best there if you want to help support the show so i hope you found this video really useful and you can create your own little menu displays now with the rotary encoder and add them to your robots a self-populating menu depending on which programs you've got available on your rugby pie pico so see you next time
Info
Channel: Kevin McAleer
Views: 15,756
Rating: undefined out of 5
Keywords: Rotary Encoder Menu lcd, Rotary, Menu, Display, SSD1306, Raspberry Pi Pico, MicroPython, Pico, Kevin McAleer, Small Robots, raspberry pi pico projects, raspberry pi pico programming, raspberry pi pico micropython, raspberry pi pico display, raspberry pi pico tutorial
Id: kgjmw6SsKMc
Channel Id: undefined
Length: 6min 8sec (368 seconds)
Published: Sat May 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.