Raspberry Pi Pico - SSD1306 OLED Micro Python Library and Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's don here from nova spare tech and welcome back to the channel and today i'm going to show you guys how to code a micro python on the raspberry pi pico to display stuff on an oled lcd so let's get started now before i begin this main project is not solely just to get a display working on oled but how easy it is to install libraries using tawny so if you guys are not familiar on how i set up this machine using tawny and everything i do have a couple of other videos which i'll make a playlist right over here for you guys so you can follow along otherwise we have everything all set and we could begin now i am working on bigger projects on the raspberry pi pico like displayed over here which is a media dial i got the code in and everything in under an hour but right now where i'm struggling with is the 3d design so i'm actually learning a brand new program instead of using tinkercad i'm i'm starting to use freecad so it took me a little bit of time to learn that so that video will be coming soon so if you guys are interested in that remember to subscribe and hit that notification bell so you know when that video is going to be out now to begin we are jumping over to my desktop and this is ubuntu 2004 and if you guys are interested in how i set up my desktop i do have a video which i'll link right over here because i know you guys were asking on my previous video and i do have a whole setting on how this works so i'm going to hop over to tawny which is our editor right over here and it is connected to our raspberry pi pico okay so here we go the first thing we need to do is actually pop over to tools and go to manage packages and as you can see on my raspberry pi pico i already have the module ssd1306 installed but what you could do in here is just type it in ssd130c search and you will actually find the adafruit circuit python or or the micropython version and the version that i'm actually using is the micropython ssd1306 version if i'm using circuit python i will actually be using the circuit python version so that's what i have installed once you click on that you could just hit install and it will install this library into your raspberry pi now that we got the library installed onto our raspberry pi you could actually verify that by going into view files and if you go into lib you will actually see that in there already okay so now i'm actually going to bring this getting started up because we are going to need to know pins are going to be used for and i just loaded up the image so i'm always in reference to this let me make this a little bit smaller so we could just do that okay and on our micro python we do have to import i squared c so from machine import pin and i i squared c okay next we're going to do from ssd1306 import ssd1306 underscore i2c okay and then we're also going to import frame buffer because we are actually going to try to load images into our oled so we're also going to do frame buff like that okay now that we have the libraries that we need imported we are we need to set up our variables so with equals uh in my case i'm using a 128 by 64. so height 64. now we have to declare the i squared c so i'm going to make a variable called i2c you see how it's lower case i'll reference that in a bit but i to c in the upper case and we are going to put in zero okay zero is basically for this you see how there's i two i squared c 1 i squared c 0 r squared c 1 and so forth and so forth we're going to be using i squared c 0 so that's why we will put the 0 here now if we are going to be using default parameters we could just put the 0 like this and it will actually load pin gp8 and gp9 these are the two default pins if you don't declare anything but because on the pico you actually have all these i2 square locations that you could use i'm going to show you guys how to declare it on a different area this way we don't have to use the default values okay so from here we would do scl equals pin 17 and sel stands for clock and this is gp 17 which is right here this is the clock scl and now we have to declare the data line so sda which is the data line you can see from cl and da that's what it is we are going to use 16 and that's the pin right over here i'm using this section of the board because that's how it wires up a little bit easier but i'm going to be using gp17 and gp16 basically for our data and also for our clock oh i forgot to put pin here so pin 16. and last setting that we have to put is the frequency and we are going to be using 200 kilohertz um you could go up to 400 kilohertz which is in fast mode and that's a speed of the data transfer rates at uh slow mode or normal mode would be 100 i'm just like right in between there so i decided to use 400 and in default if you don't set anything up default is 400 uh kilohertz so now that we have that all set up we're going to set up our oled and in here we're going to do ssd1306 i squared c which is the thing that we imported up here and we're going to set up the width which is something we declared earlier 128 and then the height which is also something we declared earlier and the i square ski bus that we're going to be using so everything's all declared everything's all set up now we can start inputting the data into our oli display now to start off we're going to fill in some text so we're going to do oled dot fill equals zero well not zero parenthesis zero the reason why we do this is we clear out whatever it is on there right now and then we could type in whatever we want so in this case we're gonna do oled text and we're gonna type hello world and the location of where it's going to be which in our case we're just going to leave it on top left which is zero zero and this is in direct coordination with the width we're just going to put put it on zero zero so it'll be on the top left and then now we could do oled dot show and we are done what we could do now is save to our main and we are going to play oops i made a typo here and here because it's supposed to be lowercase pin because that's how i wrote it up here save again and we're going to hit play and there we have it now as far as the wire up goes i would highly recommend getting like a set of these these are basically pre-length and straight wires and that's what i'm using right over here and so i got the power going well the ground going over here then the power going on to this rail then as you can see there's vcc and ground so power would go there ground would go here and then there's the scl and the sca sda and i just popped it onto the coordinating pins which we adjusted to pin 17 and 16 over here and that's how come i adjusted it this way because when i put the screen on it's a little bit easier to run the wire so here there we have it we have hello world working and if it looks a little bit different on my gopro because the frequency of the gopro is a lot faster that's how i'm just seeing some weird highlights but in all other cases it does work so now that we have this what can what else can we do how do we display images if we wanted to on this guy so let's pop back over to my desktop and i'll show you now that we don't need this uh little screen anymore because we already got the wiring all correct first thing that we need to do is actually download a software i just wrote which allows us to convert images to bit array so we're going to open up firefox github.com nova spirit and then here i did img2 byte array i believe a bit alright yeah byte array and here i wrote a little tiny code a couple of days ago on how to convert it and this program is super easy to use the only reason why i wrote something is like this because when i was searching for how to do this it's either in c code or you could do an online converter there's a manual way to do it and i just simplified the manual way which i wrote a little code in python 4. so i'm going to grab this open up a terminal and download that little piece of software so i'm going to head over to download git clone and we'll download my little program right over here so now popping into there i do have this and we could run this really easily by doing python 3 img bit array now i do have a little help here that says how to use it which is please specify the location of the image and this is how you use it the program itself the image the width and the height so this will actually rescale the saw on the image that you have and also convert it into a bitmare let me grab a logo of mine there we go i just pasted my logo let me rename this so it's easier logo and it's a black and white picture that i already have you don't have to use a black and white picture because i it will convert it to grayscale or black and white so i'm just using it because i already have one now what we do is python 3 type in our little thing over here and then we'll type in our logo image and the width and the height in my case it's 64 64 because it's squared like that and there we have it once i hit enter it actually converts everything that we need and i just have to copy this little bit of code copy and now we can go back into our code and add it in so we're going to call this buffer and in buffer we're going to tell it it's byte array and we are going to paste what we just wrote and at the end we're going to close the quote okay i already made it so it has the b in the front and all this other stuff so all you have to do is literally copy and paste from that so now that we got a buffer this is basically our image how will we display it so that's where frame buffer comes into play we're going to create a variable called fb and that's going to equal frame buff dot frame buffer and the buffer that we're going to load which we called buffer the size of it 64 64 and the type or the color you could say so it's going to be frame buff dot mono h l s b okay and that basically signifies that the frame buffer is now loaded this byte array into its memory and it is monochrome and it's 64 by 64. now the next thing we need to do is actually fill our display with it so anything after zero fill we could start typing in our stuff like over here so what we want to do is we want to bleed it so o l e d dot blitz and blit means to transfer the byte array data from the frame buffer memory directly to our oled in this case that's what we're doing shifting the memory over to our oled so we're going to grab that from fb and the location we're going to start it off from because my screen is 128 and the image is 64 by 64. if we want to center it which means we have to do some math so basically 128 divided by 2 is 64 minus 32 so it's going to be 32 and we want zero and once we do that we actually don't need the text anymore so we can now save it and it should just show up our logo and there we have it our logo is showing and that's the image now if you want to get fancy with this you could put it into a while loop and make multiple buffer arrays and play a motion picture or like image or video or something like that you could actually do that in this sense and i've seen people do it already that is it on how to get your oled display not only text but also how to display images if you guys have any questions about this you guys could hit it down in the comments below if you guys are new to this channel consider subscribing also hitting that bell notification icon so you know when the next video is going to be out and as i say my nerd cave hack till it hurts
Info
Channel: Novaspirit Tech
Views: 66,344
Rating: undefined out of 5
Keywords: novaspirit, tech, pico micropython, raspberry pi pico, micropython, rshell, thonny, raspberry pi, pico, circuitpython, raspberry pi pico micropython, raspberry pi pico projects, pico projects, rpi pico, micropython for raspberry pi pico, micropython for raspberry pi, circuit python, python, usb hid, usb_hid, oled, oled ssd1306 pico, oled ssd1306, ssd1306, ssd1106
Id: YR9v04qzJ5E
Channel Id: undefined
Length: 12min 59sec (779 seconds)
Published: Tue Feb 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.