Arduino* IDE Tutorial

Documentation

Install & Setup

000006321

10/18/2022

Required equipment:

  • Intel® Galileo Board
  • Power supply (included in the box)
  • Micro USB cable (Type B)
  • Installed and configured Arduino* software v 1.5.3

Sample sketch

When you create a file in Arduino* software, it opens up a sketch with the basic layout of an Arduino program. Here is the user interface:

BareMinimum User Interface

From left to right, the icons at the top of the Arduino user interface represent the following:
Checkmark icon Verify compiles code. Use to check your code for errors before uploading the sketch.
upload icon Upload a sketch.
New editor window icon New Editor Window opens a new code editing window in place of the current one.
Open Icon Opens a file.
Save icon Saves a sketch.
Serial monitor icon Serial Monitor opens the serial monitor, useful for debugging
Down Arrow Down arrow gives you options like adding a sketch to the current project. It opens as a new tab in the current code editor, that is useful for organizing your code into logical files.

The number at the bottom left of the Arduino user interface indicates the line number of where the cursor is.

Note The image represents the Arduino Software interface, titled BareMinimum, and is found at File > Examples > 0.1 Basics. Check out the other examples and experiment.

 

Comments

The two forward slashes (between the { and }) represent the beginning of an inline code comment. When your code is uploaded to the board, the compiler ignores the text after the two slashes. Using the inline code comment allows you to leave notes for yourself, and for people reading your code. You can also write multiline comments by starting your comment with /* and ending with */.

/* You are reading an
example of a comment
that has many lines. */

Variables

Passing around data throughout a program can get messy quick. Variables are like storage containers that hold different types of values. Using variables to pass values around is a great way to keep your code organized and readable.

When declaring a variable (introducing it into the program), choosing the right data type is important. If you are trying to measure light intensity using a photometer, you might want a precise reading. Declaring a variable type of double reserves space in memory for a number with a decimal point.

Example: double light_sensitivity;

Where double is the type of variable you are declaring and light_sensitivity is the name of the variable. To reference a variable in your code, simply use the name you gave it.

Note Pick a variable name that is relevant to what you are referencing. If the name is more than one word, use an underscore character ( _ ) between words to increase legibility.

Make sure to check the spelling on words you choose. One wrong character can cause your program to not compile properly.

 

For more information about data types and variables, visit the Arduino reference page.

Functions

The two building blocks of a sketch are the setup function and loop function. All programs require the use of these two functions as they are the required structures for a program to compile.

The setup function is where you include things like variable declarations and initializing pin modes.

The loop function is the heart of your program. It does what the name suggests, loops continuously, running the main logic for your program.

Just like variables, functions come in different types. The setup and loop function are of type void. Meaning, that they only do what they are instructed to, and return no value (thus, void). Functions that return values are discussed in future lessons.


Introduction
Getting Started
The Arduino IDE
Hello World