Skip to content
Step by Step Internet 馃寪 Guides for learning to surf the Net

Arduino programming language. What language is it based on and what are its fundamentals?

UPDATED ✅ Do you want to know more about OpenSource programming with Arduino and its boards? ⭐ ENTER HERE ⭐ and Learn Everything FROM ZERO! ✅

Arduino has become in one of electronics projects most successful in the worldit was created mainly for students in the year 2005 in Italy, All of this was aimed at making electronics work easy, allowing all those interested in the area to experience what electronics is. creation of electronic projects to be used in the real world.

Therefore, to make use of this platform it is not necessary to have advanced knowledge in electronics nor be a successful programmer, since the idea arduino main is to facilitate all this to its maximum extent, thus allowing thousands of people to Create your own projects from home.

One of the keys to being successful here is knowing write instructions for him microcontroller in programming language, which may not be so easy for many. This is how here we are going to teach you a little more what it is the Arduino programming language and what are its fundamentalsto do this, follow in detail each of the steps that we are going to teach you next in the post.

What is the Arduino programming language and what is it used for in electronics?

What is the Arduino programming language and what is it used for in electronics?

In this case, it should be mentioned that the Arduino programming language is based on C++ and despite the fact that the reference of this programming language of Arduino is found in “Arduino”, nowadays you can also use standard C++ commands in board programming.

This is how here we are going to show you what are the most outstanding characteristics of C:

  • It is considered as the programming language general purpose that is associated to the UNIX operating system.
  • It is a middle level languagel, it has basic objectives such as numbers, characters, bits, memory addresses, among others.
  • Bill with a big portability.
  • It is used for system programming. as it is text editors, building interpreters, compilers, among others.

C++ he is considered like a programming language that was designed in the mid-1980s by Bjarne Stroustrup, it was created with the intention of extending this C language with mechanisms that allow carrying out the manipulation of objects. In accordance with this, and with the views of object-oriented languages, the c++ It is considered as a hybrid language.

As time went by, generic programming facilities were added, all this was added to the other two paradigms that were already supported. (Object-oriented programming and structured programming). That is why it is understood that C++ is a language of multi-paradigm programming and currently there is a standard that is known as ISOC++.

C# it’s a Microsoft proprietary language which is responsible for mixing basic c++ features simplifying them java style and at the same time offering a framework. Finally, it should be mentioned that C# is part of the .NET platform

What other languages ​​are the programming of Arduino boards based on?

The team in charge of Arduino created a language to program this card, this language is found Wiring-based. This is all about a framework, this is a kind of technology-based template, structure or conceptual scheme that allows you to work in a much simpler way and is also open source for microcontroller programming.

Let’s take a closer look:

wiring

It is written in the programming languages ​​C and C++, This is where the syntax of both is quite similar. The main advantage achieved by using this framework is the great variety of microcontrollers it supports, since he himself is capable of support microcontrollers that are used by the Arduino board families.

Finally, like the Arduino board, Wiring count with one SDI which is based on processing that allows to carry out the programming of the microcontrollers. Therefore, simply go to the official website of wiring and download this development environment, it is available for Linux, Windows and Mac operating systems.

processing

To be able to give instructions and write the code to the microcontroller or development board an environment is necessary. These environments are known as “Integrated Development Environment” or as it is also known by its abbreviation SDI and that is defined as an integrated development environment.

In the case of Arduino-IDEknown as the program where the code is written, is developed by a programming language that is known as processing. Therefore, Processing is a programming language and development environment based on JAVA, it is mainly used to carry out the development of digital design multimedia projects.

C/C++ language

As mentioned above, the language of Arduino based on wiring and which is also based on C/C++. Which allows you to work with an Arduino project, but it is necessary to have knowledge about the C language. Please note that not all functions of this language are used, but if the structure types and variables are used.

Nevertheless, the advantage offered by C is that it is a medium-level language, it allows you to efficiently manage all the resources of the microcontroller and it is also a compiled language that allows you to create a file so that it can later be loaded into the microcontroller.

Arduino IDE Meet the development environment for OpenSource hardware!

The Arduino-IDE or as it is also known “Integrated development environment” It is a computer program that is made up of a set of programming toolsthis can be dedicated exclusively to a single programming language that is, it can be used by various types of languages.

In this way, the IDE has become the programming environment that has been packaged as an application program, which means that it is a code editor, a compiler, a debugger, and a builder graphical interface (GUI). In the case of the plate Arduino tools are incorporated to load the already compiled program in the flash memory of the hardware.

In this way, it can be said that the IDE Arduino It is the tool for working with Arduino, so it is necessary to know how it works. In the case of Arduino programs These are made up of a single file with the extension “Info”, although it is also possible to organize them in different files. In the case of the main file, it must always be in a folder with the same name as the file.

Lastly, it should be mentioned that before version 1.x extension was used “pde”, but at the time of moving to this version there were big changes, that is why it must be taken into account if it is used the old code. It should also be mentioned that the IDE is completely free and it’s possible download from official Arduino site and as for his installation process It is quite simple, so you will not have any complications.

Basics of programming in Arduino What are the most important you should know?

Arduino Programming It has several fundamentals that are important to know and apply, since they will help you achieve better results when working on this platform, which is why we are going to teach you below. What are the most important fundamentals you should know about Arduino programming.

To do this, follow each of the following aspects in detail:

Syntax

In the case of programming languages it is required to have a syntaxthe same is the one that will allow communication with the compiler. The compiler has as its mission read the code and translate it to machine code for him to understand microcontroller. In this way, it can be said that the compiler will need all the information that reaches it to be perfect, since this will be the only way that the compiler be able to read and translate the code.

Comments

The comments are just notes that the programmer leaves inside the code, this helps you understand much of that code. It is important that in this case it is not about making an extensive report of something related to the code, but something descriptive that helps to understand its operation. It is worth mentioning that it is a fundamental part when a program for Arduino is being written.

However, it must be borne in mind that comments not compileddoes not translate to machine codeso every time the compiler encounters a comment, it skips that line.

Currently there are two ways to write a comment as follows:

// esto es un comentario

Int mivariable =0;

Everything that is to the right of the double slash (//) is considered as a comment and grayed out.

In this case, the Arduino IDE will take care of modifying the color to indicate that it is a comment:

/*

Esto es un comentario

*/

Int mi variable = 0;

Is there another way to place a comment and placing /* to open and */ to close. In this way, everything between these two opening and closing marks is considered a comment. Being a comment will be changed to a gray color.

Semicolon

In the C++ programming language, the semicolon (;) is like a semicolon. This means that this symbol indicates that what is being said is that a sequence has ended and from that moment something new has been commented unrelated to the previous one at the syntax level.

Let’s see:

// esto es un comentario

Int variable = 0:

From semicolon supplied in the line above, the compiler interprets whatever is written as a new statement, which will have nothing to do with the previous one. Therefore, at this point it is already possible to test to see how the compiler acts.

To do this you must access a new program in the Arduino IDE and copy the following code, for this you do not need to connect the board to the computer:

//Sin punto y coma

Int variable1 = 0

 
Void setup() {

// Inserta aquí su código;

}

 
Void loop() {

//Ponga su código principal aquí, para que se ejecute repetidamente:

}

Then you must click on the “Verify” button, this is the first direct access to the editor:

Sketch_may29a:4: error: expected ‘,’ or ‘;’ before ‘void’

Void setup()  {

Exit status 1

Expected ‘,’ or ‘;’ before ‘void’

As you can see, here it appears the first mistake. To solve it, it is important to analyze it. If you look at the message area you can see that the error appears in English, but it is very descriptive, “Expected” “,” “Or” “, “ “before void”, This means that you must place a comma or period and like before the word void.

Let’s see:

Sketch_may29a:4: error: expected ‘,’ or ‘;’ before ‘void’

Void setup()  {

Exit status 1

Expected ‘,’ or ‘;’ before ‘void’

Finally, in the editor a red stripe will appear That would indicate the line where the error is found and where it is referenced in the console. next thing will be change the code and put a semicolon at the end of line 2 so that it compiles. As you can see, the compiler is not only demanding, but also helps to correct errors.

variables

Variables are one of the most important concepts in what is Arduino programming language. They consist of a programming tool that allows information to be stored and retrieved of the programs.

Type of data

It’s not just about having a variable namebut to be able to indicate the type of data to be stored. Therefore, the data types are responsible for indicating the information to be saved, specifying each of data types.

This will make the process of retrieving and obtaining data much easier, searching for something unknown is not the same as having previous specifications of what you are looking for. It should also be mentioned that each variable can only store a specified data type when that variable is declared.

Functions

In the case of functions, some of them require parameters, such as the digitalWrite functionwhere it is important to be able to know two things as it is the state (HIGH or LOW) and the pin number.

Surely you are wondering How do I know what parameters the function supports? In this case, it is best to go to the language reference, this is as if it were a guide or a user manual. Practically most languages ​​have their reference. When entering “DigitalWrite” You will notice that the site is in English.

This being its biggest drawback, but you can see the following:

Functions

In the references section you can find everything you need to know how to use the function:

  • Syntax: Indicates how it is written and how many parameters the function admits.
  • Parameters: Each parameter and what they mean are explained here.
  • Returns: In case a value is returned, the function will tell you the data type. The digitalWrite function It does not return any value, so nothing is placed.

Arduino setup() and loop() function

Finally, we find what is the Arduino setup and loop functionboth are considered as the most important functions of a program and essential at the time of learn Arduino.

setup() function

It is an Arduino program, where there are things that only have to be done once, such as the following:

  • Start the serial communication with the computer through the USB port.
  • To show a Welcome message on an LCD screen.
  • Configure welcome pins on an LCD screen.
  • Start a counter to zero.
  • Rotate a servomotor to a linear position default.

Keep in mind that these are one-time task types. In this way it can be said that they are the initial conditions of the program, these types of tasks are the ones that go in setup() function. In order to understand all this better, here we will see this function in more detail.

in this case setup() function has a special color the Arduino IDEas is the case with other fundamentals of language. This color indicates that the Arduino-IDE can identify the function as a special type that is used for the code structure control. Like any function, it has a parenthesis that opens and another that closes.

But unlike most functions, in this case setup() doesn’t need any arguments to operate:

Void setup() {

}

As can be seen on the left side of the word setup it’s found the word void, which is indicating that this function will not return any value or data. Therefore, said function does not need any argument and does not return any value, but if you do something.

In this case its job is to execute all the code inside it, this is delimited with the curly braces as follows:

Void setup() {

//Modos de los pines  5 y 8

pinMode(5, IMPUT);

pinMode(8, IMPUT);

//Saludo bienvenida en el LCD

LCD.write("Bienvenido a pizzería arduino");

//Posición por defecto del servomotor

Servo.move(90) ;

}

In this way, setup function it is the first thing that is executed when the arduino program. Once it runs setup function, the program will go line by line executing each one of them. The most important thing about setup is that it only runs once as mentioned above. So this is very important, the code between those two curly braces will only be executed once.

loop() function

Like setup it’s a arduino programbut this time it runs after setup function.

The meaning of loop is repetition and it is the one that has a similarity to that of setup:

Void loop () }

{

It does not require any kind of argument even though it has opening and closing parentheses. In this case it does not return any value so it has the word void to its left. This is how we are going to present you how it has the opening and closing of keys ({}).

The same thing happens here as in the setup function, when the loop function is executed it goes line by line, executing as you can see in the following code:

Void loop () {

Lectura pin 5

Int pinCinco = digitalRead(5);

//Pin 8 en estado alto

Digitalwrite(8, HIGT);

//Servomotor a posición 180°

Servo.mode(180);

}

It can be said that the great difference between setup and loop function is that when you are executing the code of the loop function, the program returns to the beginning and reruns everything. Here it goes into an endless loop over and over again. Now it is important to take into account the speed with which the function is executed, since this is mainly determined by each microcontroller.

In the case of the Arduino UNO board, the microcontroller used is the ATmega328P and has a speed of 20MHz (megahertz). All of this amounts to a total of 20,000,000 instructions per second, but this does not mean that it is 20 million lines of code. It is important to remember that the code that is written is translated into machine code.

Each line of code that you write can translate to multiple translationsbut even so if they have at least 1,000 instructions this would take 0.00005 seconds, so the speed is incredible. In the case of the Arduino program every time it reaches the last line of the code the loop functionit will loop back to the beginning to run everything again, so it doesn’t wait for any external input to do so.

Computing