Getting Started

Authors
Affiliation

Dr Timothy Davies

Department of Electronic and Electrical Engineering

Dr Chris P. Jobling

Department of Electronic and Electrical Engineering

Published

October 21, 2024

Introduction

Microcontrollers are an important topic for the Electronics Engineer. So many modern devices have a microcontroller at their core, even apparently “dumb” products such as toasters and electric fans. Specifying the right microcontroller for a specific task is a useful skill, so in our Electronic and Electrical Engineering degree program you will be exposed to a number of different microcontrollers.

As an introduction to the subject, we shall learn how to program a popular 8-bit microcontroller in the “C” language. The specific microcontroller we shall be using is the Arduino Nano, a low-cost board with a range of useful features. Before we can program it, however, we shall have to install the Arduino Integrated Development Environment (IDE) onto your computer. If you are using one of the PCs in room B107, the software is already installed. The software is free, so you can install it on your own computer if you wish. The IDE has been produced in several versions, which can be run on Linux, Windows, and Apple computers.

A vast amount of information about the Arduino project can be found on their website, arduino.cc, including downloads for the IDE. Many of you already have some experience using Arduino harware and software, and so may have the IDE already installed.

Our friends in the Swansea Hackspace have an extensive web site, which also offers guidance on getting started with Arduino projects. Their website can be found at swansea.hackspace.org.uk. If you click on “Activities” followed by “Learning” you will be offered a range of tutorials, including one on the Arduino. Click on “Introduction to Arduino” and you will find a detailed description of the device. You may find it useful to read through some of these pages before starting on the installation procedure detailed below.

Installing the Arduino IDE 2 on Your Computer

Windows

Modern Windows 10 and 11 machines are capable of finding the necessary driver for the CH340 interface chip automatically. A good strategy would be to start the Windows 10 machine, and when it is ready plug in the Arduino Nano board using the supplied lead. After a few minutes, type Device Manager into the search box, and run the application offered to you. You should see a list of devices, including “Ports (COM and LPT)”. Click on this item and look at the lines following. One of these should read “USB-SERIAL CH340 (COM5)” or similar. Make a note of the COM port number and close the Device Manager.

Next, unplug the Arduino Nano board. Go to arduino.cc (Figure 20.1) and select the tab “Software&rdquo. This will bring up a new page of options (Figure 20.2). Move past”Arduino Web Editor” and look at the section titled “Downloads” and the box labelled Arduino IDE 2.1.1. Look on the right-hand side and click on “Windows Installer for Windows 10 and newer”, which is the first item in the list. When the installation file has finished downloading return to the previous page using “back” on your browser. In the section marked “Arduino IDE 2.1.1” you will see the words “For more details, please refer to the Arduino IDE 2.0 documentation.” . Click on the link labelled Arduino IDE 2.0 documentation to open the Arduino IDE 2 documentation page (highlighted in Figure 20.3) and then select Downloading and installing the Arduino IDE 2 from the table of contents to open the Downloading and installing the Arduino IDE 2 page (Figure 20.4).

Follow the detailed instructions for Windows to start the installer. There will follow quite a lengthy installation procedure, during which you will be offered additional drivers for other members of the Arduino family, including the boards offered by the company Adafruit. We recommend installing these additional drivers. When the installation is complete, plug in the Arduino Nano board and click on the “Arduino IDE” icon that has appeared on your desktop.

A screenshot of the web page arduino.cc with software selected in the page menu.
Figure 20.1: The homepage arduino.cc with software selected
A screenshot of the software page on arduino.cc with downloads highlighted.
Figure 20.2: The software page on arduino.cc
A screenshot of the Arduino IDE 2 page with the link to downloading and installing the Arduiono IDE 2 highlighted.
Figure 20.3: The Arduino IDE 2 page
A screenshot of the Arduino IDE 2 downloading and installation instructions page.
Figure 20.4: The installation instructions page.

Linux

Fortunately, all Linux systems have the necessary drivers in place already, so it is only necessary to install the Arduino IDE application.

Go to arduino.cc and select the tab “Software”. This will bring up the Arduiono IDE 2 page (Figure 20.2). Move past the instructions for “Arduino Web Editor” and look at the section titled “Downloads”. In the section marked “Arduino IDE 2.1.1” you will see the words “For more details, please refer to the Arduino IDE 2.0 documentation.” . Click on the link labelled Arduino IDE 2.0 documentation to open the Arduino IDE 2 documentation page (highlighted in Figure 20.3`) and then select Downloading and installing the Arduino IDE 2 from the table of contents to open the Downloading and installing the Arduino IDE 2 page (Figure 20.4). Follow the detailed instructions for Linux to start the installer.

There will follow quite a lengthy installation procedure, involving unpacking the tar file, and running the script “install.sh”, either from the command line or using “Run in terminal” from “Files”. During the installation you will be offered additional drivers for other members of the Arduino family, including the boards offered by the company Adafruit. We recommend installing these additional drivers. When the installation is complete, plug in the Arduino Nano board and click on the “Arduino IDE” icon that has appeared on your desktop.

Apple (MacOS)

Once again, go to arduino.cc and select the tab “Software”. This will bring up the Arduiono IDE 2 page (Figure 20.2). Move past the instructions for “Arduino Web Editor” and look at the section titled “Downloads”. In the section marked “Arduino IDE 2.1.1” you will see the words “For more details, please refer to the Arduino IDE 2.0 documentation.” . Click on the link labelled Arduino IDE 2.0 documentation to open the Arduino IDE 2 documentation page (highlighted in Figure 20.3`) and then select Downloading and installing the Arduino IDE 2 from the table of contents to open the Downloading and installing the Arduino IDE 2 page (Figure 20.4). Follow the detailed instructions for MacOS to start the installer.

Initial set up

When you are satisfied that the Arduino IDE has been successfully installed, run the application. Assuming that the installation procedure described above has gone to plan, and after the splash screen, the Arduino IDE main screen (Figure 20.5) appears.

A screen shot of the Arduino IDE 2 as it appears on first start up.
Figure 20.5: The Ardino IDE 2 Main Screen on First Run

Plug in the Arduino Nano board (Figure 20.6) using the supplied lead. Next look at the dropdown control labelled Select Board. Identify the connection which depends on your operating system but will be identified as a USB connection on MacOS and Linux, or may be labelled COM 5 (or some other number) on Windows (see Figure 20.7).

The Arduino nano microntroller mounted on breadboard.
Figure 20.6: The Arduino nano microntroller mounted on breadboard
The select port dialogue when setting up the Arduino IDE 2 to use the plugged in Adrduiono nano board.
Figure 20.7: Choose the port that your nano board is connected on. What you will see here depends on your operating system. I have shown what I see on my MacOS machine.

Once you have selected the correct port, you need to identify the board you are using. Search for nano as shown in Figure 20.8.

Shows the slect board dialogue. We have seached for nano and will the the offered selection 'Ardunino Nano'
Figure 20.8: Search for and select Arduino Nano.

Once you have set up your board, the board idenitfier changes to Arduino Nano in the menu bar as shown in Figure 20.9. You are now ready to compile your first program.

A screenshot of the Arduino IDE 2 fater it has been connected to the Arduino nano board.
Figure 20.9: Arduino IDE 2 set up and ready to go.

The Structure of an Arduino Program

Arduino provides a useful program stucture that is called a sketch. The structure of a sketch is illustrated in Figure 20.10.

Flow-chart of an Ardunino sketch program.
Figure 20.10: Flow-chart of an Ardunino sketch program

After the program starts, the setup subprocess (subroutine) is called once, and then the loop subprocess is called over and over again until the processor is restarted or power removed. Note there is no end state for the sketch program.

In the setup subprocess, the microcontroller will be set up for the application it is to execute. In the labs to follow, this will be to ensure that the IO is correctly configured.

In the loop process, we will set up the activities that will read inputs from the IO and provide suitable outputs. We will provide flow-charts for the examples that follow and you are expectd to provide flow diagrams for any modified programs in your lab diary.

You may wish to note that I used PowerPoint flowchart shape library to draw the flowcharts in this document.


  1. The built-in LED on the Arduino Nano board is connected to digital pin 13 which is GPIO pin 5 on port B. This port is not connected to any of the pins that come out of the Ardino Nano board (see Figure 3.12) and are available for connection to external I/O devices.↩︎

Copyright © 2021-2024 Swansea University. All rights reserved.