1 00:00:00,000 --> 00:00:07,259 Hello. In this exercise, we are going to learn how to use the LCD screen, and we are going to 2 00:00:07,259 --> 00:00:12,900 connect it to the Arduino board using again a serial connection. There are serial connections 3 00:00:12,900 --> 00:00:19,399 with the computers, but here we're going to use a specific serial connection. And then we can find 4 00:00:19,399 --> 00:00:25,760 here. Here we can see the digital connectors we already know, then, and if we move to the left, 5 00:00:25,760 --> 00:00:30,640 we would find this one that is called the SCL and one that is called the SDA. 6 00:00:31,679 --> 00:00:37,899 These two connectors, these two pins, are used to transmit serial information and we can use 7 00:00:37,899 --> 00:00:45,179 them to send information to different devices, not just one. So, for example, here we have the SCL 8 00:00:45,179 --> 00:00:50,859 connection, the yellow wire, and here you can see that it is connected to the SCL connection to the 9 00:00:50,859 --> 00:00:57,000 screen. And here you can see that the yellow wire continues and goes to a new SCL connection. 10 00:00:57,740 --> 00:01:03,060 So the two of them are using the same wire, the same connection, and the same for the SDA 11 00:01:03,060 --> 00:01:09,480 connection, the green wire. It is connected from the Arduino board to the first one and then to 12 00:01:09,480 --> 00:01:24,549 the second one. And we also have two other connectors. Ground, that is connected to ground, 13 00:01:24,549 --> 00:01:29,689 obviously, and the power source there, and the red wire that is connected to 5 volts. 14 00:01:30,730 --> 00:01:37,530 This is the way we connect different screens, LCD screens, to the Arduino board. We can connect 15 00:01:37,530 --> 00:01:47,469 several of them. Here we only have connected two. But if we had a third one, we would be able to 16 00:01:47,469 --> 00:01:55,069 connect it the same way. Just continuing the different wires. Each LCD is going to be defined. 17 00:01:55,069 --> 00:02:03,689 Click on it. We want to be defined by the address. For example, this one, the address for the first 18 00:02:03,689 --> 00:02:09,849 one is 34 and the address for the second one is 32. And there's another parameter here, 19 00:02:10,169 --> 00:02:15,169 which is the protocol kind of language we're going to use to program our LCD screen. 20 00:02:15,750 --> 00:02:20,189 We use this protocol and the same, and it is the same for the two of them. 21 00:02:20,189 --> 00:02:26,990 different addresses but the same protocol. We need to use different addresses because using 22 00:02:26,990 --> 00:02:32,229 different addresses, the Arduino board will be able to know to which one it is speaking or from 23 00:02:32,229 --> 00:02:39,009 which one it is receiving information. That's why we need different addresses. This is the way we 24 00:02:39,009 --> 00:02:54,189 connect different devices. The LCD screen can be found here. If you type LCD here, there are two 25 00:02:54,189 --> 00:03:00,830 devices, and the one we use is the I2C, because I2C is the serial protocol we are going to use 26 00:03:00,830 --> 00:03:19,319 to connect it. So, what about programming it? I want to open the block window to make it bigger 27 00:03:19,319 --> 00:03:24,719 and easier to have a look at the codes. The first thing we need to look at every code, 28 00:03:25,159 --> 00:03:30,500 every block we are going to use, is in the blue library, because the Arduino, I mean, 29 00:03:30,500 --> 00:03:37,460 the LCD screen will receive information from the Arduino board. That's why we are using output 30 00:03:37,460 --> 00:03:44,780 blocks. All of them are blue. Here, because we have two screens, we are going to set the two of 31 00:03:44,780 --> 00:03:52,800 them, and we are going to use this block, configure our typo to LCD. For example, address 32 will be 32 00:03:52,800 --> 00:04:08,639 number 1, so 32, this 1 is meant to be number 1, the lower 1, and the lower 1 is going to be 34. 33 00:04:08,659 --> 00:04:14,840 number 2. And we use this protocol, the same protocol is here, because both of them, 34 00:04:15,120 --> 00:04:19,899 the LCD screen and the Arduino board, both of them need to speak the same language. 35 00:04:26,750 --> 00:04:31,089 So number 1 will use this language to communicate with the Arduino board. 36 00:04:31,689 --> 00:04:38,470 It's going to be connected in address 32. The second one, same protocol and 34. 37 00:04:38,470 --> 00:04:46,670 So this way we can connect several devices. There are addresses from 32 to 39. So we can 38 00:04:46,670 --> 00:04:53,149 connect 8 different devices using this protocol. And so be careful with addresses, they are very 39 00:04:53,149 --> 00:05:17,160 important. What other blocks do we have? We have this block. First of all, in LCD 1, or 2, or 3, 40 00:05:17,160 --> 00:05:24,120 or 4, we can do different things. For example, we can switch the light on, we can erase the screen, 41 00:05:24,540 --> 00:05:29,339 switch the light off. What happens if we switch the light on for the first one? 42 00:05:36,209 --> 00:05:42,029 If we start the simulation, the first one is on, but not the second one, and that's okay. 43 00:05:42,910 --> 00:05:49,970 We can change, we can switch the second one on, and we simulate it again. And now number 2 is on. 44 00:05:50,910 --> 00:05:56,550 Before continuing with the blue blocks, I want you to realize that we are using this kind of loop. 45 00:05:57,189 --> 00:06:09,490 Not a real loop, "Al iniciar". This part of the program, and this one, "siempre", forever, 46 00:06:09,949 --> 00:06:14,850 is a real loop and not the first one. These are the two parts of the program. 47 00:06:15,850 --> 00:06:19,790 In this new version of Tinkercad, these two blocks have been included. 48 00:06:20,810 --> 00:06:25,589 This one is the setup. "Al iniciar" means that they are going to be run just once. 49 00:06:25,829 --> 00:06:31,870 and then "siempre" means this is the real code. I mean, the part of the program that will be 50 00:06:31,870 --> 00:06:39,009 repeated again and again. So "Al iniciar", we are using these two blocks, configure our LCD here, 51 00:06:39,430 --> 00:06:44,790 because we only need to set it up once and no more than that. And the rest of the code that 52 00:06:44,790 --> 00:06:51,750 will be repeated again and again is here. So I'll go back to "siempre", forever, and for example, 53 00:06:51,750 --> 00:06:58,949 we can switch the light on. We can also erase the screen. We are going to erase the screen later 54 00:06:58,949 --> 00:07:04,769 but for the moment we are going to print a character. For example we are going to print 55 00:07:04,769 --> 00:07:11,089 we are going to switch number one on just a light. You can print things if the screen is off. 56 00:07:11,990 --> 00:07:18,550 For example we are going to do it later don't worry. For the moment just with the light on 57 00:07:18,550 --> 00:07:25,250 let's go to print hello world number one. If you click start the simulation, number one is, 58 00:07:25,569 --> 00:07:30,990 there's a problem, it is repeating again and again and again hello world, hello world, 59 00:07:31,350 --> 00:07:43,660 hello world. How can we solve it? We can solve it, for example, using boropantala, 60 00:07:44,100 --> 00:07:49,240 but if we print and we erase, there's no time to see anything. So let's use a espra. 61 00:07:49,240 --> 00:07:56,019 So we will print hello world, we will wait for 1 second, and then the screen will be erased again. 62 00:07:58,600 --> 00:08:02,600 And we need a second, Espera, because this way it will be a kind of blink. 63 00:08:03,500 --> 00:08:05,339 Can you imagine how will it work? 64 00:08:06,800 --> 00:08:11,860 Hello world, for 1 second, then nothing for 1 second, then we start again. 65 00:08:12,779 --> 00:08:14,220 Let's start the simulation. 66 00:08:15,300 --> 00:08:16,060 Can you see? 67 00:08:16,779 --> 00:08:18,220 It's a kind of blinking. 68 00:08:18,819 --> 00:08:28,660 This block, the first one. 69 00:08:28,899 --> 00:08:34,639 There's no need to be the forever block, it can be here. This way the screen will be switched on 70 00:08:34,639 --> 00:08:40,340 just once in this code. So let's start the simulation again, and you will see that it 71 00:08:40,340 --> 00:08:54,110 works the same way. Hello world, nothing. Now, I want you to see that switching the light on 72 00:08:54,110 --> 00:08:59,549 doesn't mean that this one will not work. There is no light, but we can see the code. 73 00:09:26,809 --> 00:09:29,909 So, but there are more instructions to take into account. 74 00:09:30,950 --> 00:09:33,350 This one is really, really interesting. 75 00:09:34,429 --> 00:09:36,330 It means, establish a position. 76 00:09:37,350 --> 00:09:39,830 Position means where we want to print the character. 77 00:09:40,830 --> 00:09:44,730 For example, imagine we want to print the character in position number, 78 00:09:44,730 --> 00:09:47,929 well, first of all, there are columns and rows. 79 00:09:48,909 --> 00:09:49,789 Every LCD. 80 00:09:50,970 --> 00:09:53,970 I'll run the simulation, it will be easier with light. 81 00:09:53,970 --> 00:10:06,240 There is a first row, there's a second row, and there are columns. This is the row number 0. 82 00:10:07,039 --> 00:10:18,259 This is row number 1. This is column number 0, 1, 2, 3, 4, until 15. So, with this block, 83 00:10:18,559 --> 00:10:24,980 establish a position, we can decide where we want to print. For example, imagine we want to print 84 00:10:24,980 --> 00:10:31,720 in the first row, number 0, position the middle, more or less number 8. Instead of typing, 85 00:10:31,980 --> 00:10:38,559 hello world, we will type something like that. Let's have a look. It is printed there in the 86 00:10:38,559 --> 00:10:45,159 middle of the position. We can change position, for example, instead of number row, I mean column 87 00:10:45,159 --> 00:10:53,559 8, we can choose column 4. And instead of using row 0, we can use row 1. Now the position is 88 00:10:53,559 --> 00:11:00,279 different. Row number 1, remember this one, the upper one is 0 and the other one is 1. 89 00:11:01,200 --> 00:11:08,220 Position 0, 1, 2, 3, and 4. So we can decide where we want to print things. 90 00:11:09,220 --> 00:11:13,039 Very, very important defining the different addresses for everyone. 91 00:11:13,980 --> 00:11:40,000 We can print in different LCDs. For example, I'm going to duplicate this block on this part. 92 00:11:40,000 --> 00:11:46,600 I want the program number 2, and I'm going to program it in number 12, row number 0. 93 00:11:47,559 --> 00:11:49,460 I'm going to print it in number 2. 94 00:11:50,419 --> 00:11:53,679 Instead of using this one, I'm going to use the slash. 95 00:11:54,419 --> 00:11:56,340 I'm going to erase them too. 96 00:11:57,340 --> 00:12:03,019 This way you can see that we can program different screens at the same time, because they have different addresses. 97 00:12:03,960 --> 00:12:05,039 Let's have a look. 98 00:12:05,039 --> 00:12:10,980 so we will have two different blinkings one for the first one the first one for the upper 99 00:12:10,980 --> 00:12:33,220 here this character here the second character i can also switch the light on for the second one 100 00:12:33,220 --> 00:12:41,139 and let's start the program again easier to see if the light is on so we have these different 101 00:12:41,139 --> 00:12:52,090 instructions configure our to define the program the language the code we are going to use we are 102 00:12:52,090 --> 00:13:01,970 going to use this one, so don't change it. And the addresses we are going to use, every screen 103 00:13:01,970 --> 00:13:11,909 will have a different address. We also have this block, the LCD, Active or Lose Defondo. 104 00:13:12,610 --> 00:13:18,629 We can erase the screen. There are other possibilities, but for the moment we are 105 00:13:18,629 --> 00:13:23,809 going to use just this one, Active or Lose Defondo, or switch it on and switch it off, 106 00:13:23,809 --> 00:13:30,950 or Bora La Pantala, erase the screen. We also have, establish a position, means define where 107 00:13:30,950 --> 00:13:39,480 you want to print, to define the position you want to print. And here, imprimir, means you are 108 00:13:39,480 --> 00:13:45,860 going to write something on this position, the one you have already defined. Really, really easy 109 00:13:45,860 --> 00:13:52,779 using these screens, connecting them, and you only have three or four types of blocks. Four types of 110 00:13:52,779 --> 00:14:07,470 blocks, nothing more than that. So the exercise for you is not going to be difficult. You will 111 00:14:07,470 --> 00:14:15,190 have to repeat. Again, we will have two screens. Start simulation, and they will behave this way. 112 00:14:16,149 --> 00:14:20,509 So it's not difficult, just kind of blinking, but with different positions. 113 00:14:21,549 --> 00:14:28,509 First position, second position, third position, fourth position. The first two positions in the 114 00:14:28,509 --> 00:14:35,450 upper LCD screen and the two following positions in the lower LCD screen. If you have understood 115 00:14:35,450 --> 00:14:42,429 the example, programming it, it's really easy. So that's all. All you need to know.