1 00:00:00,000 --> 00:00:10,000 [MUSIC] 2 00:00:12,482 --> 00:00:16,137 Hi everyone, my name is Patrick, and I'm a web developer from Sydney. 3 00:00:16,137 --> 00:00:21,142 I've recently been looking into using JavaScript to control devices such as 4 00:00:21,142 --> 00:00:24,068 Arduinos, the Elite Emotion, Ninja Blocks 5 00:00:24,068 --> 00:00:27,090 and hopefully very soon this, Pebble watch. 6 00:00:28,880 --> 00:00:31,456 Today I'm gonna be going over the 7 00:00:31,456 --> 00:00:35,860 absolute basics of controlling an Arduino using Node. 8 00:00:35,860 --> 00:00:37,650 We're gonna cover connecting up to a 9 00:00:37,650 --> 00:00:40,072 computer, getting Node to communicate with the 10 00:00:40,072 --> 00:00:44,699 Arduino, and hopefully, by the very end, blinking this LED light on and off. 11 00:00:46,020 --> 00:00:48,770 I'll be sticking to absolute basics here, so we're 12 00:00:48,770 --> 00:00:51,595 not going to be doing anything too advanced, hopefully. 13 00:00:51,595 --> 00:00:54,880 In future tutorials, I'll go over this and it gets a little bit more complicated. 14 00:00:54,880 --> 00:00:58,610 But, for this one, we're gonna show you how to get started. 15 00:00:58,610 --> 00:01:01,600 So, let's do that and get started. 16 00:01:01,600 --> 00:01:02,575 What is an Arduino? 17 00:01:02,575 --> 00:01:05,570 A lot of people have read the name online, or they've heard it 18 00:01:05,570 --> 00:01:08,790 mentioned, but they've never actually seen one in action, so this is it. 19 00:01:09,810 --> 00:01:12,288 It's a single board micro-controller that's 20 00:01:12,288 --> 00:01:15,130 open source which basically means that you 21 00:01:15,130 --> 00:01:19,190 can control electronics using a platform that anyone can build and tinker with. 22 00:01:19,190 --> 00:01:23,570 The people at Arduino are lovely enough to have open sourced it, which 23 00:01:23,570 --> 00:01:26,980 means that anybody can make their own Arduino boards that really want to. 24 00:01:28,180 --> 00:01:30,880 This one here, in particular, is the Arduino Uno. 25 00:01:30,880 --> 00:01:33,590 It's one of a variety, of different models 26 00:01:33,590 --> 00:01:35,750 that the lovely people at Arduino have released. 27 00:01:37,090 --> 00:01:38,520 You can have a whole range of components 28 00:01:38,520 --> 00:01:41,900 connected to it, too, like LED light bulbs, sensors, 29 00:01:41,900 --> 00:01:44,900 and even shields, which are things you kind of 30 00:01:44,900 --> 00:01:48,110 stack on top of Arduinos to add more functionality. 31 00:01:48,110 --> 00:01:51,340 This one in particular is a MIDI, shield which has 32 00:01:51,340 --> 00:01:54,432 the ability for, to play sounds, like a MIDI Keyboard does. 33 00:01:54,432 --> 00:01:56,610 34 00:01:56,610 --> 00:01:58,735 Node.js is a platform that takes 35 00:01:58,735 --> 00:02:01,550 JavaScripts, a scripting language most commonly used 36 00:02:01,550 --> 00:02:05,710 for web pages, unless you're writing up network applications such as web servers. 37 00:02:07,170 --> 00:02:11,780 We'll be using it today, to run a web server that'll talk to our Aduino. 38 00:02:12,900 --> 00:02:16,990 If you haven't used Node.js before, get started by 39 00:02:16,990 --> 00:02:19,799 heading over to Node.js.org, which I'm showing on screen here. 40 00:02:20,880 --> 00:02:22,570 Click that Install button and get it installed 41 00:02:22,570 --> 00:02:24,170 and running on your computer, so that you'll 42 00:02:24,170 --> 00:02:28,290 be able to continue and follow along with the example code that I'll be putting up. 43 00:02:28,290 --> 00:02:30,366 [BLANK_AUDIO] 44 00:02:30,366 --> 00:02:32,410 So why Node.js and Arduinos? 45 00:02:32,410 --> 00:02:34,160 Why link these two technologies together? 46 00:02:35,380 --> 00:02:38,770 Well, one of the strengths of JavaScript is that there are quite a few APIs 47 00:02:38,770 --> 00:02:42,360 out there, which you can join in different ways to make ideas come to life. 48 00:02:43,910 --> 00:02:45,600 Want to develop a robot that takes 49 00:02:45,600 --> 00:02:48,060 instructions from your Twitter followers, or a 50 00:02:48,060 --> 00:02:49,690 coffee machine that makes you a different 51 00:02:49,690 --> 00:02:51,430 style of coffee, depending on the weather outside? 52 00:02:52,720 --> 00:02:55,780 If you want to add a Leap Motion as an input 53 00:02:55,780 --> 00:03:01,230 device, or feed in data from your Jawbone or FitBit fitness products. 54 00:03:01,230 --> 00:03:02,760 The possibilities are going all the time. 55 00:03:02,760 --> 00:03:05,380 And JavaScript is becoming an easy to use bridge between technologies, 56 00:03:05,380 --> 00:03:07,520 because we've got a whole bunch of APIs we've got access to. 57 00:03:09,050 --> 00:03:10,362 And what is Johnny-Five? 58 00:03:10,362 --> 00:03:14,250 Johnny-Five, is one of those open APIs that makes JavaScript such 59 00:03:14,250 --> 00:03:17,150 a valuable language to be developing this sort of thing in. 60 00:03:18,180 --> 00:03:20,188 It allows you to control your Arduino using 61 00:03:20,188 --> 00:03:22,460 very similar functions to those that you'd use 62 00:03:22,460 --> 00:03:24,560 if you were programming it just using the 63 00:03:24,560 --> 00:03:28,180 Arduino platform that comes with the Arduino itself. 64 00:03:31,440 --> 00:03:32,980 We'll be doing a lot of this stuff in the 65 00:03:32,980 --> 00:03:36,590 tutorial that it's explaining here, so don't worry too much. 66 00:03:36,590 --> 00:03:37,720 But you can see, there's a lot of cool 67 00:03:37,720 --> 00:03:39,566 things that people have started to make with it. 68 00:03:39,566 --> 00:03:44,970 Wireless Nodebot Kinnect controlled robot arm, and LCD Running Man. 69 00:03:44,970 --> 00:03:48,950 So, you know, the possibilities get pretty exciting. 70 00:03:50,520 --> 00:03:55,290 Okay, to get started we'll need to connect our, our Arduino to our computer. 71 00:03:56,340 --> 00:04:00,660 So, we'll do this by connecting the USB port to our Arduino. 72 00:04:00,660 --> 00:04:03,550 It serves as both the power to the Arduino, 73 00:04:04,610 --> 00:04:07,990 and the way to upload software to our Arduino. 74 00:04:09,020 --> 00:04:11,220 As you can see, once you plug it in, you'll 75 00:04:11,220 --> 00:04:14,700 have the on lights flicker on, which is a good sign. 76 00:04:16,430 --> 00:04:18,860 In this demo today, I'll be doing a really 77 00:04:18,860 --> 00:04:23,380 basic example of turning this LED light on and off. 78 00:04:23,380 --> 00:04:26,868 I've already got the jumper leads in where they should be. 79 00:04:26,868 --> 00:04:30,828 So if you need to pause this to be able to follow along, feel free to 80 00:04:30,828 --> 00:04:35,320 pause it now, and put the jumper leads in, in the way that I've got them. 81 00:04:39,510 --> 00:04:41,170 Connecting up the Arduino is pretty simple. 82 00:04:42,210 --> 00:04:48,060 Connect up the green one here, to pin 13 on your Arduino. 83 00:04:48,060 --> 00:04:51,790 Then connect up the red one to the 5 volt pin. 84 00:04:54,680 --> 00:05:01,130 And finally we connect up the black one, to the ground pin. 85 00:05:01,130 --> 00:05:02,300 Doesn't really matter about colors, you can 86 00:05:02,300 --> 00:05:06,760 use whatever color jumper wire you'd like. 87 00:05:06,760 --> 00:05:12,220 Now that that's all done, we're ready to go into the software part 88 00:05:12,220 --> 00:05:17,515 of the tutorial with what code we've gotta run, and where to talk to our Arduino. 89 00:05:19,528 --> 00:05:21,130 Node application is extremely simple. 90 00:05:21,130 --> 00:05:25,560 We've only got two files, an index JavaScript file and a package Jason file. 91 00:05:27,240 --> 00:05:34,700 If you are new to Node the package Jason file is what we use to provide any details 92 00:05:34,700 --> 00:05:38,579 about the application, and what other Node modules are required for that application. 93 00:05:40,070 --> 00:05:43,286 So, to start with, I'll go over this packaged 94 00:05:43,286 --> 00:05:46,120 up Jason file, and show you what's going on. 95 00:05:46,120 --> 00:05:49,610 So, here we've got what the name of 96 00:05:49,610 --> 00:05:53,540 our application is in this case, Node in Johnny-Five. 97 00:05:53,540 --> 00:05:57,930 Can name this whatever you'd like, totally up to you, but keep it all to one word. 98 00:05:57,930 --> 00:05:59,460 It doesn't seem to like spaces. 99 00:05:59,460 --> 00:06:02,420 It'll start complaining at you, so definitely stick to one word. 100 00:06:03,870 --> 00:06:05,900 We've got a version number. 101 00:06:05,900 --> 00:06:08,020 Once again, you can pretty much use any version 102 00:06:08,020 --> 00:06:11,660 number you'd like, really, for simple basic test applications. 103 00:06:11,660 --> 00:06:16,240 I've called it 0.0.1, because really this application is very, 104 00:06:16,240 --> 00:06:19,130 very early stages and isn't going to be doing too much. 105 00:06:19,130 --> 00:06:21,280 So, I'm keeping it at a very early version. 106 00:06:22,520 --> 00:06:25,270 Then the very important thing, which will definitely prevent 107 00:06:25,270 --> 00:06:31,250 our application working with Arduinos is our dependency section here. 108 00:06:31,250 --> 00:06:34,120 This is where we say what other modules we need, 109 00:06:34,120 --> 00:06:37,710 running and in our Node application for this to work. 110 00:06:37,710 --> 00:06:41,800 So, we only need Johnny-Five, which is the module I was showing earlier. 111 00:06:42,910 --> 00:06:44,380 And this here is the version. 112 00:06:44,380 --> 00:06:49,060 So, in this case, we want the latest Johnny-Five version of that module. 113 00:06:50,550 --> 00:06:53,675 Basically, we're doing such simple stuff, just basic turning 114 00:06:53,675 --> 00:06:56,970 an LED light on and off, not likely to change. 115 00:06:56,970 --> 00:07:00,305 So, we're gonna assume that, in every future version of 116 00:07:00,305 --> 00:07:04,350 Johnny-Five, it'll be compatible with what we're gonna be doing here. 117 00:07:04,350 --> 00:07:08,580 So, there's no need to really be, specific on which version we're wanting. 118 00:07:08,580 --> 00:07:12,130 Now we'll go on to the index JavaScript file. 119 00:07:15,600 --> 00:07:17,840 Our index JavaScript file contains all 120 00:07:17,840 --> 00:07:20,350 of the functionality, but the node application. 121 00:07:20,350 --> 00:07:24,350 So, this pretty much is our note application 122 00:07:25,510 --> 00:07:28,980 in 19 lines, two of which are Console logs. 123 00:07:28,980 --> 00:07:31,810 So, very, very small application here. 124 00:07:32,940 --> 00:07:33,900 I'll go through it step by step and 125 00:07:33,900 --> 00:07:35,850 explain what everything is and why it's there. 126 00:07:37,860 --> 00:07:40,190 Firstly, we've got our five variable. 127 00:07:40,190 --> 00:07:44,030 Our five variable just requires the Johnny-Five module. 128 00:07:44,030 --> 00:07:48,600 Once again, the reason that we've got it here as well as in the package Jason file, 129 00:07:48,600 --> 00:07:54,570 is that we're assigning all of the different objects and functionality. 130 00:07:54,570 --> 00:07:57,560 That we gain from the Johnny-Five module into this five 131 00:07:57,560 --> 00:08:00,935 variable so we can access it throughout the node application. 132 00:08:00,935 --> 00:08:04,740 An example of that is our next line here, which is board. 133 00:08:04,740 --> 00:08:08,790 Our board variable, is creating a new board 134 00:08:08,790 --> 00:08:12,440 object which is part of the Johnny-Five module. 135 00:08:12,440 --> 00:08:17,310 So we're looking into the Johnny-Five object here, that 136 00:08:17,310 --> 00:08:19,860 we've required here, and we're grabbing the board object. 137 00:08:21,520 --> 00:08:23,240 Which is all the part of the Jonny-Five module. 138 00:08:23,240 --> 00:08:24,420 We don't have to worry about any of this. 139 00:08:24,420 --> 00:08:25,970 We don't have to really create any of this. 140 00:08:25,970 --> 00:08:27,680 It's all been there. 141 00:08:27,680 --> 00:08:29,350 Thanks to the geniuses who have come before us. 142 00:08:32,409 --> 00:08:35,140 Next up, we are declaring a few more variables that we use later on, 143 00:08:35,140 --> 00:08:39,929 so we are declaring the LED variable, and we are declaring toggle state variable. 144 00:08:39,929 --> 00:08:41,190 I'll explain these a bit later on. 145 00:08:41,190 --> 00:08:45,414 [BLANK_AUDIO] 146 00:08:45,414 --> 00:08:48,240 To begin, look at this here actually. 147 00:08:48,240 --> 00:08:49,790 This is an important one because this is what 148 00:08:49,790 --> 00:08:52,620 will come up first, when we run our application. 149 00:08:52,620 --> 00:08:54,900 It's just a console log saying waiting for device to connect. 150 00:08:56,000 --> 00:09:01,120 What that means is that, that will come up first, as soon as the known application 151 00:09:01,120 --> 00:09:04,669 is starts up just to let us know that the new application is at least running. 152 00:09:05,890 --> 00:09:10,070 But we don't know yet whether our Arduino has 153 00:09:10,070 --> 00:09:11,700 connected up, and whether we can talk to it. 154 00:09:13,010 --> 00:09:17,820 What then happens, is, using this baud variable here that we created. 155 00:09:17,820 --> 00:09:20,600 Which is a Johnny-Five board object. 156 00:09:21,810 --> 00:09:24,330 We say, on ready, which means, when we've got 157 00:09:24,330 --> 00:09:28,000 the event of ready fired from the board, which means. 158 00:09:28,000 --> 00:09:32,590 The board's pretty faster, sends any sort of commands and requests to it. 159 00:09:33,860 --> 00:09:38,030 We run this function right here, and this function 160 00:09:39,070 --> 00:09:41,110 starts off with a console log saying board ready. 161 00:09:41,110 --> 00:09:44,460 This will just let us know, if we're watching the console while 162 00:09:44,460 --> 00:09:47,650 our node application is running, that the board is ready to receive. 163 00:09:49,000 --> 00:09:51,120 Our request. 164 00:09:51,120 --> 00:09:54,800 It also is a good way to devote whether, or not the board is connected properly. 165 00:09:54,800 --> 00:09:55,520 You are doing a board. 166 00:09:57,380 --> 00:10:01,820 Next up, we use this LED variable that we declared earlier, and 167 00:10:01,820 --> 00:10:04,882 we create a new LED, once again part of the Johnny-Five module. 168 00:10:05,910 --> 00:10:10,420 We're basically just letting it know that we've got an LED. 169 00:10:10,420 --> 00:10:13,390 At pin 13 which is what we plugged into earlier. 170 00:10:15,770 --> 00:10:20,985 Then we get to the JavaScript bit which is, we're setting an interval using the 171 00:10:20,985 --> 00:10:24,330 JavaScript function which many of you might 172 00:10:24,330 --> 00:10:26,850 be used to if you are JavaScript gurus. 173 00:10:26,850 --> 00:10:32,440 Basically set interval means that we're gonna use this function here, toggle LED. 174 00:10:32,440 --> 00:10:36,530 Every 200 milliseconds, and you can play around with this 175 00:10:36,530 --> 00:10:39,920 number if you'd like later on, just to experiment, and change 176 00:10:39,920 --> 00:10:42,810 how often the LED light gonna toggle on and off, 177 00:10:42,810 --> 00:10:45,550 but basically we're gonna say, run this function every 200 milliseconds. 178 00:10:46,770 --> 00:10:49,000 What isn't that function well, the function here has. 179 00:10:50,672 --> 00:10:55,180 Three lines and one life line which is just there for user reading. 180 00:10:55,180 --> 00:10:59,040 Basically we use this variable here, toggle state, 181 00:10:59,040 --> 00:11:01,060 which we set up earlier to be false. 182 00:11:02,300 --> 00:11:05,840 And each time toggle LED runs, will change the value of 183 00:11:05,840 --> 00:11:09,120 toggle state from true to false or from false to true. 184 00:11:09,120 --> 00:11:11,709 So, it basically just changes it the opposite of what it was. 185 00:11:13,100 --> 00:11:19,890 Then, if total state is true, we turn our LED light on, otherwise turn it off. 186 00:11:19,890 --> 00:11:22,700 So, basically, we keep changing toggle state on and off, on and off, 187 00:11:24,120 --> 00:11:27,790 in turn, turning our LED light on and off and on and off. 188 00:11:27,790 --> 00:11:30,390 [BLANK_AUDIO] 189 00:11:30,390 --> 00:11:31,080 You've. 190 00:11:32,080 --> 00:11:33,490 You're following this now and kind of, 191 00:11:33,490 --> 00:11:36,060 picturing the function running in your head. 192 00:11:36,060 --> 00:11:39,140 If you'll notice there is nothing that turns off 193 00:11:39,140 --> 00:11:42,360 this LED, so it will theoretically go on forever continually 194 00:11:42,360 --> 00:11:45,500 turning on and off, on and off until we either 195 00:11:45,500 --> 00:11:48,180 disconnect our Arduino or we turn off this node application. 196 00:11:48,180 --> 00:11:50,270 And I'll be showing you how to do that to. 197 00:11:51,580 --> 00:11:55,040 Theoretically, you could also include some other functionality, in the 198 00:11:55,040 --> 00:11:59,310 error to turn off the, Intel by clearing Intel if you'd 199 00:11:59,310 --> 00:12:02,290 like to but in this tutorial to keep things simple, 200 00:12:02,290 --> 00:12:04,110 we're just gonna give it to the basics I'm showing you. 201 00:12:04,110 --> 00:12:08,100 This is how you can control the Arduino from Node, and 202 00:12:08,100 --> 00:12:10,930 then you can add as much functionality as you'd like to. 203 00:12:10,930 --> 00:12:12,010 On top of this and have a bit of fun. 204 00:12:14,440 --> 00:12:20,830 Now that we have those two files up there and ready to run our Node application, we 205 00:12:20,830 --> 00:12:29,150 do have to make sure those dependencies we mentioned, are there and available to run. 206 00:12:31,110 --> 00:12:34,690 So, what I've done is I've opened up a tunnel, and I've gone to 207 00:12:34,690 --> 00:12:39,560 the same folder that we put those two files in to prove that to you. 208 00:12:39,560 --> 00:12:40,530 I'll just show you there. 209 00:12:40,530 --> 00:12:44,170 So, you've got the index JavaScript file, and our package JSON file. 210 00:12:46,290 --> 00:12:46,790 So. 211 00:12:48,230 --> 00:12:53,853 How you would usually run a node application is just Node index.js. 212 00:12:53,853 --> 00:12:57,290 And we're gonna attempt to run it. 213 00:12:57,290 --> 00:13:01,610 And what we see here is that is says, cannot find Module Johnny-Five. 214 00:13:01,610 --> 00:13:02,990 Which is fair enough. 215 00:13:02,990 --> 00:13:05,970 We've told it in the Index JavaScript file. 216 00:13:05,970 --> 00:13:10,310 That there's gonna be a node module called Johnny-Five and it's gone and looked for 217 00:13:10,310 --> 00:13:13,630 it and can't find and it is now very upset at us for lying to it. 218 00:13:13,630 --> 00:13:16,050 So, we need to get it installed. 219 00:13:17,540 --> 00:13:21,750 To install it you can use an incredible package manager called MPM. 220 00:13:23,060 --> 00:13:27,202 MPM just runs through your package.jason file, 221 00:13:27,202 --> 00:13:29,440 and installs any dependencies that you've got listed. 222 00:13:29,440 --> 00:13:32,150 If you don't have MPM on your machine just do a 223 00:13:32,150 --> 00:13:35,550 quick Google search for MPM, and install it on your computer. 224 00:13:36,750 --> 00:13:41,179 It's quite a simple process, so I won't cover it here. 225 00:13:42,900 --> 00:13:47,460 So basically, once you've got MPM installed, you type in MPM space install. 226 00:13:47,460 --> 00:13:51,460 And, it will go through looking through our package Jason file. 227 00:13:52,790 --> 00:13:54,980 It also does a nice bunch of warning us, saying we 228 00:13:54,980 --> 00:13:59,880 don't have a few of those that we could have had. 229 00:13:59,880 --> 00:14:01,620 Description I think and a few other ones. 230 00:14:02,700 --> 00:14:05,350 So, basically, it's gone through and installed 231 00:14:05,350 --> 00:14:08,401 our modules here so we've got all the 232 00:14:08,401 --> 00:14:11,680 Johnny-Five Modules, and all this other stuff 233 00:14:11,680 --> 00:14:14,790 that it deems necessary to run our application. 234 00:14:16,070 --> 00:14:16,780 So now, I'm going 235 00:14:18,920 --> 00:14:22,580 to clear this, but before we run our actual. 236 00:14:22,580 --> 00:14:26,850 Application we're gonna need to set up our Arduino, so 237 00:14:26,850 --> 00:14:30,760 that it's able to receive communication from our Arduino application. 238 00:14:31,980 --> 00:14:36,700 To get this communication working between our Arduino and the computer, 239 00:14:36,700 --> 00:14:40,660 we just need to upload a bit of code to our Arduino. 240 00:14:40,660 --> 00:14:44,770 Arduino calls these bits of code sketches. 241 00:14:44,770 --> 00:14:50,018 Which you upload and then install onto the Arduino and then the Arduino knows 242 00:14:50,018 --> 00:14:55,089 what it needs to do, In our case we don't need the Arduino to do too much. 243 00:14:55,089 --> 00:15:00,480 Most of our functionality is in Node, all we need to do is install 244 00:15:00,480 --> 00:15:04,030 a bit of code to ensure it understands how to communicate with the computer. 245 00:15:05,960 --> 00:15:10,020 First off, before we install it, if you haven't used the Arduino software 246 00:15:10,020 --> 00:15:16,410 before, double check that your serial port is pointing to the correct USB port. 247 00:15:16,410 --> 00:15:17,830 You might need to do a bit of trial, and error with 248 00:15:17,830 --> 00:15:21,180 this one if you're not sure which USB port is the correct one. 249 00:15:21,180 --> 00:15:24,870 But in my case, it was this TTY USB modem. 250 00:15:26,990 --> 00:15:28,610 Do a bit of trial and error to check which will work 251 00:15:28,610 --> 00:15:33,123 if you are having any issues with uploading your code to your Arduino. 252 00:15:33,123 --> 00:15:35,625 Definitely check that setting right there. 253 00:15:35,625 --> 00:15:38,190 I've also got the board set up to 254 00:15:38,190 --> 00:15:42,135 be Arduino set up to whichever board [INAUDIBLE]. 255 00:15:42,135 --> 00:15:43,590 Then top load the sketch. 256 00:15:44,910 --> 00:15:47,620 We're going to go to file, examples. 257 00:15:47,620 --> 00:15:49,145 And then you'll have this on yours too 258 00:15:49,145 --> 00:15:54,980 Fermata, we want the standard Fermata, sketch here, and 259 00:15:54,980 --> 00:15:58,000 this as it says here is a generic protocol 260 00:15:58,000 --> 00:16:01,410 for communicating with micro controls, from software on computer. 261 00:16:03,020 --> 00:16:05,790 That is convenient, because that's exactly what we want to do. 262 00:16:05,790 --> 00:16:10,870 We want to communicate from our notes software 263 00:16:10,870 --> 00:16:14,803 to our micro control, which is our Arduino. 264 00:16:14,803 --> 00:16:17,908 So, to upload this to our Arduino, make sure you've 265 00:16:17,908 --> 00:16:22,320 got it plugged into your computer still, and click upload. 266 00:16:22,320 --> 00:16:23,690 It'll compile the sketch. 267 00:16:24,780 --> 00:16:27,210 It'll upload it onto the Arduino. 268 00:16:28,390 --> 00:16:31,040 And then in a few seconds it should be done. 269 00:16:31,040 --> 00:16:31,620 There we go. 270 00:16:31,620 --> 00:16:33,650 So, it's done uploading, which mean's you've now got 271 00:16:33,650 --> 00:16:39,270 the standard Fermata software or a standard Fermata sketch. 272 00:16:39,270 --> 00:16:42,350 On your Arduino, which means we're ready now, to move on to the 273 00:16:42,350 --> 00:16:46,560 next very exciting bit of running our Node code and communicating with that Arduino. 274 00:16:48,020 --> 00:16:50,130 We've got our two files set up. 275 00:16:50,130 --> 00:16:55,390 Our index JavaScript which has all the code for our Node application. 276 00:16:55,390 --> 00:16:58,910 We've installed all our dependencies, using MPM. 277 00:16:58,910 --> 00:17:01,590 We've also got our Arduino connected and 278 00:17:01,590 --> 00:17:06,869 running the standard Fermata, sketch code; which means 279 00:17:06,869 --> 00:17:10,119 it's now ready to accept all commands that will come to it from our computer. 280 00:17:11,319 --> 00:17:14,310 So, all that's left is to be in our terminal 281 00:17:14,310 --> 00:17:21,099 and type in Node index.js, and when we run this, 282 00:17:23,349 --> 00:17:26,140 we've got our, waiting for device to connect, message along 283 00:17:26,140 --> 00:17:31,400 with a few messages that come from the Johnny-Five Module. 284 00:17:32,600 --> 00:17:36,269 It's found our serial port, which is the 285 00:17:37,650 --> 00:17:42,890 USB port that we've got the Arduino connected to. 286 00:17:42,890 --> 00:17:45,320 Your one might be very different to this. 287 00:17:45,320 --> 00:17:46,150 Doesn't really matter. 288 00:17:46,150 --> 00:17:47,860 The main important thing, is that our console log 289 00:17:47,860 --> 00:17:51,220 that we set up, which said, board ready, has appeared. 290 00:17:51,220 --> 00:17:55,849 And if you turn to face your LED light, you'll see that it's now flashing. 291 00:17:57,570 --> 00:17:58,060 Which is lovely. 292 00:17:58,060 --> 00:17:59,346 It means that our code is working. 293 00:17:59,346 --> 00:18:04,980 We're sending our commands to the 13th pin, telling 294 00:18:04,980 --> 00:18:07,450 it to turn an LED light on and off. 295 00:18:07,450 --> 00:18:10,580 And so it's turning on and off, and on and off, on and off. 296 00:18:10,580 --> 00:18:13,630 Just as we requested it to. 297 00:18:13,630 --> 00:18:16,070 The only important question is how do you get it to turn off? 298 00:18:16,070 --> 00:18:18,650 How do you stop it from constantly running? 299 00:18:18,650 --> 00:18:19,650 This note application. 300 00:18:21,110 --> 00:18:27,452 If we go back to the terminal here, what you've gotta do is just press Ctrl C and 301 00:18:27,452 --> 00:18:34,040 then Ctrl C again and it'll close the board and it'll stop that light blinking. 302 00:18:35,050 --> 00:18:37,550 If you timed it correctly, the light'll be off. 303 00:18:37,550 --> 00:18:40,690 If you time it slightly differently, the light will stay on. 304 00:18:40,690 --> 00:18:42,750 And that's okay, really. 305 00:18:42,750 --> 00:18:43,440 It's not a big deal. 306 00:18:43,440 --> 00:18:47,130 If you want to completely turn it off, you can just unplug the 307 00:18:47,130 --> 00:18:52,750 USB from the computer, and it will turn off all power to your Arduino. 308 00:18:52,750 --> 00:18:53,780 It won't harm it in any way. 309 00:18:53,780 --> 00:18:55,800 It's just a quick way of getting it to. 310 00:18:56,920 --> 00:18:59,870 Stop doing what it was doing that you really didn't want it to do. 311 00:18:59,870 --> 00:19:05,700 And that, my friends, is how you turn a LED light on and off, and on and off 312 00:19:05,700 --> 00:19:11,250 in an infinite loop using node Johnny-Five and Arduino. 313 00:19:11,250 --> 00:19:14,510 If you followed along, you should now have an 314 00:19:14,510 --> 00:19:17,360 LED light, bending to your node application as well. 315 00:19:17,360 --> 00:19:17,860 Good work. 316 00:19:19,080 --> 00:19:20,500 This is the basics. 317 00:19:20,500 --> 00:19:22,090 There's a lot more to do from here. 318 00:19:22,090 --> 00:19:24,940 If you've got any questions, or if there's anything that 319 00:19:24,940 --> 00:19:27,300 I've missed, feel free to get in touch with me. 320 00:19:27,300 --> 00:19:29,530 My name once again is Patrick Catanzariti. 321 00:19:29,530 --> 00:19:38,110 I am on Twitter at thatpatrickguy or I've got a website Patcat.me. 322 00:19:38,110 --> 00:19:41,880 So, feel free to get in touch, if you make anything really cool with Arduinos 323 00:19:41,880 --> 00:19:43,260 following up from this tutorial, definitely get 324 00:19:43,260 --> 00:19:44,260 in touch as well, we'd love to see. 325 00:19:44,260 --> 00:19:52,719 Thanks for taking the time, to watch, and I hope you learned something new. 326 00:19:52,719 --> 00:19:55,046 See you. 327 00:19:55,046 --> 00:20:01,270