Lesson 22: using SSD1306 OLED display | Arduino Step By Step Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to an Arduino  step-by-step course by Robojax hi welcome to another video tutorial from  Robojax in this video I’m going to show   you how we can use this SSD 1306 128 pixel by 32  pixel i2c display to display live text something   like that for example this is the voltage  shown or maybe a temperature from a sensor   or another value that you can display so you can  display a text you can just fill a rectangle line   and there are tons of other options which I’m not  going to explain but these are the basic important   thing that you need to be able to use this display  so this is very tiny easy to use four wire display so this is the module as  you can see it's very tiny you don't do any setting or anything and  it has just four pins here or four wires   so you might receive it these pin not be soldered  so just solder them in my case it just arrives   soldered and it has four pins here ground vcc and  s cl and that's a clock an sda that's the data it   needs one more pin which is called the reset pin  but that one has been taken care of with the code   so the width of this is 11.8 millimeter and the length is 38.2 millimeter the  depth is 3.5 millimeter without these pens so the link for this library will be provided so  you come here and download it once you download it   you will have a file a folder something like  this you will have adafruit ssd1306 master   so you will right-click using 7-zip if  you don't have 7-zip get it from 7zip.org   and then say extract here once you do that you  will have a folder the same name as this one so you will have this folder and then all of  these files are here so right click copy it   and then go find your Arduino you're going to  see program files and your Arduino might be here   so in my case this is a folder  and you just go to the libraries   and then right click and paste it once  you paste you will have the main folder   other fruit here so if we open this there is  a ssd1306.h and there are examples so once   you put this and open your Arduino you  will see something like this go to file so go to file examples and scroll you will see here adafruit SSD 1306   and this is the one that you are opening  so 128 times 32 i2c so you will open that now let me explain the why this is the wiring  diagram for ssd1306 128 by 32 pixel led display   from the bottom ground have been  connected using a black wire to the ground   vcc pin have been connected using orange  wire to 5 volts scl or clock is connected   using a red wire to a5 and sda is  connected using a brown wire to a4   getting here we have four wires here from  this side we have ground or GND and then   vcc so ground is connected to the ground through  this black wire as you can see here to the ground   and then we have this orange vcc this vcc will be  connected to five volts which have been connected   here to five volts of Arduino and then the  last two wires so there are two other wires   so we have SCL will be connected to a5 and sda  will be connected to a4 so flc is this red wire   connected to a5 here and then the brown  and one is to a4 and a4 is the sda once you open it this has tons of features  and codes which I’m not going to explain and   you can play with them and learn from  it but the example that I’ve created   will make it very easy for you can use so once you  open the example make sure that here is the height   the height is 32 pixels so you will type 32   and here you will type 128 because that is the  width of the this screen and then upload it so this is the default code that we have and  these are the drawing all these figures and   ships will be drawn and displayed so as you can see it has  scroll up down left diagonal so white shape black shape and all this this one says include spi.h this code is made for  multiple type of application I did not remove it   so this will not be used the wire will be used  which uses the i2c and these are the other fruit   other libraries that are that are needed this  is the main library that is needed for this   so this will be part of the library so you must  keep it intact oled reset pin 4 to eliminate   extra wire so this must be left like that as  pin four and it will come here and the rest are   okay and here the thing that you need this is the  width the height of the display which is 32 pixels   so this screen is 32 pixels so we have 32 dots  here and then we have 128 pixels like that   so this 32 is the height and 128 so if it's a  different value so make sure that you change that   and beside that one more  value that you need to change   within the library under the library is this uh ss d1306h so if I open it I’m you  opening it using notepad plus plus   so if you scroll down scroll down around line 74  you will see that this code is made for 128 by 64   and 128 by 32 and 96 by 16. so this is commented  the two slash so initially when you open the file   it will be something like that  and this will be commented   so make sure that you comment the first line  and uncomment or remove the comment for this   either you open it in notepad or whatever just  click save so when you save it then it will work so after that then this is the important part that the majority  of this display has the i2c address as 0x 3c   so this is the address I will also provide the   i2c scanner so here is i2cs scanner that I’m  running now I’m going to run and show it to you so I’m going to upload it so what it does is that  it find the address of the module that you have   so you will see the address here we're  just waiting for it to get uploaded   I will provide this code on the same  page as the other code so you can get   it in case if your module doesn't work  so you have to find out the address so you see it found that zero x three c that  receives our zero x mean hexa decimal value so   majority of these modules have this address but if  not make sure that you run i2cs scanner to get the   address so and if you get a different address just  put it here other than that we don't need anything   any setup here so let me explain it from setup  from here to here this initializes the display and   with this i2c address and you put display this is  to display the adafruit splash screen which they   put in the code and they say it must be included  under the distribution so I’m including it   but if this is removed you will now  see that splash screen and then two   thousand milliseconds and then it waits to for  that to be displayed and then it clears the buffer   so this is done now we go inside the loop from here to here so to put a text we just  put this one I’m going to explain this next   but pay attention here we say Robojax text and  then inside the quotation from here to here   we put the text wherever you want and then  this is the x and that is the y so that word so this one that you see here that says voltage  with that extra space so that is that's this one   voltage and after that we want to include a live  value this is this can be from another sensor   from temperature sensor from distance sensor  whatever you have you will have to have it as   a string in this case I have it as a count so if  you have a voltage or a sensor from a temperature   monitor from other device so you must convert  it to string this way so we have string this   is the main function and that three is the three  decimal points that you have so you put that and   then you say count or the value that you have you  put it the result will be stored here as a string   with a string type so now this is the voltage  string this is just a counter that I put   it just goes and adds 0.173 to it because this  loop continues so you will have different values   you see this is a multiple of 0.13 so the  value will be converted here and will be   displayed here this 72 is the distance that  this text takes the voltage from here to here   each character takes eight pixels so you just  count one two three four five six seven eight   times eight is 64 plus this empty space so after  that I put 73 and the y is three this must be   the same as that one and then I also counted the  length of that text and then at 110 I put the v   so that's why you see this text this  value and then the v so this is the text   this is the actual value and this is the v  all these three will display one line and then   after that this is a second line which shows the  temperature this is just a text for illustration   purpose you can put a live value and then the  next one shows another text as capacity as you   can see here and then if you want to draw a line  so this is a position of x and position of y that   the beginning of line and that is the end of line  x and y if you want it straight make sure that   the two y's are the same if you want the line to  be diagonal like that so you can go x and y at   that point and x and y does this point and then  you can draw a circle which we could not see it   here because I I put it in 100 as at different  positions so this this this is the moon the most   important one that you will be using in your  rare application now this Robojax text is here so this is a function that I’ve created  that gets the string position x y size   Boolean so you don't worry about this you  just pass the your value this is x this is y   and this is the thickness if I make this  two then the voltage or the value will be   displayed thicker but when it you make it  thicker it will take more space and make sure you   account for that adjustment upload the code  again now with the other fruit splash screen you see other fruit is displayed and after  that these values and as you can see rectangle   has been removed so if you want to bring the  rectangle back there will be this plate again   this was introduction to SSD 130628  pixel by 32 pixel oled display with a   code thank you for watching please make sure to  subscribe by clicking at the subscribe button   in here thank you thank you for watching tutorial  from Robojax if you learned something and found   this useful please thumb up as this will help  my video in the search algorithm of YouTube   if you have comment or question please  post it at the comment section below   I try to answer and reply and don't forget to  subscribe so you get updates on my upcoming videos
Info
Channel: Robojax
Views: 4,949
Rating: undefined out of 5
Keywords: electronic, tutorial, training, video, robojax, arduino, code, download, project, diy, robot, robotics, engineer, english
Id: UZTAV2sRi9w
Channel Id: undefined
Length: 16min 44sec (1004 seconds)
Published: Sat Jun 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.