You are on page 1of 10

Embedded Design: Enabling Robotics Fall 2018

EECE2160 Lab Assignment 0

Lab Assignment 0
ZedBoard Linux Getting Started
Introduction
This lab is an introduction to the Zedboard, an embedded computing device based on an ARM
processor and a Linux operating system. We will be using this platform throughout this course to
get a hands-on experience working with an embedded system. The platform is a very rich
environment with abundant hardware features, though we will primarily focus on the ARM
processor (CPU) and the Xilinx FPGA, both of which are part of the Zynq System-on-Chip, the
central chip on the ZedBoard. The ZedBoard also contains a wide set of input/output (I/O) devices,
among which we will use LED lights, switches, buttons, and Pmod interfaces connected to a
Wiimote and a robotic arm.
The Zedboard is running a version of the Ubuntu distribution of the Linux operating system, called
Xillinux (Xilinx + Linux). This is a slightly scaled-down version of Ubuntu, but has a lot of the
functionality of a full-fledged distribution of this operating system. The operating system runs on
the ARM processor, and supports the execution of custom C or C++ programs.
Instructions

Submission of lab reports


• Each lab assignment consists of a set of pre-lab questions, the actual time in the lab, and a
lab report.
• The pre-lab assignments prepare you for the challenges you will be presented with in the
actual lab. So that each lab member gets the same benefits, per-lab assignments have to be
solved by each student. Although you can discuss issues with your class and lab mates, the
pre-lab assignments have to be solved and submitted individually.
• Submit one lab report as one single Word or PDF document per individual.

Reading List
The following reading list will help you to complete the pre-lab assignment. The readings will
also help you in subsequent lab assignments. Please complete the readings that are marked
[Required] before attempting the pre-lab assignments.

[1] M.Stonebank: “UNIX Tutorial for Beginners” (Intro to Tutorial Five)


http://www.ee.surrey.ac.uk/Teaching/Unix/ [Required]

[2] Nano Tutorial: https://www.tutorialspoint.com/articles/how-to-use-nano-text-editor


[Required]

[3] C++ Language Tutorial: http://www.learncpp.com/

1 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0

Pre-Lab Assignment
Complete Tutorial [1] above. Nothing to turn in this time.

Lab Assignments

Lab 0.0 Connecting to the ZedBoard


The first step to familiarize yourself with our lab equipment consists in physically connecting the
ZedBoard and creating an SSH (Secure Shell) connection between your computer and the
ZedBoard:
1. Log in to the Windows desktop PC. We will refer
to this system as the host. Use your MyNEU
credentials.
2. Make sure your ZedBoard is powered, that is,
plugged in and with the power switch on the ON
position. Give it some time to finish the booting
process, usually around one minute. Then
connect the ZedBoard to the host via an Ethernet
cable (green cable on the right figure). Connect
one end of the Ethernet cable to the Ethernet
connector on the board, and the other end to the
Ethernet-to-USB adapter. Connect the USB end
of the adapter to the host.
3. Then find the MobaXterm program that will be
used to run a secure shell (ssh) to connect to the
ZedBoard. Select menu Sessions → New session
→ SSH, and fill in the basic SSH settings. The
ZedBoard has been configured to be accessible at the local IP address 192.168.1.10, and the
default SSH port is 22.
a. We have created different user accounts on the ZedBoards' SD cards. Your user name
will depend on the course section that you're registered in, as well as your board
number, as follows:

user<SectionNumber><GroupNumber>

b. Here, <SectionNumber> is the number of your EECE 2160 class section, and
<GroupNumber> is the 2-digit number of your group, printed on your computers and on
your board, using a leading “0” if necessary. For example, the group in Section 6 getting
the ZedBoard labeled “3” will have user name user603. The password is the same as
the user name.
4. Once you are logged in, type command pwd and make sure that the initial working directory is
set to /home/user<Section><Group> (for example /home/user603).

2 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.1 Hello-world on the ZedBoards
As a first lab assignment, we will run a simple hello world program on the ARM processor of the
ZedBoard.
1. Create a directory named lab0 in your home folder ( mkdir lab0 ). In the future, make sure
that you have a separate directory for each lab session, where you will place the corresponding
files.
2. With lab0 as your current working directory, use the nano editor to create a C++ source file
named hello.cpp ( nano hello.cpp ). Write the Hello World program in this file. An example
of a Hello World program is shown below:

// Example program: Hello World


#include <iostream>
#include <string>

int main()
{
std::cout << "Hello World \n";
return 0;
}

3. Use g++ to compile the program. You should generate an executable file named runhello,
also located in directory lab0. ( g++ -o runhello hello.cpp )
4. Execute the program and verify that the output is as expected. ( ./runhello )
5. Use MobaXterm to transfer the C++ source file back to the PC. It is your duty to save your
C++ files in safe place. (Jump drive, Google drive, Dropbox, ….)

Assignment 1
a) Provide a listing with the content of the C++ program that you wrote on the ZedBoard and then
transferred back into the host (file hello.cpp). Use pwd and ls -l.
b) Show a list of all commands you ran on the ZedBoard to edit the source, compile it, and run
the program executable.
c) Take a screenshot of the MobaXterm terminal after the execution of the program, and add it to
your report.
d) Replace the term std::cout from the program above with just cout from the program above and
try to recompile the file hello.cpp again. If it shows you an error, list what the error looks like
on your lab report.
e) Show your work to your course instructor/TA.

3 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.2 Hello-world on the ZedBoards part 2
As a second lab assignment, we will run a simple hello world part2 program on the ARM processor
of the ZedBoard.
1. Use the nano editor to create a C++ source file named hello2.cpp. Write the Hello World
part 2 program in this file like the one shown below:

// Example program: Hello World part 2


#include <iostream>
#include <string>

using namespace std;

int main()
{
cout << "Hello World \n";
return 0;
}

2. Use g++ to compile the program. You should generate an executable file named runhello2,
also located in directory lab0. ( g++ -o runhello2 hello2.cpp )
3. Execute the program and verify that the output is as expected. ( ./runhello2 )
4. Use MobaXterm to transfer the C++ source file back to the PC. It is your duty to save your
C++ files in safe place. (Jump drive, Google drive, Dropbox, ….)

Assignment 2
a) Provide a listing with the content of the C++ program that you wrote on the ZedBoard and then
transferred back into the host (file hello2.cpp). Use pwd and ls -l.
b) Show a list of all commands you ran on the ZedBoard to edit the source, compile it, and run
the program executable.
c) Take a screenshot of the MobaXterm terminal after the execution of the program, and add it to
your report.
d) What is the purpose of the line: using namespace std;
e) Delete the line using namespace std; from the program above and try to recompile the file
hello2.cpp again. If it shows you an error, list what the error looks like on your lab report.
f) Show your work to your course instructor/TA.

4 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.3 Sorting Algorithm
One quality that all engineers need to have is the ability to dissect a complex problem into multiple
smaller pieces. In this exercise we want to write a C++ program that generates an array of 10
random integer numbers between 0 and 99, prints the original array, sorts the array in ascending
order, and prints the sorted array. Follow each step carefully:

1. Use the nano editor to create a C++ source file named lab03.cpp, the template is shown
below:

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main()
{
//Create an array to hold 10 integer values: randomarray
//Generate 10 random integer values and save them to randomarray
//Display randomarray
//Sort randomarray in ascending order
//Display randomarray
return 0;
}

2. Create an array labelled randomarray to hold 10 integer values.


Compile your program and make sure you have no errors.

3. Generate a random number between 0 and 99, and save it to randomarray[0]. Display the value
of randomarray[0]. You can use a rand function to achieve this goal.
The pseudo code to achieve this:
srand (time(NULL));
x = rand() % 100;
Compile your program and make sure you have no errors.

5 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0

4. Using either a while loop or a for loop, generate 10 random numbers and save them to
randomarray.
Compile your program and make sure you have no errors.

5. Using a while loop or a for loop, display all the values in the array: randomarray.
Compile your program and make sure you have no errors. Run your program.

6. Sort randomarray in ascending order. You can use whatever algorithm you want to accomplish
this. One algorithm can be found at https://en.wikipedia.org/wiki/Selection_sort
This algorithm is based on finding the minimum element on the right of the array, and placing
it on the left in an iterative manner. In each iteration, the array will be split in two parts: one
that is sorted on the left, and one with the remaining unsorted elements on the right. As the
algorithm progresses, the sorted part grows, and the unsorted part shrinks.
Compile your program and make sure you have no errors.

7. Using a while loop or a for loop, display all the values in the array: randomarray.
Compile your program and make sure you have no errors. Run your program.

Assignment 3
a) Provide a listing with the content of the C++ program that you wrote on the ZedBoard and then
transferred back into the host (file lab03.cpp).
b) Show a list of all commands you ran on the ZedBoard to edit the source, compile it, and run
the program executable.
c) Take a screenshot of the MobaXterm terminal after the execution of the program, and add it to
your report.
d) Show your work to your course instructor/TA.

6 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.4 Address
In C++ you can display the address where all variables reside. The purpose of the assignment is
for you to display the address of all the variables used in your code.

1. Use Linux to copy the content of your lab03.cpp to lab04.cpp.

2. Modify lab04.cpp so that you display the address of randomarray, randomarray[0],


randomarray[1], …, randomarray[9] and any other variables you use in your program.

Assignment 4
a) Provide a listing with the content of the C++ program that you wrote on the ZedBoard and then
transferred back into the host (file lab04.cpp).
b) Show a list of all commands you ran on the ZedBoard to edit the source, compile it, and run
the program executable.
c) Take a screenshot of the MobaXterm terminal after the execution of the program, and add it to
your report.
d) Draw a Memory Table like the one shown below with their final values. Make sure that the
values of the Memory Address column are in ascending order.
e) Show your work to your course instructor/TA.

Memory Table for Lab 0.4

Variable Name Memory Address Memory Values


randomarray
randomarray[0]

randomarray[9]
(any other used variables)

7 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.5 Value vs Address
We are now ready to create a function for each task we accomplished in Lab 0.3 and Lab0.4.
Here are some suggestions on how to proceed:

1. Using Linux, copy the content of lab03.cpp into array.cpp.

2. You can start by writing a function named PrintArray with the following prototype:

void PrintArray(int v[], int size)


{
...
}

This function takes an array v of integers as the first argument, and its size in number of
elements as the second argument. The function traverses the array with a loop and prints all
elements between 0 and size – 1.

3. Write another function named RandomArray with the following prototype:

void RandomArray(int v[], int size)


{
...
}

This function should initialize size elements of array v to random values between 0 and 99.
You can use function rand() to generate random numbers. You can obtain information on
how to use this function from the manual pages with shell command man 3 rand. You can
limit the range of the generated random number with a modulo operation (operator % in C++).

8 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0

4. Write a function named SortArray with the following prototype:

void SortArray(int v[], int size)


{
...
}

As its name suggests, this function sorts array v composed of size integer elements in
ascending order. You can use whatever algorithm you want to use to sort the array.

5. Finally, write a main() program that instantiates an array of 10 elements and invokes the
previous functions in the appropriate order.

Assignment 5
a) Copy and paste your C++ source code of the program described above in your report.
b) List the sequence of commands that you ran in the shell to create the file, compile it, and
execute it.
c) Take a screenshot of the MobaXterm terminal after executing your program and include it in
your report. The screenshot also needs to show the output of the execution.
d) Show your work to your course instructor/TA.

9 v 1.23
Embedded Design: Enabling Robotics Fall 2018
EECE2160 Lab Assignment 0
Lab 0.6 Sorting an array of strings

1. Using Linux, copy the content of array.cpp into string.cpp.

2. Modify the content of string.cpp so that it reads in 10 random strings from the console, then
sorts them, and prints them sorted. You can start with your integer sorting program above
and modify it accordingly.

Assignment 6
a) Copy and paste your C++ source code of the program described above in your report.
b) List the sequence of commands that you ran in the shell to create the file, compile it, and
execute it.
c) Take a screenshot of the MobaXterm terminal after executing your program and include it in
your report. The screenshot also needs to show the output of the execution.
d) Make sure you use functions to partition your program.
d) Show your work to your course instructor/TA.

Delete all of your files/works from the Linux system.


Use rm, and/or rm –r as needed.

Laboratory Report
You need to follow the lab report outline provided on Blackboard. Your report should be
developed on a wordprocessor (e.g., OpenOffice, Microsoft Word), and should include graphics
when trying to present a large amount of data. Include the output of compiling and running your
programs.
Upload the lab report on blackboard as one PDF file per individual, and not per team. Each
individual needs to write his/her own lab report.

You are not allowed to turn in your Lab report until you have shown all of your work to your
course instructor/Teaching Assistant.
A zero will be assessed as your overall grade for this lab should you fail to show all of your work
to your course instructor/TA prior to submitting your lab report.

For this lab assignments, you are only allowed to use the following libraries:
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

Using any other libraries is prohibited and a Zero will be assessed as your overall grade for this
lab assignment.

10 v 1.23