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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
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 pixels eye to see 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 display a rectangle line and there are tons of other option 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 for wire display. so you can get the codes for this by clicking at the link of the description which below which will take you to www.Robojax.com/learn/arduino so let's get started Hardware Explained so this is the module as you can see it's very tiny you don't do any sitting or anything and it has just four pins here or four wires so you might receive it these pins not be soldered so just solder them in my case it just arrived soldered and it has four pins here ground VCC and SCD and as a clock and SDA that's the data it needs one more pin which is called the reset pen 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 pins Getting the library so the link for this library will be provided so you come here and download it or once you download it you will have a file a folder something like this you will have Adafruit SSD1306 master , just right click using 7-zip if you don't have 7-zip get it from www.7zip.org and then select "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 go in 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 Adafruit here so if we open this there is a SSD1396.H and there are examples so once you put this an open your Arduino you will see something like this go to file If Your Arduino IDE (Arduino program) is open, please close it and open it to see the examples. the file->examples and scroll you will see here Adafruit SSD1306 and this is the one that you are opening so 128 times 32 I2C so you will open that Wiring Explained now let me explain the wiring 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 are being connected here to five volts of Arduino and then the last two wire so there are two other wires so we have SCL will be connected to A5 and SDA will be connected to A4 SCLis read wire connected to A5 here and then the brown and one is to A4. A4 is SDA once you open it this has tons of features and codes which I'm not gonna explain and you can play with them and learn from it but the example that I've created will make it very easy before you you can use so once you open the example make sure that here is the height the height is are the two pixels so you will type 32 and here you will type 1 2 8 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 shapes will be drawn and displayed so as you can see have scrolled up down left diagonal so white shape black shape and all this Custom Code explained this one says include SPI dot H this could've 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 Adafruit libraries 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 an intact PLED _RESET pin 4 to eliminate extra wire so this must be left like that as pin 4 and it will come here and the result okay and here's this is the the height of the display which is 32 pixels we have 32 dots here and then we have 128 pixels like that so this 32 is the height and 128. If your is different values to make sure that you change that and beside that one more value that you need to change within the library under the my library this this SS D 1 3 0 6 H so if I open it I'm you opening it using Notepad++ so if you scroll down scroll down around line 74 you will see that this code is made for for 128 by 64 and 128 by 32 and 96 by 16 so this has commented the 2 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 at a 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 new display has the i2c address as 0x3C so this is the address I will also provide that I2C a scanner so here is i2c scanner that I'm running now I'm gonna run and show it to you so I'm gonna upload it so what it does is that it finds 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 of 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 founded that 0x3c that receive that 0x mean hexadecimal value so majority of these modules have this address but if not make sure that you can use I2C scanners to get the address so and if you get that different address just put it here other than that we don't need 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 display this is to display the Adafruit splash screen which they put it in the code and say it must be included under the distribution so I'm including it but if this is removed you will not see that splash screen and then 2000 millisecond and then it waits to for that to be displayed and then it clear 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 the Robojax text and then inside the quotation from here so here we put the text wherever you want and then this is the X and that is the Y so so that word so this one that you see here that says voltage with that extra space so that is that 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 at a String(data type) in this case I have it at account 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 that's the main function and that three is that 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 results will be stored here as a String with the 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 zero point one three 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 8 times 8 is 64 plus this empty space so after that I put 73 and Y is 3 this must be the same as that one and then I also counted the length of that text and then at 110 I put a 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 death 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 wanted to straight make sure that the two Y 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 at this point and then you can draw a circle which we could not see it here because i put it on different positions so so this is the most important one that we will be using in your real application now this robojax text is here so this is a function that I've created that gets the string position XY size, boolean so you don't worry about this you just pass them 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 Let me upload the code again now with a Adafruit splash screen you see how the fruit is displayed and after that these values and as you can see rectangle have been removed so if you want to bring the rectangle back it will be displayed again this was introduction to SSD 1306 128 by 32 XL OLED display with a code thank you for watching please make sure you subscribe because I don't have a lot of other projects coming so you get updates and also thumb up 👍 the video. if you so if you have any comment or question please post it and I will try to reply or answer Typed on Mar 04, 2020 by Ahmad Shamshiri please 👍 the video and share. you The least you can do for me is to click on SUBSCRIBE button. Thank you
Info
Channel: Robojax
Views: 79,511
Rating: 4.7309942 out of 5
Keywords: electronic, drone, tutorial, training, video, robojax, arduino, code, download, ssd 1306, ssd1306, ssd-1306, 128x32, oled, display, show, text, i2c, screen
Id: RjyulqVsz2o
Channel Id: undefined
Length: 16min 8sec (968 seconds)
Published: Sun Mar 18 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.