Arduino IDE: More Detail
Free Arduino Course
In the last tutorial, we talked about the board itself and the hardware on the board. This time we’re going to talk about the Arduino IDE again and go into a bit more detail about the IDE and Arduino sketches.
IDE stands for Integrated Development Environment. That’s quite a mouthful, so from now on we’re just going to call it IDE. Programs in Arduino are called sketches and the file extension for Arduino sketches is .ino. What’s a file extension? These examples may help clear it up: the file extension for an Excel spreadsheet is .xls or .xlsx, and the file extension for a Word document is .doc or .docx.
Older sketches have a file extension of .pde, but don’t sweat it – these work in the newer version of the IDE, too. In case you run across an older sketch or program, just know that Arduino used to use the .pde extension. The transition if you try to open a .pde file in a newer version of the IDE is seamless by the way. You won’t even really know it.
When you program an Arduino you’re using a language similar to C/C++. Though it’s not 100% completely compatible or interchangeable with C, the goal of the IDE is to make things simple.
Figure 1: there’s beauty in simplicity and the Arduino IDE is meant to be simple and easy to use. The numbers highlight different parts of the IDE.
Tweaking the Arduino IDE
Once you install the IDE, there is something I strongly suggest you do. First, go to file and then preferences, and check the display line numbers box. This is optional, but it will make your life easier because you’ll be able to tell what line of code corresponds to which line number. Trust me on this.
Figure 2: do yourself a favor and check the Display line numbers box. For now, I suggest leaving the other boxes in their default state.
Getting to Know the Arduino IDE
You’ll notice when you open up the Arduino IDE it names your sketch a default name, which we can see with the black rectangles around it in the top of figure 1. The name will likely read something like sketch_today’s date.
Also at the top next to the sketch name lies the Arduino IDE version, which we can see in figure 1.
If you want to change the name of your Arduino sketch, go to File, Save As and give your sketch a new name. The name can’t have any spaces in it (_underscores are ok) and you can’t start the name with a number (though you can use numbers elsewhere).
In the bottom right of figure 1 we can see the Arduino board and port name if we look carefully. Your port name may be something different than COM3 — it’s just a name the computer gives the port. This information might come in handy.
Become the Maker you were born to be. Try Arduino Academy for FREE!
You can’t see it in figure 1, but in the bottom left corner you’ll notice a number. This number tells you what line your cursor is on, which is another tidbit of info that can come in handy.
Now, let’s talk a little bit about the main buttons. Refer to figure 3.
Figure 3: the main buttons in the Arduino IDE.
The verify button on the left resembles a check mark. It compiles the code you write and checks it for errors. The keyboard shortcut for this is CTRL+R on a PC. Do this every so often, to make sure you don’t have any errors in your code. It’s a lot more convenient to find an error before you write a 100+ lines of code.
When you click the verify button it will compile the sketch which might take a few seconds. After that, in the black area with a number 2 in it from figure 1, you’ll get some information.
When you’re finally ready to transfer the program to your Arduino board, you’ll click the upload button, which resembles a right-pointing arrow and is next to the verify button. It will compile the sketch and then upload it to the board. The keyboard shortcut for upload is CTRL+U.
Next comes the new button which looks like a sheet of paper. Use it to start a new sketch. It’s keyboard shortcut is CTRL+N.
On the left of the New button, we have the Open button, which is good for opening sketches, as you may have guessed. The shortcut is CTRL+O.
Finally, all the way on the right, we have Save and this is one you’re going to want to do a lot. Remember the old adage: save early, save often. Why is that? Because if something goes wrong and your computer crashes, you don’t want to lose an hour’s worth of work. CTRL+S is the shortcut for Save.
The TX and RX LEDs are back from the last tutorial to haunt us. As you may remember, TX stand for transmit and RX stands for receive. When you upload a program you’ll see those LEDs on the board blink. This is a good indicator that the PC and IDE are indeed communicating with the board and uploading the sketch. Figure 4 shows their location on the Arduino board.
Figure 4: the Arduino Uno’s TX and RX LEDs in the white circle.
If you have a sketch open and make a change to it without saving it, you may notice a funky looking symbol appear next to the name in the sketch’s tab. The symbol looks like two S’s on top of each other and is depicted in figure 5.
Figure 5: this symbol appears when you make a change. Once you save your sketch, it will disappear.
Let’s talk about the text editor. This is the big white area in figure 1. To spare you the pain of scrolling up and down as you read, figure 1 can be seen again below.
When you open a blank sketch in the Arduino IDE the text editor automatically populates with two functions: setup() and loop(). These functions are absolutely necessary to have, you can’t upload and compile a sketch without them. Even if you don’t use the setup function, for example, it still has to be there.
Figure 1 (again): the Arduino IDE. The numbers highlight different parts of the IDE.
In area 1 from the figure above, you’ll see information pertaining to the compilation progress. If an error occurs during compilation, you’ll see a notice here. You’ll also be able to copy the error message by clicking a button that appears if you need to do some online research on the error.
The black bar (area 2) gives you more detailed information about errors and compilation tidbits. This whole area (that is areas 1 and 2) can expand. You can drag this out with your mouse by hovering over where area 1 meets the text editor and expand it.
When a compilation error occurs, the IDE highlights the erroneous line of code in the text editor. This is pretty awesome and makes it easier to find what line has caused the error.
Another feature of the IDE worth mentioning is shown in figure 6.
Figure 6: another nice feature of the Arduino IDE.
By clicking the arrow in part (a) of figure 6, you can create a new tab, rename a tab and do a few other things, as we can see from part (b) of the figure. This feature is good for navigating the tabs and more.
Above the arrow in part (a) of figure 6 there is another symbol which resembles a magnifying glass. This is the serial monitor. I’m not going to go into a ton of detail about the serial monitor in this tutorial, but it lets you see the communication between the PC and the Arduino. And, like many of the other features of the Arduino IDE, the serial monitor is useful.
One last thing I want to discuss are the example sketches. There are a lot of example sketches — code that’s already written to perform certain tasks — that are built into the IDE that you can use to learn and develop projects quicker.
Reusing code is one of the basic fundamentals of programming. To browse the examples go to File and then Examples. Here reside a whole bunch of built in examples dealing with things like basics, digital, analog, communication, and more. The examples are code that other people have written that you can use as a foundation for some of your own programs. For example, if I want a program that blinks an LED, I might come over here to basics and then open blink, and then modify it to suit my own purposes. This can be a big time saver. It’s also a great learning tool.
Figure 7: the Arduino IDE comes with a ton of open source, useful example programs.
I suggest that you install the IDE if you haven’t already and then open some of the examples up and take a look at some of the code.
That wraps up this tutorial. Until next time, I have a few action steps to help you start creating with Arduino.
Arduino IDE Action Steps
- Download and install the Arduino IDE if you haven’t already.
- Get familiar with the IDE, go through the menus and play with the settings.
- Open some example sketches and see if you can understand any of the code. Can you modify any of them? As an extra bonus, upload some to your Arduino board and see what they do. Note that some of them may require extra hardware.
For even more detail on the Arduino IDE check out this page on Arduino’s website.
Become the Maker you were born to be. Try Arduino Academy for FREE!