Embedded System - Arduino

 

 

 

 

Programming in IDE

 

In this page, I will explain on progamming Arduino using Arduino IDE and describe mostly on functions that you would use in Arduino Sketch file. You would have a lot of information on this from Arduino Tutorial page and the contents of this page would not be much different from what you get from Arduino homepage, but I will reorgnize and describe things so that you can use as a kind of quick cheatsheet.

 

 

 

Basic Structure

 

Every computer language has its own structure. Arduino also has its own structure as shown below. Basically it is made up of three sections. You will see these three sections in every Arduino program that is called Sketch.

 

Section 1 : Global Variable Declaration

 

This section is located at the beginning of the program. This is where you can define variables (global variables) that you will use at later part of the program. In case when you don't need any global variable, this part would be left empty.

 

 

Section 2 : Initialization

 

This part is defined as a function named as 'setup()' and this is the function that is executed at first when you run Arduino program and this functions is excuted only once. So usually you would put down the code that needs to be done before the main body (loop()) is executed.

    void setup() {

      ....

    }

 

 

Section 3 : Main Body

 

This is the main body of the program (it is like main() in C language). As the function name implies, this function keep repeating once it starts.

    void loop() {

       ....

    }

 

 

Build and Upload  Process

 

Following flow chart shows the overall procedure of what's going on when you press [Run] button on Arduino IDE.

 

 

 

 

Build in Verbose mode and Getting intermediate files

 

The flow chard shown above shows only the brief overview of the compile and upload process. In reality, there are so many steps going on in the background. If you are interested in the full details of the process, you can get all those information by compiling and uploading a program in verbose mode. Somebody would be interested in these just for study purpose and some others would be interested in this for reverse engineering purpose. Actually I am interested in both :)

 

How can I get Arduino IDE to compile and upload the sketch in verbose mode ?

It is simple. Click [Preference] in [File] menu and you will get the Preference setup window. Then, check "Compilation" and "Upload" items in "Show verbose output during" section as shown below.

 

 

If you execute a sketch with this kind of verbose setting, you will see the full details on every procedure the IDE is performing as shown below.

 

 

What you see in the above screenshot is only a part of the information printed out during the compile and download process. Here goes a example of full text output for building and downloading Blink example :  Verbose output

 

When Arduino IDE compiles a sketch, it creates a tmp folder and put all the intermediate files created during the build process. You can get the location of the tmp folder from the output print in verbose mode. For example, in executing Blink program on my PC, it created a tmp folder as shown below.

    C:\Users\Sharetechnote\AppData\Local\Temp\build9c9ef3bdfe2fccb480bc6e4bac749e41.tmp\

Open up the folder, you would see a lot of files and folders are created in the folder as below.

 

 

Out of these folders and files, I am more interested in sketch folder because the c source code for the Arduino sketch file is generated and saved here.