How to use SSD1306 128x64 OLED Display I2C with Arduino code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to Robojax in this video I'm going to  Jews with all the stats of SSD 1306 sixth display   module this is a 128 pixels by 64 pixel module  that you can display text you can display draw   graphics lines triangle rectangular circle and  you can move them how to draw a circle how to   draw a line how to draw a rectangle how to draw a  rectangle and on the text also you can have a text   and also text inside the two triangle so this  is the module as you can see this is the size   this is I to see which means the communication  protocol that this money is using only to wire   here so we have four connections here on the  back side there are some components that you   can see and view them so let me just connect  it here so we have four connections here so   VCC and ground so these already connected this  can work up to 5 volts to 3.3 to 5 volts that's   also fine we have SCL and SDA this is CLA the  clock and then this is a data and then the SCL   will be connected to a5 and SDA the data will be  connected to a 4 SDA the connection here so VCC   ground SDA and SCL the second one is clock goes  up and 5 and that the data goes to 4 the yellow   and then VCC goes to 5 volts I have connected  it now to 3.3 volts and then it can go to the   ground in both cases this will work now let's  have a look at the code so the library will be   provided on our website Robojax.com/learn/arduino  also the link will be provided to this page as   good app so once you landed in this page just  click on download click download and get it I'm saving it in my download and Arduino  so existing doesn't matter so go to the   where you download it this is I have downloaded  right click go to 7:57 zippy is a free software   you can get it from 7-zip dot org website and  then select extract here once you do that you   will have a folder like this Adafruit SSD one  3:06 master then we need to copy this into our   Arduino libraries right click copy it and then  go to wherever you have our wieners installed   in some cases you might be looking at here  Program Files or wherever you have that so   once you go to the installs folder in my case  it's here and so you will see something like   this this is a program that you run the dot exe  and then look at the library and somewhere here   right-click and then paste it once you paste you  will see it here this is done now we can go now   we can go and open our arduino ide file example  and then other fruit fft one three zero six and   here we select 64 128 by 64 I to see this is  the board that I use because the type is now   this is I to see not spi so I can delete that it  will work but I’m going to leave it for now this   is a wire that does the i2c connection heather  so these are all included you need that this   is for the drawing and other stuff from Adafruit  and this is the main library that does the tasks   of drawing writing texts and all those so these  are the values that you do not play with you do   not touch it I'm not gonna waste time on those  you do not touch this and then here is a value   that you need to change for this module that I'm  using for this module that I'm using at the top   is one color at the bottom is another color so  this can be single color or multiple colors but   the color doesn't make any difference because  it's the liquid crystal that they use they use   different color so it doesn't matter so as long  as it's a single color it's the same but RGB is   different so this code will work even if you buy  white yellow and this one is yellow and blue so   two color doesn't matter so for this one the  address is 0-3 C so the address that you type   is 0-3 C they have other suggestions for this but  this was in my case it was 3 C so you have to play   with this either this value or this value one of  them will work the word display dot begin and it   begins with the module with the i2c address so  that it starts an important function here is   display which we put the object displayed dot  display if you don't put a display the text or   whatever you have will not be displayed so and  then this method clear display will clear the   screen draw pixel so how it works is this 10 10  means this is the X location and that's the y and screen assaults her legs from death left to right  so it goes from 0 to 127 or 128 dot and Y is from   0 to 63 which is 64 so 128 by 64 so any X when  you see here 1010 it draws a pixel drop Excel it   goes at a location 10 X and then 10 Y so it will  draw a dot here so you have to set three important   parameters for the display to work the first one  is the size which is 128 by 64 which I'm going to   show you the second one is the i2c address that's  very important otherwise you will never be able to   see any text and the third one is modification of  the size in the library that is connected because   it's unfortunately not set it will not detect that  you have to set this up so let me show you these   two and then the second one is the address that  the it must match for the i2c communication and   the third one is that you go so the third one  is just find out where you are or doing it in   salt where you put the code inside the library  so go to that and go to the other fruit master   and here is the file that you need to change SS D  1 3 0 6 H right click so right-click open it with   edit I've already said this to open with notepad  last class if you have note that last class just   open it so just scroll down more and more until  you reach around line 70 or 73 so these are the   three that are four different sizes 128 by  64 128 32 1 to 96 16 because I'm using 128   64 just uncomment this one so initially it was  like this so this was now set because minus 64   commenting this and then uncommon that one so  these will be useless so this will be now active let me run the code make sure that it works so that was that's the dot okay so when you  type display dot display without anything   this will print the other fruit main thing  that you saw initially so when the code   runs it draws this triangles and it's and  also another type of triangle with filled   up line it draws arrow with all this drawing  and sided circle filled up with circle and   also with the corner rectangles rounded  rectangle and this is now a triangle and   then it filled it up and then shows all the  character characters and then scroll the text triangle and then triangle again you see here that  one triangle another triangle and then this is   clearing it and then there are character so this  draws all the character that is within the system   and then a scroll text whatever you do after  if you have to say that display if you don't do   the display it will not transfer I'm gonna show  you and here display these are the internal one   that you can use without any extra effort so for  example you say set text size equal one when you   set at one that's the smallest one and you can go  to three or higher and then here you say you sent   you said the colors the texts of the color so  very important to mention here that the white   when you say that is a color if your display is  white yellow blue whatever so that white mean   that color that you have so even if it's blue  so we put white here the white means the color   the black or this area so which has no color and  then the set cursor this set the position where   to start zero zero and then it prints hello world  at that position with this size with this color   one is set the colors with the two parameter  so this will invert it so the first one is the   text color which is black and then the white is  the background colors if you need to change the   background you said that and parental and as  a pie value it'll print and then so forth so   it just plays with all of those an inside loop  there is nothing so which means when this runs   the display stops at this and stays like that let  me show you how you start customizing it for the   purpose that you need so the first thing is just  let's save this as so I'm going to name it test customize when I'm gonna open it here and then  open the other one that initially that I had so   this was the original one with all the values and  this is a customized so the first thing first all   these methods that are there we will we will  delete them all anything inside the setup just   below the begin display dot begin so display and  that's delete everything so inside the setup you   will have only one line these are the comment  doesn't matter so with the address and then   you have the loop underneath we have a lot of  methods that are really that are there for us   so for now I'm not going to delete it but I'm  gonna show you how you can print a text how you   can do some stuff here okay let's using this one  draw a circle that expands so just copy this I'm   pressing ctrl C go to the loop and then open close  and close it so test draw it will use that method you see Adafruit at the top exist that the  reason because I forgot to put that clear   display because when you open this this method it  trans that backsplash from Adafruit so let's put   this code here so the reason that we see this  other fruit stuff here is because this method   by default prints that splash so you have to set  display clear display that's method inside the   setup and then just wait two seconds give it a  little time so let me upload it now this should   just draw the circle without this backsplash of  other fruit so to draw a rectangle something like   this you just test draw a rectangle so it'll draw  a rectangle to the for loop that draws rectangle   that are getting smaller and smaller and smaller  their color as I mentioned don't worry I'm not   playing with a color it's just a display built  and the top portion to be always yellow so don't   worry you will get either whatever color you have  this is a single color to draw a triangle like   this that is expanding just use this method  so draw a circle which is already filled up just use this method the Russell curve and  then clear display is always needed in the   loop so it clears the previous drawing this is  the code that you can print this text here for   example Robojax so to print it without any  extra thing I've deleted everything so this   is says display dot set text size this is  determining the size of the text here which   I'm going to show you next that one would be  small the white is the color that is opposite   the background and then we said the cursor  this is X and this is y so X is 10 pixels   from here which is here now we go ten pixel  and then thirdly means from the top go 30   the hole height is from here to here is 64 so  this point the corner of this is 30 so that   is 10 and then 30 and then after that we put  the actual text and then we say display if we   don't say display it will be blank so let me  just change the color now the text size to 1 so as you can see that texted in got smaller so  to see the text with a background white and the   color text color of the text should be black  just like black the first parameter that's a   color of the text and the white if you said this  automatically will set the background white if you   don't set it the background will be always black  so this code now if you want to send to text just   put the position of the cursor and in the text  and then the position of other cursor second   cursor for the second text so very important to  know that you need to have two different things   two different position of the cursor but the  display should be only once called so here is   the code that have written for that one so it's  called Ruby Jacks text so you pass a string and   you press that position X Y size and then this  Boolean D is if the display should be printed   immediately or it should weigh sometimes you  need it so what I'm gonna do is I'm gonna use   it now to show you how you can eliminate  all this by just using this method here for this code just if that plant the world  Robo jacks at the position X equal two so two   pixels to the right and then one pixel from  the bottom so that is why and then the size   of the text is two and then through means per on  the display so now if I have another text I just as you can see here now because I forgot to  change the text it just printed exactly at the   same position the Robojax and YouTube so we have  to find out the size of this this one the position   X is good I just need the Y to be changed let me  put it at 16 so the exact size so maybe this is   14 pixels or 15 so if I so that says you can send  another text and so forth so as much as text as   you wish you just put so in this example I have  printed the one word Robojax and then aligned   and then YouTube as you can see here Robojax the  first line have not changed and then to display   that line I just say put go at a position X and  then Y is 16 so X Y is 16 which means to go down   on Y and then this is a method that you can use  this is internal method that display dot wealth   would give you all with the wet -1 because we  said that a 64 pixel now what is 64 so we have   to say minus 1 so it displayed on the screen and  then so this is that the line starts with a one   point beginning point and then the end point x  and y so it is source at 0 16 and then 64 and 16   so it goes 64 and then 16 down so this means 63  16 and 16 and the color is white after that we   just type the word YouTube now because this text  is taking 15 pixels I started this at 16 so maybe   this text is taking 14 because there is one pixel  empty and then we said for 15 years empty as you   can see in between those and then we said from 16  start this takes 1 pixel line and then we left the   17 empty and then 18 so the text the next thing  starts from 18 and held this is the final example   that I'm gonna show you here so the first text  prints the value and then inside the rectangle   we are putting the voltage of 41 volts and the  temperature at 32 degrees Celsius so regardless   what takes you 1 so this is the text start from XY  and the size XY and 22 so because we are coming 22   pixels down and then we put also temperatures  this is a text the size is one source from X   4 and then YF 45 so X is 4 and then Y is 45 it's  way below so this number will just put it up and   down and then that true is for displaying and then  here we say display line the line has a starting   point and end point so a start is 137 that is 1  and then 37 that corner and disc sorry this is   a line okay so one corner and then 137 under this  event so this is one piece off line and this is a   rectangle so the rectangle is sourced from 120  that's one corner 120 and then ends the other   corner it goes 200 so that is hundred and then X  is hundred and then Y is 40 so because this was   20 so we went 40 here so it's always diagonal  and there's the color so this way you can print   values that are based on some other parameters  or they're coming from somewhere else in actual   industrial design you can use this to display  those values all the code for this project for   this project was a three example that I did will  be posted at Robojax those counselors learn slash   Arduino which you can also click by clicking at  the description below so I will have also video   for the SPI version which has multiple connection  that does faster and also a different type of the   place so please subscribe and also please tumble  the video if you like it thanks for watching you
Info
Channel: Robojax
Views: 63,167
Rating: undefined out of 5
Keywords: electronic, drone, tutorial, training, video, robojax, ssd13306, address, 0x30, arduino, oled, display, text, draw, show, rectangle, triangle, circle, example, explained
Id: UmYiHTOz-5k
Channel Id: undefined
Length: 22min 36sec (1356 seconds)
Published: Sun Dec 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.