software

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

Arduino has become one of the most successful electronics projects in the world, it was created mainly for students in 2005 in Italy, all this had the objective of allowing the work of electronics to be simple, allowing all those interested in the area experience what it is like to create 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 to be a successful programmer, since the main idea of Arduino is to facilitate all this at its maximum reach, thus allowing thousands of people to create your own projects from home.

One of the keys to being successful here is knowing how to write the instructions for the microcontroller in the programming language, which may not be so straightforward for many. This is how here we are going to teach you a little more what the Arduino programming language is and what its fundamentals are, for 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 for in electronics?

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

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

  • It is considered as the general-purpose programming language that is associated with the UNIX operating system.
  • It is a medium level language, it has basic objectives such as numbers, characters, bits, memory addresses, among others.
  • It has great portability.
  • It is used for programming systems such as text editors, interpreter construction, compilers, among others.

C ++ is considered a programming language that was designed in the mid-80s by Bjarne Stroustrup, it was created with the intention of extending this C language with mechanisms that allow to carry out the manipulation of objects. In accordance with this, and with the views of object-oriented languages, C ++ is considered 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 multi-paradigm programming language and currently there is a standard that is known as ISO C ++.

C # is a language belonging to Microsoft that is responsible for mixing the basic features of C ++ simplifying them in the style of Java and at the same time offering a framework. Finally, it should be mentioned that C # is part of the .NET platform

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

The team in charge of Arduino created its own language to program this card, this language is based on Wiring . All this is about a framework, this is a kind of template, structure or technological-based conceptual scheme that allows working in a much simpler way and it is also open source for the programming of microcontrollers .

Let’s see in more detail:

Wiring

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

Finally, like the Arduino board , Wiring has an IDE that is based on Processing that allows programming of the microcontrollers. Therefore, you simply have to go to the official Wiring website and download this development environment, it is available for Linux, Windows and Mac operating systems .

Processing

In order to give you instructions and write the code on 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 IDE and which is defined as an integrated development environment.

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

C / C ++ language

As mentioned above, the Arduino language based on Wiring and which is also based on C / C ++. Which allows working with a project in Arduino, but it is necessary to have a knowledge of the C language. Bear in mind that not all the functions of this language are used, but the types of structure and variables are used.

However, the advantage that C offers is that it is a medium-level language, it allows to efficiently handle all the resources of the microcontroller and it is also a compiled language that allows creating a file so that it can be loaded later. on the microcontroller .

Arduino IDE Get to know the development environment for OpenSource hardware!

The Arduino IDE or as it is also known “Integrated development environment” is a computer program that is composed of a set of programming tools, this can be exclusively dedicated to a single programming language or it can be used by several 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 graphical interface constructor ( GUI). In the case of the Arduino board , the tools are incorporated to load the already compiled program into the hardware flash memory.

In this way, it can be said that the Arduino IDE is the working tool 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.

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

Fundamentals of Arduino Programming What are the most important ones you should know?

Arduino programming has several fundamentals that are important to know and apply, since they will help you achieve better results when working on this platform, that is why below we are going to teach you which are the most important fundamentals that you must 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 syntax, it is the one that will allow communication with the compiler . The compiler’s mission is to read the code and translate it into machine code for the microcontroller to understand . 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 it will be able to read and translate the code .

Comments

The comments are simply notes that the programmer leaves within the code, this helps you understand a large part of that code. It is important that in this case it is not a question of making an extensive report of something related to the code, but of something descriptive that helps to understand its operation. It should be mentioned that it is a fundamental part when writing a program for Arduino.

However, it must be borne in mind that comments are not compiled, they are not translated into machine code, so every time the compiler encounters a comment, that line is skipped.

Currently there are two ways to write a comment such as the following:

// this is a comment

Int myivariate = 0;

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

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

/ *

This is a comment

* /

Int my variable = 0;

There is another way to comment and place / * to open and * / to close. In this way, everything that exists between these two opening and closing marks is considered as a comment. As it is a comment, it will turn gray.

Semicolon

In the C ++ programming language, the semicolon (;) is like a semicolon . This means that said symbol indicates that what is being said is that a sequence has been finished and from that moment on something new has been commented without relation to the above at the syntax level.

Let’s see:

// this is a comment

Int variable = 0:

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

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:

// No semicolon

Int variable1 = 0

 
Void setup () {

// Insert your code here;

}

 
Void loop () {

// Put your main code here, so that it runs repeatedly:

}

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

Sketch_may29a: 4: error: expected ',' or ';' before 'void'

Void setup () {

Exit status 1

Expected ',' or ';' before 'void'

As you can see, the first error appears here . 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 a comma or a period and as 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, a red stripe will appear in the editor indicating the line where the error is found and where it is referenced in the console. The next thing will be to change the code and place a semicolon at the end of line 2 to make it compile. 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 language programming. They consist of a programming tool that allows storing and retrieving information about the programs.

Type of data

It is not only about having a name for the variable, but also about being able to indicate the type of data that is going to be stored . Therefore, data types are responsible for indicating the information to be saved, specifying each of the data types .

This will allow the data recovery and obtaining process to be much easier, it is not the same to look for something unknown to 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.

Features

In the case of functions, some of them require parameters such as the digitalWrite function, where it is important to be able to know two things such as 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. Virtually most languages ​​have your reference. Upon entering “DigitalWrite” you will notice that the site is in English.

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

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

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

Arduino setup () and loop () function

Finally, we find what is the Arduino setup and loop function, both are considered the most important functions of a program and essential when learning Arduino.

Setup () function

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

  • Start the serial communication with the computer via the USB port.
  • Display a welcome message on an LCD screen.
  • Configure the welcome pins on an LCD screen.
  • Start a counter to zero .
  • Rotate a servo motor to a default linear position .

You should keep in mind that these are types of tasks that are done only once. In this way, it can be said that they are the initial conditions of the program, these types of tasks are the ones that are based on setup (). In order to understand all this better, here we will look at this function in more detail.

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

But unlike most functions, in this case setup () does not need any arguments to operate:

Void setup () {

}

As you can see on the left side of the word setup there is the word void, which is indicating that this function will not return any value or data. Therefore, this function does not need any argument and does not return any value, but it does do something.

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

Void setup () {

// Modes of pins 5 and 8

pinMode (5, IMPUT);

pinMode (8, IMPUT);

// Welcome greeting on LCD

LCD.write ("Welcome to arduino pizzeria");

// Default position of the servomotor

Servo.move (90);

}

In this way, the setup function is the first thing to run when the Arduino program is launched . Once the setup function is executed , 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 braces will only run once .

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button