OLED Displays with Arduino - I2C & SPI OLEDs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today and the workshop will be working with oled displays we'll see how we can connect both eye to see and spi displays to an Arduino Uno we'll even build a temperature and humidity meter we have a lot on display for you today so welcome to the workshop [Music] hello and welcome to the workshop today we're going to be working with organic light-emitting diodes or ohlet's now all LEDs can be called a 21st century display product even though they were developed during the 20th century the very first commercial device to use old LEDs was a Kodak camera in 2003 in 2013 Samsung became the first company to release OLED televisions and they're now the biggest manufacturer in the world of OLED television screens now the O LEDs we're going to be using are not as big as TV screens they're very small ones I've got an example of one over here these are the type of devices that you will see on things like radios mp3 players and smartwatches and they're very good for using with an Arduino as a display these things have a lot of excellent properties they're very easy to read they're bright they take a very little current you can read them from different angles so it's really useful to know how to work with one in an Arduino now I'm going to actually work with a couple of different ohlet's today the OLED I'm holding over here is an SPI one I've also got a couple of I to see bus ohlet's affiliate hook both of those up to the Arduino and how to run some code to use them now we're going to go through a bit of example code we're going to quickly go through it because it contains a lot of graphic stuff that we really don't need what I really want to show you is how you can write to an OLED and in order to do that what I've done is I've developed a small project it's a temperature and humidity meter that uses an OLED as a display and with that project I'll go through the code bit by bit so you know how to use an OLED in your own projects so let's get going and learn a bit about all LEDs and start working with them in the Arduino Oh LEDs are organic light-emitting diodes organic molecules are molecules that contain carbon Oh LEDs use organic molecules to admit light organic semiconductors were first discovered in the mid 1970s and led to a Nobel Prize in the year 2000 first practical Oh LEDs were developed by laboratories of Kodak in 1987 now let's take a look at the difference between an LED and an oled internally an LED consists of an N and a p-type semiconductor material an OLED consists of several layers of organic molecules in an LED there is a gap between the two sections of semiconductor material in an OLED the different layers are sandwiched together between plates the components of an LED are as follows you're probably familiar with them there is the cathode and there is the anode material the layers of an OLED are as follows first the cathode then the emissive layer then the conductive layer and then the anode these layers are sealed between the top layer called the seal and the bottom layer called the substrate when current is applied to a standard LED electrons travel between the anode and the cathode as they cross the gap light is emitted in an OLED the electrons travel through the layers the emissive layer emits light ohlet's of several advantages they're thinner and lighter than LCDs and LEDs and they can also be flexible allowing the use of curved displays all LEDs are brighter than standard LEDs all LEDs consume very little current ohlet's don't require any backlighting like LCDs do you can create very large OLED screens because old LEDs are printed on to a substrate oh let's have a very wide field-of-view approaching a hundred and seventy degrees so they look good from any angle there are also a few disadvantages to O LEDs blue o LEDs have a shorter life span than standard blue LEDs currently uh LEDs are quite expensive to manufacture all LEDs can also be damaged by exposure to water eventually Oh LEDs will become keeper than LCDs as manufacturing techniques improve the lifespan of OLED displays is also being improved OLED displays can be printed on to a substrate and that brings up a number of unique possibilities many new materials are possible including the possibility of printing o LEDs on the cloth to create clothing that actually could act as a video display and finally all LEDs are a lot of fun so let's start using öhlins and our Arduino projects now now here are the OLED displays that I'm going to be working with in today's video and as you can see there are three different sizes let's start with the smallest one over here now this is a 128 by 32 display meaning it's got 128 pixels across and 32 down let's just take a closer look at it now this is just an i2c display and you can see the i2c connections at the top of the display here on the back of it there's really nothing to talk about just a number of resistors and capacitors and what looks like maybe a small voltage regulator there's no method of setting the i2c address with this display so it basically comes configured at the factory now this next display over here is twice the size this is 128 by 64 it's also a two color display so the very top 16 pixels down are in yellow and the remaining 48 are in blue now let's take a closer look at this particular one again you can see it's an eye to see display so it's got the connections at the top if I flip it over you will see there's a method of setting the i2c address now there's a small surface mount resistor sitting on these two pads and if you want to change the address you need to remove it and put it across these two pads over here so it's not quite as easy as a jumper switch but it's only something you'd have to do once so there's that display now this one here as you can see is much larger this is me by wave share and what's interesting about this display which is 128 by 128 is that this display can be both I - C or SPI and let's take a closer look at this one over here you'll see some connections on the side over here for the display you'll also see a connector that has the same connections on it and wave share does supply a cable with the display and that's actually what I'm going to be using now as I said it can be set for SPI or I to see there's a little resistor pad again that you move to one position for SPI and the other one for i2c now I've got this in SPI mode and that's how we're going to test this one so what we have over here then are two i2c OLED displays and one SPI display so now let's start working with these displays so we're going to begin by using the two i2c display as I had that's these two small ones here the 128 by 32 and 128 by 64 display so let me fill you how you hook that up to an Arduino and then we'll run some code to actually make the displays work we'll be working with two I to see displays today one has a dimension of 128 by 64 and the other has a dimension of 128 by 32 the connections on both displays are identical on the far left side we start off with the ground pin next is the VCC pin which we will be connecting to 5 volts beside that is the SCL connection this is the i2c clock line and finally the SDA connection which is the i2c data line now I'm going to illustrate the large display in my connection diagram but keep in mind connecting the smaller display is identical from the Arduino will connect the ground to the ground connection on the OLED display will connect the Arduino 5 volt output to the VCC on the display will then connect analog pin a-five to the SCL connection on the OLED display and finally we'll connect analog pin a4 to the SDA connection now your Arduino may have separate connections for SCL and SDA and if so feel free to use those instead of the analog connections they're actually internally the same connection now that we have it wired up let's take a look at some code to put something on to our OLED displays so now that we've hooked up our display we're going to need to write some code to make it work now in order to facilitate that we are going to need to install a library and there are many libraries you can use for ohlet's OLED displays typically have a driver tip and the driver chip in both of these displays are the same it's called an SSD one 3:06 and there are a number of libraries you can use to control the SSD one 3:06 driver chip I'm going to be using a library from Adafruit to control this display it was originally written for one of their displays but it can be used with pretty well any display that uses the same driver chip another library is also going to be installed and it's an Adafruit graphics library and this is just going to be used to draw a number of patterns on the display so we'll install those libraries and then run a few bits of their test code that come included with it so we can take a look at our displays in action so let's go ahead and do that in order to work with our OLED display we're going to need to install a couple of libraries into our Arduino IDE now there are several Arduino libraries you can use for working with oh let's I've decided to use a couple from Adafruit now you install libraries by going into your library manager which he will find under sketch and include library and then manage libraries open up the library manager and you'll be able to install some new libraries now there are two libraries are going to install they're both from Adafruit and you can search upon the search line over here the first one is the adafruit gfx library so type in a two fruit GFX and here we have it over here now as you can see I've got mine installed but if you don't have it installed when you hover over it you'll get an install button for example if I go to the next library you'll see the install button over here on the right side so just click install which will install this library and then go search for another Adafruit library this time the Adafruit SS d1 306 and here we have the SS d1 306 library again I've got mine installed but you'll need to hit the install button to install yours once you've done that you can close the library manager now go into file and go into examples and go down near the bottom where you'll see examples from custom library and look at Adafruit SS d1 306 and you'll see for example files now we're using a 32-bit sorry a 32 line display and I've got it connected via IC to si2 C so let's go and click on that one right now and that's the one that I've got opened up over here ok so let's take a look at this sketch now I'm not going to go through the entire sketch because it's a very long sketch which goes through a lot of the graphics library to draw all sorts of graphics and animations on the screen and if you want to draw graphics and animations there are some good examples here however I'll go over some of the key aspects of it for you first of all we're including both the SPI and wire libraries now personally I think this is an error over here I think it's because Adafruit has these 4 sketches and two of them do SPI that they've just done this because all the sketches have it I really don't think that this particular code needs the SPI library but it does indeed need the wire library the wire library is included in your Arduino IDE and this is the way we talk to i2c then of course we're going to include the two libraries we've just installed now here are some of the things you'll need to know when you setup the program we've got the screen width and the screen height as a couple of constants defined over here and this is what would change if you're using a different OLED display based on the SSD 1306 tip but a different size you could change this over here now one thing I need to mention if you're looking at some instructions on the internet for using this library you may find some instructions for going and modifying the library file to use 32 line displays this is no longer necessary the new version of the library has corrected that issue okay after that we need to define an object which we're going to call display now what's interesting about this definition is that this definition uses a parameter called OLED reset which is a reset pin some of the Adafruit devices had a separate reset pin this needed to be defined now the devices we're using don't have this reset pin but you actually need to define it in your code in order to be able to create this object so keep this in mind after that there's a number of definitions that just have to do with the data they're going to be displaying on the screen for example a number of snowflakes in an animation example I won't go through all of those with you one interesting thing is this is the Adafruit logo as a bitmap and it's filthy how bitmaps work and that's an interesting thing to know because as you're using these displays and you do animations or define custom character sets you will need to define bitmaps and I will tell you not in this video but in a future one where I fill you animations on the screens how you can define bitmaps but what I find interesting is this is the adafruit star symbol and if you stand away from your screen far enough you can actually see perhaps you have to squint to see it the star in the middle of this pattern over here because this is actually a pattern of what pixels are on and which pixels are off and so you'll find that font files and local files and things look exactly like this anyway that's a bit of an aside in the setup we're going to go and we're going to initialize our device now one thing that's important that I want to point out over here is the address of the device this is the address of mine so it's correct but if you have a different eye to see address on your device you're going to need to change this over here now after that we basically will just go through the code again I'm not going to go through all of it I will show you an example later on how to use this library to write your own code to the display and we'll go through that in detail but right now just suffice to say that we're going to clear the display and draw a whole bunch of different things here and each of these things is defined by a separate function and you can look below here at those functions to see exactly how they work what's interesting about this program is it all happens in the setup because the very last thing that they use the test animate function is one that runs forever and therefore when you get to the loop there's actually nothing in the loop over here so again I'm not going to go through all the code over here we're just going to take a look at how this looks on our display right now and then later on we'll show you how you can write your own text on the display so let's go and take a look at our display now now here's our OLED demo wired up on a solderless breadboard with the i2c and power lines connected back to the Arduino and so let's start it up and run the Adafruit demo and it starts up with the Adafruit logo and then it starts drawing a number of patterns as you can see this is a pretty bright display I've got all the lights on the workshop on right now and even under all my LED lighting you can still see this very clearly and it just runs through all of its different patterns right now it's showing a bit of text and you can see how small you can actually make the text on one of these displays and so it seems like our sketch is working now for our final look at the 32 line display I thought I'd try something a bit amusing now I've got two of these 32 line displays over here and they both have the same eye to see address in fact on this particular display I don't know of any way of changing that address I've got them in parallel on the i2c data bus right now now these are displays they are not sending data back to the date of bus they're simply picking it up so though although you normally don't want to I to see devices with the same address in this particular case I think we'll make an exception and let's take a look at what happens when I start the arduino up and it's probably what you expected what happened both displays are showing the exact same thing now again this is working because displays are just receiving data from the arduino they aren't sending any back if that was the case you certainly couldn't have two devices with the same i2c address and if you wanted to independently address these two displays of course you'd have to use two ones that had different I to C addresses but if you want to parallel a display this is actually a pretty neat technique that you can use so now that we've seen the 32 line display let's move on to the 64 line display which I have wired on my solderless breadboard over here now it was quite easy to connect this because the pin ups are identified to the pin notes on this 32 line display so I simply unplug this and plug this into its place now the thing about this display is it also has the same eye to see address as this display so it should actually come up and work with the existing code that we have now as you recall if you need to change the i2c address on this display you can do it by changing the position of a small resistor on the back of the circuit card but without changing it these two of the same I to see address so before I run any specific code for the 64 line display I thought it might be kind of neat to see what happens when I give it the code for the 32 line display and it actually comes up and starts running and looks like it runs pretty well when you look at it carefully though you'll see the aspect ratio on a number of things are off there's a number of lines that are missing the resolution isn't as high because it's only expecting there it could be 32 lines and not 64 lines over here so let's take a quick look at a modification to the sketch another version that Adafruit is provided for the 64 line display and then we'll come back and run it on this and see how much better it looks so to properly run our 64 line display we will use a 64 line example code that came with the aid of fruit libraries now this code is virtually identical to the code that we briefly looked at earlier for the 32 line display in fact they've even written 32 pixels up over here even though it's a 64 line one they've simply changed a couple of lines in the sketch and that's what I want to show you up over here we've got the display height which is now 64 and another line that you're going to want to look at because I needed to change it to make mine work is the i2c address now when you load this sketch it's gonna come up with this address which is 3 D hexadecimal that is not the address of the i2c device I'm using mine is at 3 C so I had to change it and you would change the address over here so take a look at that otherwise this is an identical sketch so what we're going to do is loaded up to the Arduino and take a look at it on our 64 line display so now let's take another look at the 64 line display this time with the correct sketch driving it and as you can see the Adafruit symbol comes up a lot clearer than it did before and so do the lines they're a lot closer together and of course we would expect that because this sketch knows that we're driving sixty-four lines and not 32 lines another thing that you of course will have noticed is that the top of the display is in yellow and the bottom is in blue this is a two color OLED display and these are quite common you could use the top for some sort of status indicator and the bottom for some sort of text to make a more vibrant display for your users as you can see from the text display it's capable of very tiny tiny text and it's still very legible and again this is being filmed right in the workshop under all of my LED lights and it's very easy to see and so there you have it the 64 line OLED display so now that we've seen how those two I to see displays work I want to move on to the SPI one now that's this wave share device which as you recall can be used in both SPI and i2c mode I'm going to be using an SPI now the Arduino Uno has an SPI bus as does the Raspberry Pi and many other controllers the Arduino Uno can control two different SPI devices so that also opens the option of controlling two different OLED displays via SPI as opposed to doing that with i2c in different addresses now I'm going to show you the wave third device in a bit more detail I know we already looked at at bubble take another look at it and then I'll show you how to hook it up and then we'll install some demonstration software onto our Arduino IDE and watch it on the display so let's go ahead and take a look at our display now now once again here is our wave shared display we looked at it earlier when we looked at all of the displays and here's the cable but comes with it now this cable can attach to the connector at the back of the display or you could simply solder some pins onto these pads over here on the display it's really up to you they're the same connections the cable has a number of female connectors on the end of it so that won't plug directly into an Arduino Uno I'm going to be using some little jumper cables in order to assist me with that if you want to use a Raspberry Pi with this this will plug directly into the GPIO connector on the Raspberry Pi now once again let's take a peek at the back of our display and we saw this before that there's a little jumper down here that puts it into SPI or i2c mode and this is currently in SPI mode now when you go into i2c or SPI mode the function of a couple of the pins changed and they have a little chart over here that shows you that interestingly when you're in I to C mode you can use this DC connection and either bring it high or low and that will set the i2c address but we're going to use our little wave sir display in SPI mode so let's take a look at how we are going to do that now I'm going to use the connector that waves here provided to connect my display to my Arduino but you could also use the pins on the display and use a solderless breadboard instead using the cable the connections are as follows the VCC which is the red wire is connected to the Arduino five volt output the ground which is the black wire is connected to the arduino z-- ground the DN connection which is the blue wire is connected to Arduino pin 11 the CLK connection which is the yellow wire is connected to Arduino pin 13 the CS or orange wire is connected to Arduino pin 10 the DC connection or green wire is connected to Arduino pin 7 and the rst or white wire is connected to Arduino pin 8 in order to work with the 1.5 inch OLED module from wave share we're going to need to install a few files into our arduino ide we can get these files on the wave share wiki for the 1.5 inch OLED module you'll find the URL to that wiki and the article accompanying this video once you get there go take a look for demo code and open up that page I've got it open up over here and amusingly they've got a bit of a spelling mistake here it's a 1.5 inch OLED module apparently at any rate download the 1.5 inch OLED module file it's a zipped file so you're going to need to extract it and let me show you that here now on the right side pane I've got my file and I've extracted it and it creates a directory called 1.5 info LED module which I'm going to open up and in that directory you'll see three other directories arduino raspberry and stm32 let's open up the arduino directory now on this side of my file manager i'm showing you the contents of my own arduino directory this is the directory where all my arduino sketches are used and it is set up by your arduino ide you'll find it on your local hard drive and it'll probably be called arduino now you're going to need to move some files from here into there the first ones we're going to look at are in this directory called Lib which means library and you'll find one that says fonts now in the arduino ide all of your libraries are kept in this folder called libraries so open up your local folder called libraries in the arduino directory and copy these fonts into there now i've already done that if you already have a fonts folder you can also open up this folder and just copy the contents of that into these font folders once you've done that you can return back out to this stage here and we'll bring our arduino directory back to over here now there are two sets of examples here one for external RAM and one for internal Ram external RAM requires that you actually add additional RAM to your Arduino we obviously aren't going to do that so let's go to the internal or example and you'll notice one called Oleg so copy that entire folder into your Arduino IDE as I've done over here and then in the OLED shell you will notice that you have a number of files including an OLED so Ino full file open up that file loaded into your Arduino IDE and loaded up to the arduino now i'm not going to go through that file with you right now it's very complicated you're welcome to go through yourself I'm simply going to show you the results so I've taken that file put it into my IDE and loaded it up to my Arduino so now let's go take a look at it so here's our wave share display running the demo sketch now as you can see I've used the cable that they provided to attach it to the Arduino and because their cable has female ends on it I just used very short jumper wires to make the connections to the Arduino itself so let's take a closer look at this display if we can now as you can see it's a pretty nice display they've got a number of different symbols on it to show you what you can do with it along with their fake clock in the middle and a bit of text and as you can see it's very clear it's very easy to see even under the lights of the workshop right now so this is another excellent display that you could use for one of your projects and the beauty of this one is that you could use it either as AI to see or with the SPI bus so it's quite versatile as well so now we've seen how we can hook up an OLED to an Arduino using both SPI and i2c we've also installed a couple of libraries and some sample code into our IDE and we've been able to use that to make the OLED work and that's great now if you want to use all LEDs in your own project you can go into the sample code and dissect it and start seeing how you can print to the OLED and that's also a really useful exercise however you might find with some of these samples it's a bit overwhelming these are very very long pieces of code and they can tane a lot of graphics routines the wave fair one directly addresses fonts and that might seem a bit complex if all you want to do is display a bit of data on an OLED display so in order to make things a bit simpler I've created a little project it's a temperature and humidity meter it uses an OLED display and I'm gonna go through the code with you step-by-step so you understand how you can print text on the OLED now there's no graphics on this it's dis simply text now the sensor amusing is kind of interesting this is the a.m. - 3 - 0 sensor now I know it looks a lot like the dht11 and dht22 and it works the same it's a temperature and humidity sensor but this is an i2c device I've used it in a previous project you might recall so it's an i2c device we're also going to use an i2c display I'm going to use the 128 by 64 display for this so let's take a look at how we wire up for temperature and humidity meter and then after that I will walk you through the code so you can understand how to use OLED displays in your own projects now to build our temperature and humidity display we're going to start with the same circuit we already have for our eye to see display we'll then add the a.m. - 3 to 0 temperature and humidity sensor will connect the sensor as follows starting from the left side we'll connect the first pin to VCC that's the 5 volts from the arduino the second pin is the SDA pin that's the analog a 4 connection on the arduino the third pin is the ground and the pin on the far right side is the SCL connection which is arduino analog a 5 now that we have our temperature and humidity sensor connected let's take a look at the sketch we'll use in order to display the temperature and humidity on the OLED display here is a sketch for our OLED temperature and humidity meter now you've already installed the libraries we're going to need the OLED displays but you're going to need to install a library for the temperature and humidity sensor itself so again you'll do that in your library manager and you will look for the Adafruit a.m. - three to zero library and install that and while you're there look for the Adafruit unified sensor library now the unified sensor library may already be installed because it's used by a number of Adafruit sensors including the two three to zero but if you don't have it install that as well because it won't work without it now that you've got the required library so let's take a look at the sketch now we start off by including the arduino wire library so we can talk on the i2c bus then we include the two libraries we need for the OLED display the art the graphics library and the SSD 1306 library now we include the library we just installed for the temperature and humidity sensor notice we don't include the unified sensor library the temperature and humidity library will call that library now we're going to set up an object to represent the OLED display called display and in order to do that we need to provide it a parameter called OLED reset so we're going to set an OLED reset value even though we don't actually use it that's just so we can set this object up over here called display and this will represent our OLED display we're also going to set up an object called a.m. - 3 to 0 and that will represent the temperature and humidity sensor now in the setup we'll just initialize all of these different objects so we're going to initialize the i2c library will initialize the display and we'll give it the i2c address which is 3 C now if you have a different address for your display you'll need to change this parameter and then finally we'll initialize the temperature and humidity sensor now the majority of the action in the sketch happens in the display temp you mid in which we're gonna go over right now so we'll start off by delaying for a full two seconds that's because the temperature and humidity sensor needs a couple of seconds to stabilize then we'll go and read the humidity and temperature and assign them to a couple of floats called H and T now the temperature's going to come back in Celsius if you look in the a.m. - three - zero manual you will find that there is also a function you can bring it back in Fahrenheit if you wish now this is how we write on the display and this will be true of any time you want to write to an oled display first of all we clear the display we're actually clearing a display buffer because we're writing through a buffer which will eventually print out to the display then we set the color and we are going to use white for a monochrome display no matter what the actual color of the display is so we've set the text color to white then we'll set the font size I'm setting mine to one then we're going to set up the cursor coordinates where do we want a place to cursor to start printing and so I'm going to pick the top corner which is zero zero this is the position on the line and this is the line itself and so now we're going to print something there and I've chosen to print drone ba workshop you could of course print something else but you're welcome to print drone ba workshop if you like now I'm going to move the cursor down position zero on line number ten and I'm going to print the word humidity followed by a number of spaces then I'm going to print the value of the humidity which has been assigned to the variable H and then I'm going to print a space and the % now I'm going to move my cursor down again to another position on the 20th line at the zero position and I'm going to print the word temperature followed by a couple of spaces the actual temperature value and then a space and a C because I'm displaying in Celsius and so go into the loop and the loop is quite simple we just call display temp u mid which we just looked at get all those values written into the buffer and then we simply use a display property to actually display them and the window will over and over do it again and again so now that you've seen the sketch let's take a look at our temperature and humidity sensor so here's our OLED temperature and humidity gauge in action as you can see right now in the drôme bot workshop the humidity is a very comfortable 49.7% and the temperature is 21 point 8 degrees Celsius which is a bit on the cool side but I just cranked the thermostat on so it should be going up pretty soon now it's a very simple thing to wire up here's the i2c temperature sensor and it's disconnected in parallel to the i2c bus that I've got the OLED display connected to so a very simple circuit the wire up and a good demonstration of how to use an OLED display alright that about wraps it up for our look at old LEDs today hopefully you've learned something and that you've started to think about using old ads in your own Arduino projects now that horizon looks very bright for all LEDs the cost of manufacturing these will continue to go down to the point where they eventually become cheaper than LCD displays or regular LED displays and that's something to look forward to another thing to look forward to is the fact that they can print old ads on to a variety of different substrates and that includes things like cloth and so eventually you'll be able to make wearable clothing that actually is a video screen so you can imagine that my shirt was actually a video screen that opens up a whole world of possibilities now we aren't going to be working with anything so esoteric over here in the workshop that soon but I do have a number of interesting projects and so if you haven't subscribed to the YouTube channel please do just hit the little button below the video and subscribe I would very much appreciate that you'll also find an article that goes along with this video you'll find it on the drone bot workshop comm website and there's a link below the video to that while you're on the website please consider subscribing to my newsletter it's not a sales letter its diss my way of keeping in touch with you and letting you know what's going on in the workshop and I'll tell you there's a lot of new things about to happen here in the workshop so if you subscribe to the newsletter you'll be among the first to know until next time please take care of yourselves and I hope to see you again very soon right here in the workshop goodbye for now [Music]
Info
Channel: DroneBot Workshop
Views: 501,413
Rating: 4.9226799 out of 5
Keywords: oled arduino, oled arduino projects, oled arduino tutorial, ssd1306, waveshare oled arduino, waveshare oled 1.5, oled temperature display, arduino uno, oled, oled display
Id: 7x1P80X1V3E
Channel Id: undefined
Length: 41min 40sec (2500 seconds)
Published: Sat Feb 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.