Arduino-IDE
The Arduino IDE (Integrated Development Environment) is a software package for programming Arduino or compatible microcontroller boards.
Its main features include:
- a text editor for entering program source code;
- a compiler to transform this source code into machine language;
- a board manager (microcontroller drivers);
- a library manager: installation of the libraries or programs needed to use the various modules (screen, sensor, etc.) or functions. It also allows you to track versions;
- a function for uploading a program to a microcontroller;
- a serial port monitor for viewing and exchanging information on program execution status.
IDE interface
Most of the IDE window is dedicated to the text editor. From top to bottom, you'll find the composition of the Arduino IDE interface:
- drop-down menus;
- quick access buttons;
- tabs for open project files;
- the text editor containing the source code of the selected file;
- the information section displaying the current operation;
- detailed compilation information;
- the status line indicating the currently selected microcontroller.
General principle for programming a microcontroller
After opening the IDE:
- load the source code into the IDE's text editor: this is the program to be executed by the microcontroller in a language that the developer can understand (C++ language);
- connect the microcontroller to the USB port;
- selection of the driver corresponding to the connected microcontroller (the IDE needs to know who to address and how to talk to it);
- compilation of the source program: the resulting code is no longer understandable by the developer, but only by the microcontroller;
- uploading machine code to the microcontroller via the USB connection (serial port);
- the programmed microcontroller can be disconnected from the computer and implemented in its own electronic assembly.
The card manager
The IDE board manager is used to install drivers for microcontrollers.
It is accessed via the drop-down menu : Tools/Board type/Board manager
The drivers required for Arduino microcontrollers (Nano, Uno, Mega) are already installed. For other models, such as the ESP32, you'll need to install a specific driver.
Library management
The library manager allows you to install and monitor libraries required for the operation of certain external modules or containing functions that can be used in programs.
It is accessed via the drop-down menu : Tools/Manage libraries
The libraries used by a program are declared at the start of the code with the #define <library name> command.
When you run a program compilation (first quick access button), the information window will tell you if a library has not been installed (in addition to potential syntax errors in the source code). In this case, you'll need to:
- open the library manager;
- search for the library concerned (a text field in the top right-hand corner of the window lets you filter libraries by name);
- select the line in the manager to display the install button;
- install this library by clicking on the install button;
- close the library manager;
- restart program compilation.
Program execution in the microcontroller
A new ino file (1) loaded into the IDE editor (File/New or CTRL+N or quick access button) contains the minimal structure of a program. This structure is made up of two blocks:
- The setup function, containing all program initialization commands. For example, the definition of input or output pins, the state and content of variables at program start-up, or the initialization of modules connected to the microcontroller. This function is executed only once, when the microcontroller is powered up.
- The loop function which, as the name suggests, loops indefinitely as long as the microcontroller is powered up. This loop is used, for example, to program a measurement from a sensor connected to the microcontroller and display it on a screen also connected to the microcontroller. This measurement will be taken and displayed continuously.
(1) extension of the files used by the IDE and corresponding to the last 3 characters of the word Arduino
Using the Serial Monitor
The serial monitor, accessible via the last quick-access button, is a window that allows you to:
- display information from within the program, to check the status of certain variables, or verify breakpoints in certain code branches;
- send various commands to the program during execution, to check its behavior.
All exchanges between the microcontroller and the IDE serial monitor take place via the USB connection.
Change preferences to make life easier...
Select File/Preferences to bring up the preference settings window:
- Enable detailed results
If your program contains syntax errors when you run a compilation, an error message will appear in the results window. In some cases, this message is not sufficiently clear or precise to determine the source of the problem. Having more information about the anomaly can be very useful.
- Display line numbers and activate code folding
To avoid getting lost in the source code when it becomes large, displaying the line numbers will let you know where the part you're working on is located, so you can return to it more easily.
Code folding allows you to reduce certain blocks of code (conditions, loops, etc.) to give you a better overview of the program.
Installing the Arduino IDE
Go to the official Arduino website to download this software for free : https://www.arduino.cc/en/software