We’Ll learn two different methods of connecting these displays to our Arduino, including using the i2c bus we’ll, build a digital temperature and humidity gauge and we’ll learn how to use an LCD keypad filled with some very unusual push buttons there’s a lot on display today. So welcome to the workshop Music, hello and welcome to the workshop today we’re going to be working with liquid crystal displays or LCDs. Now I know you’ve seen LCDs and all sorts of different appliances and equipment. We first started to see them used in calculators and digital watches in the late 1970s and now they’ve progressed into all sorts of displays, including video displays in fact I’m willing to bet that the video display you’re watching this video on right now makes use of LCDs. Most televisions these days, including so called LED televisions, are actually LCDs. Lcds have an advantage in that they’re very easy to manufacture and mass produce, so they can be made quite inexpensively and they are very versatile devices. Now LCDs work in a principle of a liquid crystal which can align itself between two different polarized filters and then either let light pass or it can block light and because it doesn’t emit light itself. An LCD requires a backlight. Now this backlight can be manufactured in a number of different ways: they’ve used electric luminescent panels for them fluorescent tubes have been used, but by far the most common method, these days is to use an LED backlight.
Now the LCDs were going to be working with. Today. Are very simple: monochrome, LCDs they’re either two or four line displays and you can purchase these they’re quite inexpensive and they can be used in your Arduino or Raspberry Pi projects. We’Re going to be focusing on the Arduino today. Now LCD displays have a lot of advantages and that they are outside from being low cost. They are also very low current, so they won’t take a lot of power, so they’re ideal for battery devices and they’re, certainly nicer than using a serial monitor in your project. So let’s take a look at the LCD displays, we’re going to be using, and also at a very interesting little shield. That I’m also going to show you how to use with the Arduino. Now the display we’re going to be working with today is called a 1602 display and it’s called that for a reason. It’S got 16 characters across on the row, that’s where the 16 from, and it has two rows now. You can also get a 1604 display which would have 16 characters and 4 rows. Now this little device over here is an i2c adapter. I squared C adapter. It allows you to use the i2c bus to communicate with the display and as you’re going to see that will really cut down on the number of wires. You need to connect to the display, so these are quite handy devices to have now. This is a shield for the Arduino and it’s an interesting shield.
It has a 1602 display on it. It also has a series of push buttons on it, and these six buttons can be used in your project now. What’S interesting about this display to me is actually the way the buttons are connected and I’ll show you that in a minute they aren’t what you might expect now. This is my little experimenters platform and I just wanted to show that to you I’ve built that just so we can do our test today. What I did is, I took a 16 2 o2 display and I soldered a female header strip on the top. Now this is not the normal way. You’D do things. Normally you would solder a header strip on to the bottom of the display and you’d, probably solder a male one on to it, or you would connect one of these. I 2c adapters directly on to the pins of the display, but I chose to do this for a reason, although it’s not a practical reason, because you could never use this display in a project with this connector sticking up, it allows me to connect the wires from The Arduino to the display quite easily so I’ve just done this or prototyping purposes. So now that you’ve seen the display let’s take a look at the pin outs on the display. Now, here are the pin outs for the LCD 1602 display pin 1, which is often labeled VSS, is the ground pin for the display, pin 2, which can be labeled VDD is the 5 volt power supply for the display? Pin 3, which is labeled vo? Is the input pin for the brightness control for the display pin 4, which can be labeled rs? Is the register select, pin, pin 5, which can be labeled RW? Is the readwrite pin, pin 6 labelled e n? Is the enable pin, pin 7 through 14? Are the parallel data input pins pin 7? Is data 0 pin 8? Is data 1 10 9? Is data to pin 10? Is data 3 pin 11? Is data 4 and 12? Is data 5 pin 13? Is data 6 and pin 14? Is data 7 pin 15, which is sometimes labeled with an A is the anode of the backlight LED and pin 16, which is often labeled with a k? Is the cathode of the backlight LED now the display works on parallel data and takes in one bite at a time? This requires 8 connections, which is a lot of connections to make to a microcontroller.
You can also run the display in a half byte mode and in this case, data pins d4 through d7, are used to transmit one half of the byte at a time. This cuts down on the number of wires you’ll need to run to your interface. So now that we’ve seen the pin outs of the LCD 1602 it’s time to get experimenting with one we’re, going to hook one up to an Arduino and run a number of experiments. Now the Arduino IDE comes with a library called liquid crystal and we’ll, be using that library and some of the example sketches that come with that library. So for our first few experiments, you won’t even need to write any code after that we’re going to modify a couple of those sketches in order to create our own sketch can add a few more components to build an interesting project with our LCD display. So let’s get going and see how we hook our Arduino up to the LCD display now here’s how we’ll be hooking up our experiments. We will need an Arduino Uno. An LCD 1602 display module, a 10k trim pot or variable resistor, and a 220 ohm resistor. We’Ll start by connecting the arduino 5 volt out to the displays 5 volt in that’s pin 2 on the display labeled VDD next we’ll take the Arduino ground and connect it to the display ground, which is pin 1 on the display. Labeled VSS we’ll take both ends of our trim pot and tie them across to 5 volt and ground lines from the Arduino we’ll then take the wiper from the trim pot and connect it to the display.
Brightness control, that’s, pin 3 labeled vo Arduino digital pin 12. Will connect to the display register, select, pin that’s, pin 4 on the display, labeled RS. We will ground the displays readwrite line, that’s pin 5 on the display. Labeled? U RW, our dueo digital pin 8 will be connected to the display and able line. That’S pin 6 on the display labeled en Arduino pin 5 will be connected to displays data pin 4 that’s pin 11 labeled D for our dueo digital pin. 4 will be connected to display data line 5 that’s pin 12 label d 5 Arduino pin 3 will be connected to display data line 6 that’s pin 13 label D 6 on the display. Our dwee no data pin 2 will be connected to display, pin data 7 that’s pin 14 labeled d7 we’ll tie one end of the 220 ohm resistor to 5 volts. The other end of the resistor will be connected to the display backlight anode connection, that’s pin 15 labeled a on the display and finally, the ground from the Arduino will be connected to the display. Backlight cathode that’s pin 16 labeled K on the display. Now the sketches were going to be looking at or included, as example, sketches in your Arduino IDE. So the way you access them is to go into file and then go to examples and go down to examples for any board and you’ll find liquid crystal and you’ll see a number of sketches that you can try with your liquid crystal display.
Now these sketches are set up to have the display wired, as I showed you in the wiring diagram, so the first one we’re going to try is HelloWorld now, after some credits as to who wrote the sketch and description as to how to connect the LCD, we Get into the actual sketch itself now, first of all, like all of these sketches, we include the liquid crystal library. We then initialize, the library. First of all, we define a number of integers, and these integers represent the pins we’ve connected the LCD display to then we create an object, called LCD and define it with those pin numbers. Now, if you wanted to change the way you’ve got it wired, you would just change these pins. Accordingly, in the setup we set up the LCD for the number of columns and rows so we’re using 16 columns and two rows. So we use LCD begin 16, 2 and then we print the message for the LCD and it’s. Just as simple as doing an LCD print and the message you’re printing is hello world. You can experiment, of course, by changing that message as long as it’s 16 characters or less it’ll fit on your display now in the loop we’re going to set the cursor to the next column. So we do a set cursor command and we’re going to set it to position 0 and column. Number 1. Now keep in mind. The top column is column number 0, so the second column is number 1 after this we’re going to print the number of seconds.
Since the reset so we’ll take the millisecond command and we’ll divide it by 1000 and we’ll print that so milliseconds divided by a thousand, will give you a second so every time a second occurs, we print the number and then we go through the loop and do It over and over again and it’s as simple as that so let’s take a quick look at how that looks once it’s running so here’s the hello world sketch and as you can see, it is printing hello world on the first line and on the second line In the first position, we’re counting the number of seconds since the Arduino was last reset now I’m going to adjust the trim pot that controls the brightness and, as you can see at one extreme, you can’t see the display at all. Then you start to see it. It gets brighter and then you start seeing the actual character outlines at the back. If you bring it too far up so you need to come to a sort of happy medium between the two something like this. So now let’s go and take a look at another example sketch the next example we’re going to look at is the scroll sketch. Now this again is found in the example section for the liquid crystal, and this, as the name would imply, shows you how you can scroll text scrolling is a convenient thing to be able to do it’s a way of overcoming the limit of only having sixteen characters.
In a row on the display and it’s also a way to draw attention to the text, so the sketch starts off identically to the last one. We include the liquid crystal library we define the pins were using and set up an LCD object with those pins defined. The setup is very similar as well. We define the number of columns and rows with an LCD begin and we print a message to the LCD so again, we’re going to print hello, world and we’ll delay things for a second. Now we move into the loop, and this is where we do the scrolling and we’ll juice, three Scrolls in the loop. The first one is to scroll 13 positions to the left, so we set up a four next counter. So we’ll do a four int going from 0 to 13 we’ll advance. The variable called position counter every time by 1 and then we will do an LCD scroll display, left we’ll, wait a bit we’ll delay and then we’ll go and do it again. So, every time we this we’re going to scroll one position left and we’re going to do this 13 times, then we’re going to scroll 29 positions to their right. So basically we are going to do the same thing. We’Ll set up a counter except we’re, going to go from 0 to 29. This time and we’re going to do a scroll display right to command, wait a bit and do the whole thing again and then once again, we’re going to scroll back to the center, which means you’re going to scroll.
The display left again. We’Ll set up the counter from 0 to 16. Do an LCD scroll display left, wait a bit and do it again. Finally, at the end of the loop we’ll wait for a second and then we’ll start the whole loop all over again. So let’s take a quick look to see what that looks like once. We load it up to the arduino and here’s the scroll sketch in action, and it does pretty well what you’d expect it to do: it’s scrolling the hello world back and forth on the display and then pausing for a second after a complete iteration of the loop. So now, let’s move on to one more example: sketch the final demonstration we’ll be looking at is the custom character demonstration now custom characters can be useful when you want to display a character on the LCD display. That’S, not part of the standard ASCII character set. You can define your own custom characters, but keep in mind that a character on the LCD display is done in a five by seven matrix, so your character needs to be done within the confines of that matrix. Before we run this sketch, we need to add one additional component to our circuit, a potentiometer which we will connect as follows. We’Ll connect five volts in the Arduino to one side of the pot will connect the opposite side to the ground on the Arduino and we’ll connect the wiper to the analog 0 input on the Arduino.
Now, let’s take a look at the custom character sketch the sketch starts, just as our previous sketches have we’ve included the liquid crystal library and we’ve defined the connections to our LCD display. Then we create an LCD object using those connections. Now we need to mix and characters each one of our characters is defined as an array of bytes, the arrays have eight elements to them. The first one we’re going to call heart now each of these entries in the array determine which elements are turned on and turned off within the character display on the LCD. Our next one is called smiley and frowny, and we have one called arms down and arms up. These are a little stick, man with his arms facing down and his arms facing up now in the setup we initialize the LCD, as we did previously through the size of our display, which in our case is 16 by 2, and now we need to actually create The characters so we used to create car function now each character’s defined with a number. So the heart we defined earlier is number 0. The smiley is number one. The frowny array is number two, etc, etc. Then we’ll set our cursor to the top left corner and we’ll print, something on the first line: we’ll print I space and then we were right character, number zero, which is the heart, then we’ll write Arduino, then we’ll write character, number one which is the smiley.
So the line should read: I heart Arduino, with a smiley at the end of it now let’s go into the loop now we’ll read the potentiometer using the analog, read command and define that as sensor reading next we’re going to map that result to a range of 200 to 1000, so sensory reading can be anything from 0 to 1023 and we’ll use the map command to map that 200 to 1000 and assign that to the variable delay time now, we’re going to set our cursor to the bottom row in the fifth position and We’Ll draw a little man with the arms down so that’s element: number 3: the arms down. Then we’ll delay by the delay time that we’ve determined by the position of the control and we’ll draw the little man with the arms up and we’ll delay him again by the same delay and we’ll repeat over and over again. The effect of this is, as we turn the control the little man will wave his arms up and down at a different speed. So now that you’ve seen the sketch let’s take a look at it and so here’s our custom character sketch you can see it says I heart Arduino with little smiley and you can see her a little stickman down here and he’s waving his arms up and down. He’S doing an alteration between the arm up and arm down, and so, if I turn the control all the way to one extreme, his arms move very slowly: I’m assuming it’s a heat, and if I go to the other extreme he’s, much more excited he’s waving.
His arms up and down a lot quicker. I hope you can see that and so that’s the custom character sketch now, as we’ve seen from the previous demos, using the LCD display with the liquid crystal library, is quite simple and we can build a number of projects. Just using that library and an Arduino and adding sensors and switches etc to our circuit to to make a complete project. However, one thing you may have noticed is that we’re using a lot of the isle lines on the arduino, even though we’re only using four data connections instead of eight, we still have control connections that also go to the display and, as a result, on the arduino Uno we’ve used half of the digital io connections. Now you can use little tricks like using the analog inputs as additional digital io lines if you wish but there’s another method of cutting down the number of connections that the LCD display and thus freeing up the rest of the io ports for other things, and that Method is i2 c or i IC, inter integrated circuit communications. Now this is a very important Arduino concept and it certainly goes far beyond just using LCD displays. You can connect all sorts of devices using i2c. You can even connect to our dwee nose together or an Arduino and Raspberry Pi, or several Arduino, and a Raspberry Pi and communicate through i2c it’s, a fascinating subject that I intend to do an entire video about one day.
But for today we are going to simply look at using i2c to drive our display using that little adapter that I showed you at the beginning of the video. So let’s take a quick look at how I to see works and then we’ll. Look at the adapter that we’re going to use in order to use i2c with our liquid crystal display. The i2c or inter integrated circuit bus can also be referred to as the I squared C or III C bus. It was developed by Philips semiconductor in 1982 for communications between integrated circuits and televisions. The bus is used to connect multiple devices to one micro controller or to connect multiple microcontrollers and micro computers to each other. The i2c bus is generally used over short distances. Usually a metre or less the i2c bus consists of four pins VCC, which can be 3.3 or 5 volts a ground pin the SDA pin, which contains the data on the bus and the SCL pin for the clock signal. Originally, the i2c bus was available in two speeds: 100 kilohertz or 400 kilohertz. Additional speeds have been added fast mode Plus, which is 1 megahertz high speed mode, which is 3.4 megahertz and ultra fast mode, which is 5 megahertz. The data and clock lines on the bus use pull up resistors to bring the signals high when they are unused. The i2c bus uses a concept of masters and slaves. Generally, we have one master and multiple slaves.
Every device on the bus has a unique address in operation. The master calls the slave address to address the slave and retrieve data or descendant data, so here’s a little adapter we’re going to be using to convert our LCD displays to use the i2c bus. These are very inexpensive and they’re. Quite simple. To use they’ve got a 4 pin connector on them, and this is where you connect the i2c bus connections. They’Ve got a little control on them and that’s how you control the brightness of the LCD there’s a jumper here. So you can turn on and off their internal power LED and they’ve also got three little jumper points over here that you can solder over now. What those three jumper points are for are to change the i2c address of the device now since we’re only using one eye to see device in our experiments. We won’t need to worry about this, but if you’re using multiple eye to see devices, you can’t have two devices with the same address, so this will allow you to resolve any conflicts that you might have with the i2c address now a normal operation. What you would do is you would take one of these mount it on the back of your LCD display and just solder it on over here, and then you end up with a little backpack device, which is quite convenient and very easy to mount now. Of course, I’m using my experimenters platform, so I’m, just going to plug mine on platform like that, and it fits on there very nicely – and I can just add my i2c connections up here and experiment with it.
Obviously, this isn’t very practical because it sticks up beyond the front of the LCD display. But again this is just for experimenting and prototyping. So now that you’ve seen the device let’s take a look at how we hook it up the hook up for our eye to see experiment is quite simple: you will need an Arduino Uno and an LCD display with the i2c adapter connected to it. The VCC from the i2c adapter will be connected to the 5 volt output on the Arduino. The ground from the adapter will be connected to the arduino z’ ground. The SDA connection on the adapter will be connected to the SDA connection on the arduino uno. If your arduino does not have an SD, a connection connected to analog, pin a for the SCL connect pin will be connected to the SCL connection on the arduino. If you do not have an SC L connection, use pin a 5 now before we start RI 2 C experiments will need to determine what the addresses of the adapter that we’re using now. You may already know this address, but if you don’t, this is an easy way to find out. This is a scanner that was written by Nick gammon and I’ve got the code for this up in the article that’s associated with this video load. This up to your Arduino and then go into your serial monitor, and this will display the address of all the i2c connections available to the Arduino right now, there’s, only one which is, of course, our LCD adapter, so it’s this number here, we’re looking for the 3f Hexadecimal number is the address of my adapter and I’m going to be using that in my sketches, so let’s take a look at the first sketch we’ll be using with our LCD display connected with the i2c adapter.
Now, in order to use this demo and the subsequent demos, you’re going to need to install a new library and you’re going to need to grab the library from the link that I provided in the article associated with this video you’ll get the latest version of the Library, which is called new liquid crystal and you’ll download a zip file to a location on your hard drive that you’re familiar with after that, in order to install it you’ll go into sketch, include library, add zip library and navigate to the place where you downloaded. It then you’ll select the library and click OK to install it. I’Ve already installed it. So I won’t go through the whole process right now, once it’s installed, we can begin to look at this sketch now. The first library we include is the wire library, the wire library, is an art library, that’s built into your arduino ide and is for using the i2c bus. Then it will include the new library we install the new liquid crystal library after this we’re going to define some LCD pin outs. Now this is the LCD pin out pattern for the i2c adapter. You are using it’s, not the pin out pattern for the Arduino, because the Arduino is connecting through i2c. Now this is the pattern for the adapter I’m. Using there are a couple of different ones and in the article associated with this, video have listed some other combinations in case yours, doesn’t match.
The next thing we do is we define the address for our eye to see adapter now, you’ll recall from the last sketch that I determined that my adapter was at hexadecimal 3f. If yours is different and many of them are at to 7, you need to change this line to match where your adapter is, then we create an LCD object using the information that we just provided. Above now, the new liquid, crystal library, actually is compatible with the original liquid crystal library and all of the same commands will work. So these will look very familiar. We do an LCD begin to set up for display as 16 by 2, then we’re going to print on the first row, we’ll set the cursor to position 0 0 and we’ll print hello world. The NAFTA bet will delay a second and, on the second row, we’ll print. How are you will 8 wait 8 seconds and then we’ll clear? The display now we’ll go into the loop and we’re just going to demo a few of the features of the display in the i2c interface in our loop. The first demo is to flash the backlight so we’ll set our cursor at position: 0 0 and we’ll print backlight demo to the display, then we’ll set the cursor to the row below and we’ll print. Flash 4 times will delay for 3 seconds and then clear. The display then we’ll flash our backlight 4 times we’re going to go through a loop, so we set up an integer called eye and we’ll go through the value of 0 to 4 we’ll increment by 1 and during each increment we’ll do an LCD backlight, which turns The backlight on will delay for a quarter of a second, then we’ll do an LCD, no backlight, which will turn your backlight off and will delay for another quarter.
Second, it will repeat this four times to flash the backlight four times when we’re done we’ll turn the LCD backlight back on now for demo 2 we’re going to do a scroll. So once again, we’ll set the cursor to position 0 0 will print scroll demo will delay for one and a half seconds and then we’re going to use the auto scroll command and we’re going to start printing the number 0 to 9 after the word scroll demo. So again, we’ll use a for loop, we’ll call our variable. This car and we’ll have a go from a value 0 to nine, because we’re looking for something that’s less than ten and we’ll increment by one every time and on every intrument, we’ll print this car and then we’ll delay for half a second and we’ll continue to Do this so the number zero to nine should start printing and the display should start scrolling. Then we’ll turn off. The scrolling will clear the screen delay for a second and go back up and repeat the loop over again. So now that you’ve seen our demo sketch let’s take a quick look at it in action, so here’s our demonstration starts off with the hello world. How are you and it moves into the loop? The first thing is the backlight demo, so it flashes it four times and then the scroll demo and it repeats the backlight demo and the scroll demo, and it will continue to do this infinitely so now let’s build something more practical with our LCD display.
So we’ve seen how we can connect our LCD display up to our Arduino in two different fashions, both directly and using i2c and we’ve run. Some demo sketches to illustrate how everything works, but I think now it’s time to build something practical so for our next demonstration. I’M, going to build a temperature and humidity gauge using an LCD along with a dht22 temperature sensor, so let’s take a look at how that’s going to work in order to build our temperature and humidity sensor. We’Ll need to add a dht22 temperature and humidity sensor device to our circuit. We hook, pin one of the dht22 to the 5 volts on the Arduino. Pin 2 of the dht22 is its output, and that goes to digital pin 7 on the Arduino. Pin 4 of the dht22 is the ground connection, and this goes to the Arduinos ground. Pin 3 remains on enacted now that we’ve hooked it up let’s take a look at the sketch we’ll need to make it work. Our temperature and humidity sketch is going to make use of some libraries from Adafruit, as well as the libraries we’ve already installed. I’Ve talked about these libraries in an earlier video, specifically the one in using the 8c SR 0 for ultrasonic sensor, and I went into detail on how to install it. Essentially, these can be installed from your library manager. You’Ll need both the unified sensor library and the DHT libraries from Adafruit. I also have details on the article associated with this video on the website.
In case, you need further details on installing those libraries once you’ve installed the libraries you can begin to sketch. We start, as we did with the last sketch by including the wire library for i2c and including our liquid crystal library, the new liquid crystal library, then we’ll include the DHT library from Adafruit. Once again, we define the LCD pin out that our adapter uses and we’ll set up the adapter address. Again. You may need to change these two lines depending upon your adapter. Now we’ll define a couple of pins through the dht22 will define, pin 7 as the output connection and we’ll define the type of sensor as a DHT 22. As a DHT library can handle a number of different sensors, a game will set up the connections to the LCD and create an object, called LCD and define a couple of variables, one which defines our humidity and one which will hold our temperature value after that, we’ll Set up the DHT sensor for normal operation, we then go into our setup in the setup. Once again, we set up our display type as a sixteen by two and we initialize the dht22 and now into the loop. Our loop starts with a two second delay. This is required, so the dht22 sensor can stabilize then we’ll get the humidity and temperature values from the dht22 and we’ll store them in two variables we defined earlier. We then clear our LCD display and will print the temperature on the top line, so we’ll set the cursor at zero, zero print, the word temp in a couple of spaces, print the actual temperature and then a space and ac, because we are measuring our temperature in Degrees Celsius, then we’ll move to the next line.
We’Ll set the cursor down to the beginning of the next line will print humid with a space after it print the humidity value and then a space and a percent symbol. And then we simply go back up and repeat the loop over and over again, so every two seconds we should get a new temperature and humidity reading. So now that you’ve seen the sketch let’s take a peek at our temperature and humidity sensor in action. Okay, here’s our temperature and he made of these setup an app tune and, as you can see, it seems to work pretty well it’s. Reading the current temperature and humidity in the workshop, which, as you can tell, is a fairly pleasant twenty one point: eight degrees Celsius and 40.2 humidity. If you’ll notice, the display is flashing, every couple of seconds and you’ll occasionally see it refresh itself with a different number. As it’s taking a new reading about every two seconds so now that we’ve seen that let’s move on to some other experiments now for our final demonstration, I’m going to tell you how to use one of these LCD keypad fields, these are very popular fields for the Arduino they have an LCD display, a sixteen by two identical to the one we’ve been using plus they have a number of push buttons here: five buttons, plus a reset button. Now, like any arduino field, this this plugs into the top of an arduino. So i’ve got an email over here, it’ll also work on omega and they brought up the unused connections to a bunch of solder pads, and you can solder wires to these or solder terminal strips to these to make additional connections of the arduino.
But when you’re prototyping was something like this, it can be a little bit hard to use. Yes, you can solder terminals on to here, but by far an easier that is to use another field like this one over here. This is called a screw field. There are similar fields to this and what it does is you plug this onto the Arduino first, so I’ll put that on, and then you take your shield and plug it into the top of the screw shield like so, and so now you have a number of Terminals over here with little screws on them and you can connect wires to all of the different terminals on the Arduino, so it exposes all the terminals, even though you’ve got a shield on top. So this is very handy for prototype into something like this. So let’s take a look at how this LCD keypad field works and then I’ll show you a sample sketch that you can use to demonstrate its operation. The LCD keypad shield provides a convenient method of adding a liquid crystal display, along with a number of keys to your Arduino project. In addition to the LCD display, the keypad consists of five push buttons plus a reset button. The field also brings out the unused connections to the Arduino to solder pads so that you can use them in your project. The arrangement of the five push buttons on the keypad shield is rather unique. Instead of using digital io ports, there is a resistive divider array that is connected to an analog input port on the Arduino.
Each push button will deliver a different voltage to the analog input port and you can use your code to determine which button was pressed. The LCD keypad shield uses the following connections to the Arduino analog input. A zero is used for the push button array pin four is used for data line four on the display, then five is used for data line. Five on the display. Pin six is used for data line six on the LCD display and pin seven is used for data line. Seven on the LCD display. Pin 8 is the RS line to the LCD display. Pin nine is the enable line to the LCD display and pin 10 on the Arduino is connected to the backlight LED on the LCD display. Now here’s a sketch we can use to demonstrate the operation of the LCD keypad shield will start by including the liquid crystal library and then we’ll set up an LCD object based upon the pin notes that the keypad shield uses. Next, we define a number of constants. Each constant represents one of the push buttons. We also have a constant if none of the buttons have been pressed, we then define an integer to hold the value of these constants it’ll represent the current button that has been pressed. We define another integer to hold the analog value that we read from the a zero pin when a push button has been pressed. Remember each button will give us a different voltage level.
Next, we define a function to actually read the buttons we call it read: LCD buttons and it’s going to return an integer now in our function. The first thing we do is we read the value of analog port, a zero, which is where the push buttons are now. These are the values of the manufacture. States will happen when you press the various buttons we’re going to add 50 to each of those values. Just to be certain because there are in tolerances and the resistors and all that now in the first line, if we get a value of over 1000, then none of the buttons have been pressed and we’ll return. The button none value the value is under 50. Then the right button has been pressed. If that doesn’t evaluate, we check to see if it’s under 195 – and that means that the UP button has been pressed and we continue that for the other buttons if we don’t get a valid response, will also return a value that says no button is impressed. Now we move on to our setup. We set the LCDs display for a sixteen by two display on the first line. We set the cursor to the first position and we’ll print a message on the first line that says push a button. Then we go into our loop. We go to the second line, ten spaces over and going to display on this line a counter that counts seconds, since the project has been reset.
This way we can demonstrate the use of the reset button, which isn’t one of the buttons tied to the resistive array, but it’s just tied to the reset and on the arduino. Now we go back to the beginning of the second line and we’re going to call the function that we define to read the buttons and we’ll get a value that we place into the LCD key variable. Then we’ll use a switch statement based upon the value in that LCD key. So if we get button right for going to print right and then break out of the switch statement, if we get the left value, then we’ll print left and again print break the up value, will print up, etc, etc through all of the buttons. And then we just repeat the loop over and over again remember every time we repeat the loop we’re going to display another second until we press the reset button. So now that you’ve seen the sketch let’s take a look at it working so here’s our keypad test right now, it’s displaying that I’ve not pressed any buttons, and you can see the counter on the side. Counting up the seconds now, I’ll just press a button, that’s the UP button and, as I hold it down it says up. When I release it, it says none down button, the right button, the left button and the select button. Now, if they hit the reset button, you’ll notice that my counter goes back.
It starts counting from zero and that’s our LCD keypad demo, and so there you have it. Lcd displays are a very effective way of adding a display to your Arduino project, they’re, inexpensive and very easy to use. Now you will find an article on the drone bot workshop comm website that goes along with this. Video and it’s got more details than what I’ve covered in the video, as well as the sketches that I’ve used and links to things like the new liquid crystal library. That you’ll want to use for your eye to see displays and also for your regular connected LCD displays, because you can use all of the code. We saw in the example code with the new liquid crystal library for improved performance. Now, if you have any questions about LCD displays let’s, please leave them in the comments below. I love getting your comments and I do try to respond to them as often as possible and if you haven’t yet please subscribe to the channel.
arduino if Video
arduino if news
Posted on Wednesday October 09, 2019If You’re a DIY Tech Lover, This Arduino Kit Subscription Box Is a Must Futurism … Continue Reading »
Posted on Friday October 11, 2019Best CNC Software for Arduino All 3DP … Continue Reading »
Posted on Saturday September 28, 2019Learn Arduino, Raspberry Pi, or CAD with these e-books that are on sale Mashable … Continue Reading »
arduino if Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr
Originally posted 2015-12-22 01:20:44.