This five-part series is aimed at those who would like to implement Arduino projects, but are not very familiar with the programming language and the Arduino IDE.
It is often the case that hobbyists know electronics very well, but programming is still a problem. Numerous tutorials offer ready source code that you only have to load onto the microcontroller. You learn by try-and-error, but often do not understand what is happening in the program. If you then want to implement a more extensive project, you sometimes end up in a dead end. The following basics should help to ease the access to programming.
To transfer your own program to an Arduino microcontroller can be done in different ways. In our blog posts there are already instructions for installing and using the PlatformIO development environment. In this series of posts, we focus on the Arduino IDE, which is well suited for beginners.
What is needed?
• Computer (Windows, Linux, MacOS)
• Arduino microcontroller
• Mini-USB cable
On the website Arduino.cc Is the Arduino IDE (Integrated Development Environment:
Integrated Development Environment) is available for download. The platforms Windows (from Win XP upwards), MAC OS X (from 10.8), Linux 32 and 64 bit as well as Linux on ARM 32 and 64 bit are supported.
So one of these platforms would necessarily have to be available. The aforementioned website provides a web editor in Arduino Create, which will not be discussed further here.
Of course we want to program an Arduino compatible microcontroller. For this we use the Arduino Nano V3, which you get for free from us as a new customer. It has an integrated LED, which we can use later for the first test. The Nano is connected to the computer with a mini-USB cable. This supplies it with power and also transfers our program.
transferred through it.
Tip: Arduino.cc is a good place to start if you are stuck. Much of what is mentioned here is described there in more detail.
First step - Installation
First, of course, the Arduino IDE should be installed. The best way to do this is to run the Windows Installer and follow the instructions of the installation program.
A portable version is also available as an option. For Linux, download a packed .tar.xz file and unpack it afterwards. This can be done from the context menu via the right mouse button. Here one selects "Unpack here". In the folder that is then created, there is a file called install.sh, which is also started via the right mouse button and the command "Run in terminal". This is a shell script.
If you have already opened a terminal window, change to the folder you just unzipped and as an alternative start the installation with the command line ./install.sh. If there are problems with the authorization
you can add a sudo to the beginning of the line. If the file is then still not executable, it must be made executable with the command line sudo chmod +x install.sh. In case there are still problems with the installation, the user patrickthecreator has published a workaround for the Arduino IDE version 1.82 under Linux on the website instructables.com.
Figure 1: Installation Arduino IDE - driver
If the installation was successful, the Arduino Nano is connected to the computer via mini USB cable and the IDE is started. The starting order is irrelevant. You may have to select the port manually in the program under the menu item "Tools", connect the Arduino only after the program start.
Under certain circumstances a driver is needed under Windows, so that the Arduino is recognized. USB (Universal Serial Bus) is a form of serial interface. If an Arduino is connected, it is assigned to the COM port. If you use the Windows Installer, the required drivers are usually installed at the same time. It is possible that the nano is still not recognized. Possibly there is an Arduino Nano with CH340/CH341 chip. If you enter this into the internet search of your trust, you will quickly find it. The problem is well known. Also under Linux or Mac OS said problems can occur. If the Arduino is recognized, it appears under Windows as /COMx (instead of the x a number appears) and under Linux and Mac OS as /dev/tty or /dev/usb.
Numerous libraries are available. This means that ready-made program functions can be integrated and used. The Arduino IDE offers this in different ways. On the one hand, you can install numerous libraries from the online repository in the menu item "Tools" under "Manage libraries..." or CTRL+SHIFT+I. For example, if you want to use an LCD display, you can install the LiquidChrystal Library and have suitable functions available in a simple way as well as sample code, which can then be accessed via the menu "File" and then "Examples". In the Arduino IDE such a library is already installed. We can also see this in the administration.
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
It is now possible to initialize the display with lcd.begin(16, 2); (16, 2 stands for 16 columns and 2 rows. For larger or smaller displays you have to change these values) and then output text on it with lcd.print("hello, world!");. There are some other functions available in this class. It should only be clarified, how one can include ready program modules.
The first program - Sketches
The Arduino IDE saves programs as so-called sketches. A folder "Sketchbooks" is created for this purpose. Hardware information and libraries that you manually add to the IDE are also stored there. Of course you can also choose your own locations. Sketches are stored as .ino file.
Tip: Make sure that the name of the file is identical to the name of the folder in which the file is located. If this is not the case, you will be kindly informed when saving or a folder with the name will be created independently.
This is how it goes: