0% found this document useful (0 votes)
3 views20 pages

Arduino IDE Lab Manual for Robotics

The document is a lab manual for using the Arduino IDE 1.8.x in robot programming at Ho Chi Minh City University of Technology. It covers the introduction to Arduino, installation instructions, programming basics, and troubleshooting common errors. The manual also includes details on the Arduino Nano's specifications, communication methods, and sample source codes for robotic control.

Uploaded by

bao.dang2451015
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views20 pages

Arduino IDE Lab Manual for Robotics

The document is a lab manual for using the Arduino IDE 1.8.x in robot programming at Ho Chi Minh City University of Technology. It covers the introduction to Arduino, installation instructions, programming basics, and troubleshooting common errors. The manual also includes details on the Arduino Nano's specifications, communication methods, and sample source codes for robotic control.

Uploaded by

bao.dang2451015
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Ho Chi Minh City University of Technology Electronic Workshop

LAB MANUAL
ARDUINO IDE 1.8.x
(Use in Robot Programming – Engineer Lecture Lab)
1. Introduction
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino
boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it
into an output - activating a motor, turning on an LED, publishing something online. You can tell your
board what to do by sending a set of instructions to the microcontroller on the board. To do so you use
the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on
Processing.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping, aimed
at students without a background in electronics and programming. As soon as it reached a wider
community, the Arduino board started changing to adapt to new needs and challenges, differentiating its
offer from simple 8-bit boards to products for IoT applications, wearable, 3D printing, and embedded
environments. All Arduino boards are completely open-source, empowering users to build them
independently and eventually adapt them to their particular needs. The software, too, is open-source, and
it is growing through the contributions of users worldwide.
Ho Chi Minh City University of Technology Electronic Workshop

⮚ Power
The Arduino Nano can be powered via the Mini-B USB connection, 6-20V unregulated external
power supply (pin 30), or 5V regulated external power supply (pin 27). The power source is
automatically selected to the highest voltage source.
⮚ Memory
The ATmega328 has 32 KB, (also with 2 KB used for the bootloader. The ATmega328 has 2 KB of
SRAM and 1 KB of EEPROM.
⮚ Input and Output
Each of the 14 digital pins on the Nano can be used as an input or output, using pinMode(),
digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a
maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In
addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are
connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a
rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which,
although provided by the underlying hardware, is not currently included in the Arduino language.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED
is on, when the pin is LOW, it's off.
The Nano has 8 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values).
By default they measure from ground to 5 volts, though is it possible to change the upper end of their
range using the analogReference() function. Analog pins 6 and 7 cannot be used as digital pins.
Additionally, some pins have specialized functionality:
I2C: A4 (SDA) and A5 (SCL). Support I2C (TWI) communication using the Wire library
(documentation on the Wiring website).
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields
which block the one on the board.
Ho Chi Minh City University of Technology Electronic Workshop

⮚ Communication
The Arduino Nano has a number of facilities for communicating with a computer, another Arduino,
or other microcontrollers. The ATmega328 provide UART TTL (5V) serial communication, which is
available on digital pins 0 (RX) and 1 (TX). An FTDI FT232RL on the board channels this serial
communication over USB and the FTDI drivers (included with the Arduino software) provide a virtual
com port to software on the computer. The Arduino software includes a serial monitor which allows
simple textual data to be sent to and from the Arduino board. The RX and TX LEDs on the board will
flash when data is being transmitted via the FTDI chip and USB connection to the computer (but not for
serial communication on pins 0 and 1). A SoftwareSerial library allows for serial communication on any
of the Nano's digital pins. The ATmega328 also support I2C (TWI) and SPI communication. The
Arduino software includes a Wire library to simplify use of the I2C bus. To use the SPI communication,
please see ATmega328 datasheet.
⮚ Programming
The Arduino Nano can be programmed with the Arduino software (download). Select "Arduino
Duemilanove or Nano w/ ATmega328" from the Tools > Board menu (according to the microcontroller
on your board). The ATmega328 on the Arduino Nano comes preburned with a bootloader that allows
you to upload new code to it without the use of an external hardware programmer. It communicates using
the original STK500 protocol. You can also bypass the bootloader and program the microcontroller
through the ICSP (In-Circuit Serial Programming) header using Arduino ISP or similar.
⮚ Automatic (Software) Reset
The Arduino Nano is designed in a way that allows it to be reset by software running on a connected
computer. One of the hardware flow control lines (DTR) of the FT232RL is connected to the reset line
of the ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line
drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload
code by simply pressing the upload button in the Arduino environment. This means that the bootloader
can have a shorter timeout, as the lowering of DTR can be well-coordinated with the start of the upload.
This setup has other implications. When the Nano is connected to either a computer running Mac OS X
or Linux, it resets each time a connection is made to it from software (via USB). For the following half-
second or so, the bootloader is running on the Nano. While it is programmed to ignore malformed data
(i.e. anything besides an upload of new code), it will intercept the first few bytes of data sent to the board
after a connection is opened. If a sketch running on the board receives one-time configuration or other
data when it first starts, make sure that the software with which it communicates waits a second after
opening the connection and before sending this data.
Ho Chi Minh City University of Technology Electronic Workshop

2. Installation
2.1. System Required
Win XP, Win 7, Win 8, Win 10 32/64 bit.
2.2. Download, Install Arduino IDEt:
Step 1: Download Arduino IDE
Get the latest version from the Arduino: [Link] and choose Software. There is where
Arduino stores and updates the Arduino IDE versions and the latest version at the moment is ARDUINO
1.8.7. We proceed to Download, select Windows Installer
Step 2: Install Arduino IDE
Right click on the downloaded Arduino-1.8.3-windows file and select Run as administrator

The Arduino Setup: License Agreement window appears, select I Agree to continue
Ho Chi Minh City University of Technology Electronic Workshop
Immediately after, the Arduino Setup: Installation Options window appears. Here, pay attention to tick the
box Install USB Driver to install both the USB driver for Arduino and select Next to continue

The Arduino Setup: Installation Folder window appears, choose where to save the installation file
(default is C:\Program

File\Arduino) and select Next to begin the installation process.


Cửa sổ Arduino Setup: Installation Folder xuất hiện, chọn nơi lưu file cài đặt (mặc định là C:\Program
File\Arduino) và chọn Next để bắt đầu quá trình cài đặt.
Ho Chi Minh City University of Technology Electronic Workshop

Wait a few minutes for the device to install

When asked to confirm driver installation at the Windows Security window, select Install

Wait for the installation process to complete, select Close to exit.


Ho Chi Minh City University of Technology Electronic Workshop
Note: When installing the Arduino IDE for Windows 7 you may get an error that cannot connect
to the COM port. If you go to Device Manager to check, you will find the missing USB 2.0 Serial
Driver as shown below::

To fix this error, you can download and install the USB 2.0 Serial driver.
After downloading and extracting, go to the CH341SER folder, right-click on [Link] and select Run as
Administrator → Yes, the installa on program appears the DriverSetup dialog box, select INSTALL to
start the installation.
Ho Chi Minh City University of Technology Electronic Workshop

The program will appear a dialog box saying that the driver has been successfully installed (Driver
install success!). OK to exit.

Now we go back to Device Manager to check if the USB 2.0 Serial driver is installed successfully!
Note, the COM port in the picture below is for illustration only.

After installation, you will see a message like "COMx port has been installed successfully" (this "x" will
be replaced by a positive integer, remember to take this number, because you will use it later. this COMx
port to program the Arduino Nano)
So we have completed the installation of the Arduino IDE software.
Ho Chi Minh City University of Technology Electronic Workshop
3. Program Interface

3.1. Toolbar:
Includes menu command buttons (File, Edit, Sketch, Tools, Help). Below are icons that allow quick
use of commonly used IDE functions described as follows:
Ho Chi Minh City University of Technology Electronic Workshop

3.2. Text editor for writing code:


You will write your code snippets here. Your program name is displayed just below the row of Icons,
here it is named “Blink”. Notice that after the program name there is a "§". That means your program fragment
has not been saved.

3.3. Debug section:


Messages from the IDE will be displayed here. Notice that the bottom right corner shows the type of
Arduino board and the COM port used. Always pay attention to this section because if you choose the wrong
board type or COM port, you will not be able to upload your code.
Ho Chi Minh City University of Technology Electronic Workshop

3.4. Some notes when connecting the Arduino board to the Arduino IDE program:
3.4.1. Select Arduino board:
Example: Select Arduino Nano board

3.4.2. Select Processer :


In the Processer section, select ATmega 328 (Old Bootloader)
Ho Chi Minh City University of Technology Electronic Workshop

3.4.3. Select Port :


Now connect the Arduino Nano to the computer

Select port to connect

Note, the COM port in the picture below is for illustration only.

Confirm the COM port of the Arduino IDE in the bottom right corner of the workspace
Ho Chi Minh City University of Technology Electronic Workshop

4. Basic operations
4.1. Open and load sample program source code:
- Select menu File -> Open -> Examples -> 00.Code_Test -> 1.Code_Go_Straight.

- You will see the Arduino IDE open a new window containing the source code 1.Code_Go_Straight.
This code is the sample source code that controls the Walking Robot.

- Note: In the Sample Code File -> Open -> Examples -> 00.Code_Test includes 3 sample source
codes, depending on the requirements that we use for the meeting..
Ho Chi Minh City University of Technology Electronic Workshop

4.2. Load programs for Arduino


To load the program for the Arduino we need a cable to connect the Arduino to the computer. Before
loading the program, you need to check the correct Port (virtual data port when connecting to the board)
and Board (the name of the board you use) on the Arduino IDE by going to Tool → Board and Tool → Port to
review. section 3.4.
Note: If you choose the wrong type of Board or Port, your program will not be able to upload. After writing a
program, we proceed to compile and load the program for
Arduino.
4.2.1. Compile the program:

+ If the program you compose has no errors, the program will say Done compiling in the blue
message area, the black message area will announce some information such as: the number of bytes used
in the program and the total number of program bytes. can use…
Ho Chi Minh City University of Technology Electronic Workshop

+ If the program you compose has errors, the message bar turns orange and the IDE will list the errors
in the message bar
Ho Chi Minh City University of Technology Electronic Workshop
4.2.2. Load the program:

When the compilation is successful (the program has no errors), you proceed to load the program for
the board. When the notification bar shows Done uploading information, it means that you have
successfully loaded the program.

So we have successfully loaded the program for the Arduino Board.


Ho Chi Minh City University of Technology Electronic Workshop

5. Sample source code:


5.1. The source code for the robot to go straight: 1.Code_Go_Straight.

Attention: Only edit the source code in the guided section


Ho Chi Minh City University of Technology Electronic Workshop

5.2. The source code for controlling the robot to go straight and turn left:
2.Code_Go_Straight_and_Turn_Left.

Chú ý: Compare two source codes


Ho Chi Minh City University of Technology Electronic Workshop

6. Common errors and causes:


6.1. '...' was not declared in this scope: Undeclared value.

6.2. Problem uploading to board: Loading the program to the board failed.

- Board is not connected.

- Choose the wrong Board (refer to section 3.4.1).

- Select the wrong Processer (see section 3.4.2).


Ho Chi Minh City University of Technology Electronic Workshop
- Select the wrong Port (refer to section 3.4.3).

You might also like