0% found this document useful (0 votes)
95 views

Technical Training I Manual 2022 Sem A - R1

This document provides instructions for an EE 3070 design project technical training on using Arduino boards and the Arduino IDE. It describes the purposes of the training, schedules, types of Arduino boards, installing and using the Arduino IDE, the basic structure of Arduino programs, serial communication functions, and includes self-practice exercises for students to complete. The exercises guide students through running an example blink program and modifying it to print timestamps to observe the output.

Uploaded by

Cc Cc
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)
95 views

Technical Training I Manual 2022 Sem A - R1

This document provides instructions for an EE 3070 design project technical training on using Arduino boards and the Arduino IDE. It describes the purposes of the training, schedules, types of Arduino boards, installing and using the Arduino IDE, the basic structure of Arduino programs, serial communication functions, and includes self-practice exercises for students to complete. The exercises guide students through running an example blink program and modifying it to print timestamps to observe the output.

Uploaded by

Cc Cc
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
You are on page 1/ 18

EE 3070 Design Project

Technical Training 1
Laboratory Manual
(Arduino IDE and Programming)

2022/23 Semester A

P.1
Purposes of this training
• To get familiar with Arduino board and the programming platform (Arduino IDE)
• To get familiar with Arduino basic programming

Schedules
1. Each individual practices the exercises and completes the tasks given in this
manual. Remember to give demo to the tutors as specified in the manual.
2. If you finish this manual fast, you can go ahead to read Technical Training II manual and
start to work on it
3. Take some time to read the report template to understand what are required.
Note: Students are not expected to leave earlier from the lab session.

P.2
1. Arduino Boards
Arduino is an open-source platform used for building electronic systems. It consists of hardware
(microcontroller) and software tool (Integrated Development Environment, IDE). The IDE
facilitates the programming and also downloads program to the hardware board.
More details can be found in the Arduino website. (http://arduino.cc/en/Guide/Introduction)
There are different types of Arduino boards with different features available in the market. In
this technical training, two types of Arduino boards may be used. They are Mega 2560 ver 3 and
Micro.
1.1 Arduino Mega 2560
Fig. 1 shows a photo of Arduino Mega 2560 ver 3. It provides many I/O pins and memory, so
that complex projects can be implemented. Pin layout of Mega 2560 ver 3 is given in Fig. 2.
Self-Reading Material: https://store-usa.arduino.cc/products/arduino-mega-2560-rev3

Fig. 1. Photo of Arduino Mega 2560 ver 3

Fig. 2. Pinout of Arduino Mega 2560 ver 3


P.3
1.2 Arduino Micro
Fig. 3 (a) and (b) show the photo of Arduino Micro and its pin layout, respectively.
Self-Reading Material: https://store-usa.arduino.cc/products/arduino-micro

Fig. 3 (a) Photo (b) Pin layout of Arduino Micro

Arduino Programming
To program an Arduino board, you need to use the Arduino IDE. A web-based version and a
downloaded version are available. Here, only the downloaded version is focused. If you are going
to use the web-based version, you may visit the following URL and create your own account.
URL for web editor: https://create.arduino.cc/editor
1.3 Installation of Arduino IDE
The followings describe the procedures for installing the Arduino IDE and drivers to your
PC/notebook.
a) According to the OS of your PC/notebook (eg. Windows or Mac OS X), download the
corresponding Arduino IDE from https://www.arduino.cc/en/Main/Software. You can click
Just Download.

Windows

Mac OS X

P.4
Click this to just download
Fig. 4. Screen showing the download of Arduino IDE.

b) Run the downloaded executable file (eg. Arduino-1.8.x-windows.exe for Windows) to


install the Arduino IDE, along with the driver if needed. (Note: The installation of IDE may
need the Administrator password of the PC/Notebook. If you are using the PC in the Lab
and need to install the Arduino IDE, please contact the in-charge technician/demonstrator.)

1.4 Brief Guides for IDE


Connect the Arduino board to the PC using a USB cable. Wait until the initialization of the board
finished (Note: The orange IDE on the board no longer blinking). For the first time, it may take
a moment.
a) Start Arduino IDE, check the settings
• Board: Select Arduino Micro OR Arduino Mega, according to your Arduino board

Fig. 5. Selection of Arduino boards

P.5
• Port: Select the proper communication port; Com XX (Arduino Micro) or (Arduino Mega)
[Your Port number may be different from the example shown in Fig. 6]

Fig. 6. Selection of communication Port

1.5 Managing Library


For some tasks, specific libraries may be needed. Procedures to add a library are as follows.
a) Click Tools->Manage Libraries.

Fig. 7. Menu for Manage Libraries

b) Search the library by typing its name and press Enter. The corresponding library will be
shown. You can then install the version that you want.
Insert library name here

Select latest
version
Click Install

Fig. 8. Search and install Libraries


P.6
1.6 Examples in the Libraries
Usually, examples are provided by the libraries. They can be found by click File->Examples.

Fig. 9. Program examples in Libraries

P.7
2. Software Design
Arduino program (also called sketch) follows C++ syntax, but with some functions related to the
hardware. As a controller program (called as “sketch”), it has a basic structure.
2.1 Basic Structure of a Sketch
The sketch (i.e. a program) in Arduino consists of two inevitable functions, called setup() and
loop(). (See Fig. 10)
a) setup()
The setup() function is called when a sketch starts. You can use it to initialize variables, set pin
modes, start using libraries, etc. The setup function will only run once, after each power-up or
reset of the Arduino board.
b) loop()
After running the setup(), the loop() function will be run. It will loop consecutively.
c) Before setup(), we usually include libraries, define some global variables, create some other
functions [Note: Those variables and functions can then be used in setup() and loop()].

Fig. 10. Basic Arduino program structure

2.2 Program Compilation and Uploading


After writing your program, you can first compile it to see whether there is any syntax error. The
compile button is . If your program is error free, you will see the memory usage. Then, you
can upload it to the Arduino board. The uploading button is .

P.8
3. Serial Monitoring
We can establish Serial communication between a PC and an Arduino board, if they are
connected via an USB cable. It is useful for debugging and also as an I/O interface of your
program.

3.1 Functions/Commands
a) Set up
• Serial.begin(val) : val is the baud rate.
• Serial.end(): disable the serial communication
Note: The baud rate in the program and the serial monitor should be the same.

b) Sending data to PC
• Serial.println and Serial.print: print the texts (with or without line return)

c) Receiving data from PC


• Serial.available() : get the number of byte available for reading from the serial port
• Serial.parseInt() : get the first valid integer from the serial buffer
• Serial.readString(): read characters from serial buffer and return as a string.

3.2 Serial Monitor


To receive / send data at PC side, you’ll need to open the Serial Monitor.

Fig. 11. Menu for Serial Monitor function

You need to make sure the baud rate setting at the terminal matching with your program.

Match this baud rate


with your program.
Serial.begin(115200)

Fig. 12. Serial Monitor


P.9
Self-Practicing Exercises
If you are using your own PC/notebook, you have to first install the Arduino IDE as described
in Sec. 2.1.
Practice 1:
Here, we’ll go through an example available in Arduino IDE.
a) Select the correct Board and Port for your Arduino board, as described in Sec. 2.2
b) Pick the example BlinkwithoutDelay as shown below

b) Press to compile the program, notice different kinds of memories usage.


c) Pressing button (Note: The board should be connected with PC using USB cable). It
will compile the code again and upload the program to the Arduino board. If no error is
detected, the Status Bar would display ‘Done Uploading’.

If error occurs, some error messages would be displayed. For example, below shows the case
that Arduino IDE cannot find the board on the given port. Correction is then needed, say, go
to Tool ➡ Port and select the correct port for the IDE.

P.10
Practice 2:
Modify the BlinkwithoutDelay as follows and observe the output

The output should be as follows

This must be the


timestamp You can disable the same as the value
timestamp by click set in the program.
this option

P.11
After you finished Practice 1 and 2, you can start on the following Training Tasks.
Training Tasks
Task 1. Understanding the Arduino Board
(You can refer to Self-reading Materials in Sec. 1.1 and 1.2)
Task 1.1
By checking the technical specification of MEGA 2560 ver 3, answer the following questions
Questions Your answers
1) What is the operating voltage of Mega 2560
ver 3?

2) In maximum, how many digital I/O pins you


can assign in Mega 2560 ver 3?

3) Which I/O pins can provide PWM output (give


the pin numbers)?

4) What is the smallest non-zero average voltage


that PWM output can provide?

5) How many pins can be used to read a sensor


for which its output is ranged from 0V to 3V?

6) Can we use an I/O pin to directly light up a


LED if it needs 2V and 10mA (without using
any driving circuit)?

7) If you use your Arduino board to read an


analog input, what is the possible largest
digital value you obtained?

8) How many serial communication pairs that


Mega 2560 has?

9) In maximum, how many bytes you can use for


your program code?

10) List all the pins that support external


interrupts?

P.12
Task 1.2
Answer questions to get familiar with pin assignment for communications.

This project will make use of different types of serial communications. They are based on
UART, I2C and SPI, respectively. [Please refer to Lecture notes]
a. There are four default UART Serial communications. One of them is also used for the
Serial monitor (So, you are not to use that serial, if you use Serial monitor). Circle the
transmitter and receiver pins of that serial port, and mark as UART
b. I2C communications use 2 pins, one is clock SCL and one is data SDA. Circle the default
pins that assigned for these functions, and mark as I2C.
c. SPI communications use 4 pins. They are clock (SCK), slave select (SS), master-input-
slave-output (MISO) and master-output-slave-input (MOSI). Circle the default pins that
assigned for these functions and mark as SPI.
P.13
Task 2 Get Familiar with the project platform
Task 2.1 Get Familiar with the modules
You’ll be given a project platform. Followings are the photo that contain all modules. In your
board, you may not have all the modules, but you should be able to identify their locations.

I
J

G
E

Modules The name of the module


A
B
C
D
E
F
G
H
I
J

P.14
Task 2.2 Transistor Circuit to drive LEDs
The driving circuit for RGB LED is shown below. For clarity, only one circuit is given.

common
anode
RGB LED

Explain how the driving circuit works to turn D2 on and off

P.15
Task 3. Programming Tasks
You are to complete all programming tasks given below.
Task 3A: Display color with RGB LED
Turn on the RGB LED to show three colors in sequence repetitively, each holds for 1 second
(Color 1→ Color 2 → Color 3 → Color 1 → …)
i) Draw the connection (in block diagram)
ii) Draw the flow chart of your design
iii) Do the actual programming

Provide your connection (in simple block diagram)

B.LED Input

Transistor
G.LED Input driving RGB
circuit LED

R.LED Input

Arduino
Jumper box

Note: The actual colors depend on your SID.


Last digit in your SID Color 1 Color 2 Color 3
0 Blue Green Magenta
1 Red Blue Yellow
2 Yellow Green Blue
3 Magenta Red Green
4 Blue Magenta Red
5 Green Yellow Blue
6 Magenta Blue Red
7 Red Yellow Green
8 Yellow Blue Red
9 Green Red Yellow

P.16
Flow Chart (Specify how to control the I/O pins, instead of giving the colors)

Remarks: Save your program as SID_task3A.ino for later report usage

CHECKPOINT: SHOW THE FLOWCHART AND RESULTS TO THE TUTOR

P.17
Task 3B: Display colors based on command inputs
Control the color display of a RGB LED by entering commands in the Serial monitor. You have
to describe your own mapping between the commands and the colors.
i) Give a description on your function mapping
ii) Do the actual programming
Remarks: Save your program as SID_task3B.ino for later report usage

CHECKPOINT: SHOW THE RESULT AND EXPLAIN TO THE TUTOR

Task 3C: Display different brightness based on command inputs


Control the color and brightness of a RGB LED by entering commands in the Serial monitor.
For example, Rxx indicate RED color with brightness of xx% (You may define your own
commands). But, in your design, you need to implement at least two colors and 3 levels of
brightness
i) Give a description on your function mapping
ii) Do the actual programming
Hint: analogWrite() is to be used.
Remarks: Save your program as SID_task3C.ino for later report usage

CHECKPOINT: SHOW THE RESULT AND EXPLAIN TO THE TUTOR

P.18

You might also like