Arduino
Introduction and Setup
The Arduino programming labs on this web site provide
an introduction to Arduino C++ programming.
Arduino experience is very useful for future courses such as MECH 368, MECH
370, MECH 371, MECH 390 (mini-capstone), MECH 490 (capstone), university club
projects (SAE, Space Concordia, etc.), and related Industrial / Aerospace
courses since they all involve Arduino programming and mechatronics. Mechatronics also has a very large role in
industry, so this is a very practical skill to learn.
In the labs you will read information, observe
examples/demonstrations, and solve various assignment problems. You will also develop and program your own
robot based on the material presented in the labs. This task is open and flexible depending on
the interests and ideas of the students.
Possible robot types include a two link robot, two wheel mobile robot, etc.
with sensors to guide the motion of the robot.
More information about possible robot designs will be posted later on.
Introduction
Arduino is a type of microcontroller board used for
mechatronics and robotics. The following
definitions are provided in order to elaborate.
A mechatronic system is a collection
of interacting components (i.e. a system) including mechanical, electronic,
computer, and software components. Mechatronics
is the study and implementation of mechatronic systems. Mechatronics is playing an increasingly large
role in engineering (Mechanical, Aerospace, Industrial, etc.) as products and
manufacturing become more automated and intelligent. Examples include self-driving / autonomous
vehicles, flying drones, robots, and the “internet of things”. Automotive, aerospace, manufacturing, and
computer companies (Amazon, Google, etc.) are all deeply involved in
mechatronic activities.
A microcontroller is a digital
computing device that combines a microprocessor with special input / output
capabilities (ADC, DAC, etc.) for mechatronic and control applications. It can provide the “brains” / controller for
a mechatronic system and the interface to related electronic components. For example, an automobile contains many (100
or more) microcontrollers which control everything from braking to engine
combustion.
An Arduino compatible board is a
microcontroller board that uses an Arduino C++ function library. This library provides relatively easy access
to the hardware capabilities of the microcontroller. Before Arduino was introduced there was no
standard function library for microcontrollers.
Therefore, it was significantly more difficult to program and implement
microcontrollers. Arduino also provides
a simple USB interface and a programming IDE to upload and monitor Arduino
programs. Before this was introduced special
(and more difficult to use) microcontroller programming hardware was normally
required. Together, these features make Arduino programming much easier to use
than other microcontroller boards. As
such, Arduino boards have become very popular with the hobby community,
students, and researchers for microcontroller applications. A wide variety of Arduino compatible boards
and related hardware (shields, interface boards, etc.) have also become
available.
The Arduino programming labs provide significant
introductory experience with Arduino programming and related hardware. In order to perform the labs, each lab group
(of exactly two students – not one, not three) is required to obtain an Arduino
Lab Kit from the UAV club in the ECA office. This kit provides a carefully selected list
of components that allows students to construct and program their own robot
(robot arm, mobile robot, etc.). Don’t
be too concerned about the function or utility of each item in the kit for now. That will become clear in future labs. Note that you will also use this kit in other
courses in later years, so it’s important to use and become familiar with all
the components in the kit. Please buy the
kit as soon as possible after you have found a lab partner. The Arduino lab kit contains the following
components:
Lab Tip: The
“Arduino lab kit” is just a collection of related components which you buy
individually from UAV club in the ECA office.
Each project group of 2 students should get
our special “MECH 215 Arduino kit” as
Note that each lab
group of two students buys one kit, so the expenses are divided by two. This amounts to a small price for each
student.
1) Arduino Compatible
Microcontrollers – quantity 2 (one for
each student)
Arduino Uno (better
compatibility with Macs and the lab computers) – quantity 1
Arduino Nano (good
for the project, good compatibility with Windows) – quantity 1
2) Servo Motors – quantity 2
https://www.banggood.com/Tower-Pro-MG90S-Metal-Gear-RC-Micro-Servo-For-RC-Model-p-74870.html
3) Ultrasonic Range Finder
This sensor is good for measuring distance and
obstacle avoidance.
4) Light Sensor – quantity 3
This sensor is good for measuring light, distance, and
obstacle avoidance.
5) Jumper Wires
Needed to connect the Arduino to components.
6) 5-Wire Block Connector – quantity 3
Good for connecting wires together without
solder. Note this course does not
require solder or a soldering iron.
7) Nano screw terminal shield – quantity 1
https://www.banggood.com/NANO-IO-Shield-Expansion-Board-For-Arduino-p-963967.html?cur_warehouse=CN
This very practical
item allows you to connect wires or male jumper pins to a Nano board using screw
terminals. This substantially reduces
the chance of loose wires (a significant problems with jumper wires and
breadboards) for your project. I have
used this connector in many of my projects (both research and industrial) and
it greatly improves the reliability of wiring connections without resorting to
soldering (causes fumes and a pain to make changes).
8) Poweradd Slim2 5000mAh
Ultra-Portable Charger External Battery
(or an equivalent power bank).
Note this is an
optional item in case you want to have a mobile / battery powered robot for
your project. You can buy it anytime
during the term if you decide you want one.
Note: you buy this item directly from www.amazon.ca and not the ECA.
This cell phone / tablet portable charger (a.k.a.
power bank) is needed to power the servo motors. It includes a charging cable you can use to
charge it from a PC USB port or a cell phone / tablet USB charger adapter. The power bank can also be used to power the
Arduino in order to make a mobile robot.
More information on that will be provided later.
Note: you should (no guarantees though) be able to use
any other brand / model of USB power bank.
This option might be desirable if you already have one and are sure it
won’t get damaged (i.e. it has short circuit protection)
The Poweradd Slim2 5000mAh
is the best option (in my experience) since it’s the least expensive model you
can get from a good manufacturer. I’ve
tried it and carefully compared it to many other models – this one is the best
bang for the buck. The quality is better
than many other more expensive models (some have loose USB connectors, lower
performance, etc.). Note that the 5000
mAh size provides the ideal weight / capacity tradeoff for small robots. The Poweradd Slim2
also charges fast (2A input) and has a 2A output (much better for robots than
power banks with just 1A output).
Furthermore, it also has short circuit and other forms of protection. Finally, this model looks nice and is light
(120g) which makes it great for using to top up your cell phone / tablet or
“re-gifting” it to a friend :)
If you want to spend more to get a larger capacity
power bank then make sure you get a model with two outputs (at least one with
2A) and a 2A input. Keep in mind,
however, they get heavier and larger as the capacity increases and thus less
suitable for small robots. A capacity of
12,000 mAh (typically weighing about 300g) is the upper suitable range in my
opinion.
Note: this
concludes the list of items in the Arduino lab kit.
Lab Tip: Once you
have the components above you can install and set up the Arduino software using
the instructions in the following section.
Don’t try connecting / wiring the components together at this
point since you can accidentally damage them if not done correctly. Wiring will be covered in Lab #2.
Setup
The computers in the MECH 215 lab rooms should have
all the required Arduino software installed (you
might have to download/install the Arduino IDE in
some cases). You just need to plug your
board in and run the Arduino programming IDE (at
least for the Arduino Uno board, the Nano boards
might have some problems on the lab computers). However, it’s best if you also
install the software on your own PC.
This section will guide you through the process of software installation
and testing the Arduino.
1) Driver installation
Note that you should not plug in the Arduino board
before installing the device driver since the OS might try to install
some other less compatible driver automatically.
Appropriate USB drivers need to be installed for the Arduino board.
Different brands of Arduino boards require
specific drivers. The Nano
microcontroller used in this course requires the following device driver (see
the links below). The Uno board in our
kit should not require installation of device drivers – 30 s after plugging the
Uno board into the computer the device driver should be automatically
activated.
http://wch.cn/downloads/file/65.html
-- windows download
http://wch.cn/downloads/file/178.html
-- mac download
http://wch.cn/download/CH341SER_ZIP.html
-- main driver page
Note that you need to be administrator of the computer
in order to install the device driver.
However, some computers might already have the drivers installed and in
some cases Windows will install the drivers automatically after the board has
been plugged in for 30s.
After the device driver software has been installed
you should re-boot the computer.
2) Installing the Arduino IDE
Make sure you have installed a text editor since it’s
useful for opening and modifying the Arduino program text files (which have
*.ino extensions). Instructions for this
are provided here:
http://users.encs.concordia.ca/~bwgordon/lesson1_software_installation.html
Previous versions of the Arduino IDE can be downloaded
here:
https://www.arduino.cc/en/Main/OldSoftwareReleases#previous
I normally prefer the previous versions since they are
more compatible with other Arduino hardware and libraries. There are also more than likely less bugs.
Note you should select the “Windows Installer” file
for Windows.
For the Mac you need to drag the Arduino folder into
your application folder after you have downloaded it.
For the lab I recommend Arduino
IDE version 1.8.5.
3) Testing the Arduino board
Once the USB driver and Arduino IDE software has been
installed you should perform a simple test of the Arduino board using the
Arduino IDE. The following video shows
how this is done.
http://users.encs.concordia.ca/~bwgordon/arduino_testing_windows.mp4
-- Windows
http://users.encs.concordia.ca/~bwgordon/arduino_testing_mac.mp4
-- Mac
For Linux here is some advice for getting the Arduino board working with the Arduino
IDE:
https://learn.sparkfun.com/tutorials/how-to-install-ftdi-drivers/linux
If the testing process doesn’t work it’s most likely
because the driver was not installed properly or due to some incompatibility
between your computer and the board. If
that happens try re-installing the driver software and check the process
carefully. If that doesn’t work then you
should try another computer / operating system if possible.
Note that the Arduino Uno board included in the lab kit (or any board
with an ATmega16U2 USB interface chip) should not require driver installation
on Windows, Mac, or Linux. This makes it
more compatible with a range of computers compared to the Nano board. You should thus try the Uno board on your
computer if you can’t get the Nano board working. The Nano board should work well on Windows
computers though. It’s better for the
project since you can use the Nano screw terminal board which helps reduce the
problem of loose wires (a significant problem with jumper wires and
breadboards).
After the board has been successfully tested you are
now ready to proceed to Lab #1.