Arduino, as a convenient, flexible, and easy-to-use open-source electronic prototyping platform, is popular among various groups of people. We will launch a series of Arduino learning posts to help you quickly master this increasingly popular microcontroller. Our “Getting Started with Arduino” will guide everyone to understand Arduino, starting with the simplest “Hello World!” program, helping you enter the world of Arduino.
1. Microcontrollers and Arduino
1. What is a Microcontroller?
Simply put, a microcontroller is an integrated chip, but the functions of this integrated chip need to be controlled and implemented by our own programming. It is a small and complete microcomputer system formed by using ultra-large-scale integrated circuit technology to integrate circuits with CPU, RAM, ROM, various I/O ports, terminal systems, timers/counters, and other functions into a silicon chip.
The microcontroller has developed to now, its family already includes multiple members such as 51, MSP430, TMS, STM32, PIC, AVR, STC, etc. Each member is further divided into many different series, making it dazzling in the market. Its development into today’s scale is inseparable from its characteristics of compactness, flexibility, and powerful functions. It is precisely these characteristics that establish the unshakable position of microcontrollers in the field of system-on-chip. Its wide applications can be found in smart instruments and meters, automatic control, household appliances, medical devices, and various other fields. It can be said that our world has long been inseparable from microcontrollers.
2. What is Arduino?
Arduino is a type of microcontroller and is a very unique microcontroller. Strictly speaking, Arduino is a convenient, flexible, and easy-to-use open-source electronic prototyping platform. The term open-source means that anyone can modify and develop its technology, whether hardware or software. It is because of this concept that Arduino has become increasingly popular and is widely welcomed among different groups of people.
Compared to ordinary microcontrollers, Arduino is more friendly to beginners due to its large number of highly integrated standard library functions, making it particularly suitable for students and hobbyists to learn and use. Learning Arduino microcontrollers can be done without understanding its internal hardware structure and register settings, and there is minimal hardware knowledge required, even the demand for software knowledge is reduced to the extreme—users only need a basic understanding of C language to write beautiful and powerful Arduino code by referring to the function library. In addition, its low price is also a major feature, so there is no need to worry about learning costs. Of course, Arduino has many more advantages, which will not be listed one by one here.
2. Software to Control Arduino—Arduino IDE
01
Arduino IDE Download and Installation.
Since Arduino is completely open-source, its IDE can be obtained directly for free from the official website (http://arduino.cc/en/main/software). The IDE is available for Windows, OS X, and Linux versions, and readers can download according to their needs. This article will explain the installation of Arduino IDE using Windows as an example.
First, obtain the standard .exe file of the IDE from the official website and double-click to run it, opening the Arduino IDE installation wizard. The subsequent steps can be followed according to the prompts of the wizard. It is important to note that when selecting installation content, be sure to select the “install USB drivers” option, as shown in the figure below, to ensure normal use after connecting the microcontroller.
02
Introduction to the Arduino IDE Interface
After opening the IDE, you will find the following interface, with commonly used button functions as shown in the figure.
Compile: Compiles the written program to ensure there are no syntax errors.
Upload: Uploads/burns/downloads the program to the microcontroller board for application.
Create Program, Open Program, Save Program, functions as named.
The functions of the other menu bar items are very simple, and we will gradually cover them as learning progresses, so they will not be elaborated on here.
3. Taking the First Step in Learning—Hello World!
01
First Attempt
The first time using the Arduino development board, we will use the “Hello World!” example to lead everyone into the magical world of microcontrollers.
The function of this example is to allow the microcontroller to communicate with the computer via a serial port and continuously send the string “Hello world!” to the computer, displaying it on the monitor. If you do not understand serial communication, it doesn’t matter; we will introduce it in subsequent chapters. For now, you just need to follow the steps to experience the basic steps of Arduino development.
As shown in the figure, input the program into the editing area, then click verify to compile the program and ensure it is correct.
In the menu bar, select “Tools” -> “Port” to configure the serial port number that the development board is connected to (i.e., the serial port number of the current computer connected to the microcontroller); then select “Tools” -> “Board” to select the board model.
Since the development board we are using is the Uno development board distributed by the school, select the “Arduino/Genuino Uno” option, as shown in the figure below. It should be noted that these two steps are very important and indispensable; the correctness of the configuration will directly affect whether the program can be successfully uploaded to the board.
After configuring, click the upload button, and when “Upload Successful” appears, the program has been burned to the development board and is now running.
Although the program has been successfully burned into the development board and is running, we still cannot see the running results. This is because serial communication needs to be monitored through a dedicated serial monitor. Fortunately, the Arduino IDE has already integrated a serial monitor, so we do not need to download it separately.
As shown in the figure below, select “Tools” -> “Serial Monitor” to open the serial monitor, and you will see the screen continuously refreshing “Hello World!”, which also indicates that our first project has been perfectly successful.
02
Explanation of the “Hello World!” Program
By imitating and executing the example, we can easily find that at the beginning of learning, the first thing to master is how to write a program that can be compiled and uploaded. Below we will analyze the structure of an Arduino program.
In standard C language, the main function is the entry point of the program. However, when observing the Arduino program, we find that there is no main function; instead, there are setup and loop functions. As the name suggests, the setup function is for some preparation done at the beginning of program execution; it is executed only once for variable or interface initialization. The loop function, as its name implies, means looping, and its function is equivalent to an infinite loop. Thus, the program in this example can be translated as:
void setup() { // The following content is for initialization
Serial.begin(9600); // Set the serial port baud rate to 9600
}
void loop() { // The following content loops infinitely:
Serial.println(“Hello World!”); // Send “Hello World!” through the serial port and print it
delay(5000); // Delay 5000ms
}
This is the basic structure of an Arduino program. As for the knowledge of serial ports, baud rates, delays, etc., don’t worry; we will explain it in subsequent tutorials. We look forward to your continued attention!
Produced by Beihang University Electronic Technology Association
Planning/ Hou Fuchao
Copywriting/ Zhou Bowen, Liang Jiawei, Hou Fuchao
Editing/ Hou Xiaopeng
Leave a Comment
Your email address will not be published. Required fields are marked *