0% found this document useful (0 votes)
12 views110 pages

GET 212 - Fundamentals of Computer Aided Engineering - Lecture 1 - Introduction To Arduino C Programming-Released

The document outlines the agenda and learning outcomes for the 'GET 212 – Fundamentals of Computer Aided Engineering' course, focusing on Computer Aided Engineering (CAE) and Arduino C. It includes an introduction to CAE, necessary tools like Linux OS and Arduino Starter Kit, and practical exercises involving Linux and Arduino programming. Students will learn to apply computer algorithms, programming languages, and CAE software to solve engineering problems.
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)
12 views110 pages

GET 212 - Fundamentals of Computer Aided Engineering - Lecture 1 - Introduction To Arduino C Programming-Released

The document outlines the agenda and learning outcomes for the 'GET 212 – Fundamentals of Computer Aided Engineering' course, focusing on Computer Aided Engineering (CAE) and Arduino C. It includes an introduction to CAE, necessary tools like Linux OS and Arduino Starter Kit, and practical exercises involving Linux and Arduino programming. Students will learn to apply computer algorithms, programming languages, and CAE software to solve engineering problems.
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/ 110

GET 212 – Fundamentals of Computer

Aided Engineering
Lecture 1: Introduction to CAE and Arduino C

Prof Christian Bolu


Agenda - Topic No 1
Introduction to CAE and Arduino C - Lecture
2

Theory
11:00 Course Learning Outcome and Course Plan [15 mins]
11:15 What is Computer Aided Engineering? [10 mins]
11:25 What we need: Linux OS, Arduino Starter Kit? [20 mins]
11:50 Break [10 mins]
Exercises/Practical
12:00 Lecture Ia: Gentle introduction to Linux – Ubuntu [30mins]
12:30 Lecture Ib: Gentle introduction to Arduino C [20mins]
12:50 Prepare for Laboratory Practical
Agenda - Topic No 1
Introduction to CAE and Arduino C - Practical
3

Practical
2:00 What is in the Starter Kit? [20 mins]
2:20 Installing CAELinux 2020 [15 mins]
2:40 Lesson 0 - Installing Arduino IDE [15 mins]
2:50 Break [10 mins/Catch Up]

3:00 Lesson 1 Add Libraries and Open Serial Monitor [20 mins]
3:30 Lesson 2 Blink [20 mins]
3:50 Break [20 mins/Catch Up]

4:00 Lesson 3 LED [20 mins]


4:00 Report Writing [30 mins]
4:50 Closing [10 mins/Catch Up]
Course Learning Outcome and
Course Plan [15 mins]
Introduction to CAE and Arduino C - Lecture
Course Learning Outcomes

Upon successful completion of the course, students will POs Assessment


be able to: Tools
Understanding computers and computing process 1 Quiz
Apply Computer algorithms for design using flowchart and 5 Assignment
pseudo-code.
Apply high level programming languages such as C and 1,3,5 Assignment
C++ syntax, flow of control, input/outputs construct, data
types.
Solve simple engineering problems using ARDUINO C. 3,5 Project
Analyse and construct simple Community engineering 6 Project
problems.
Using and applying Computer-Aided Engineering software for 1,5 Project
solving simple engineering analysis problems such as FEA,
CFD, etc.
Design and produce simple computer aided engineering 11 Project
community problem.
What is Computer Aided
Engineering? [10 mins]
Introduction to CAE and Arduino C - Lecture
Ehat is computer Aided Engineering?

Computer-aided engineering (CAE) is the use of


computer software to simulate performance in
order to improve product designs or assist in
the resolution of engineering problems for a
wide range of industries. This includes:
• Simulation, validation and optimisation of
products, processes, and manufacturing tools
• Computer-aided engineering is used in many
fields such as automotive, aviation, space, and
shipbuilding industries
Introduction to CAE and Arduino C - Lecture
What is computer Aided Engineering?

CAE areas covered include:


• Stress analysis on components and assemblies
using finite element analysis (FEA);
• Thermal and fluid flow analysis computational fluid
dynamics (CFD);
• Multibody dynamics (MBD) and kinematics;
• Analysis tools for process simulation for operations such
as casting, molding, and die press forming.
• Optimisation of the product or process.
• Embedded Systems for Control and Optimisation
Introduction to CAE and Arduino C - Lecture
What is computer Aided Engineering?

Embedded Systems

• An embedded system is a computer system with a


dedicated function within a larger mechanical or
electrical system, often with real-time computing
constraints.
• It is embedded as part of a complete device often
including hardware and mechanical parts. Embedded
systems control many devices in common use today.
What we need: Linux, Arduino,
Starter Kit? [20 mins]
Introduction to CAE and Arduino C - Lecture
What we need

Operating System
• Operating system is a software program that manages the computer
hardware, system resources, memory, and interaction between the
system and its users.
• Some popular operating systems are:
• Linux
• Unix-Solaris, SCO and Irix, AIX, HP-UX
• Microsoft DOS
• Microsoft Windows Vista
• Microsoft Windows Server 2012
• Android, BlackBerry, BSD, Chrome OS, iOS, Linux, share roots
in UNIX
❑ About UNIX http://www.unix.org/what_is_unix.html
❑ About Linux http://www.linux.org
Introduction to CAE and Arduino C - Lecture
What we need

Types of Operating Systems


Multi-User System
Single-User System • A multi-user system can run
multiple programs
• A single user system is a small, concurrently, share multiple
general-purpose system, used resources such as printers and
by one person at a time such as disks, and support multiple
a personal computer (PC). users working simultaneously
on a system.
• The example of a single-user The examples of multi-user
operating system is MS DOS.
operating systems are:
•Linux
•Unix
•Windows 10 & 11 Server
Introduction to CAE and Arduino C - Lecture
What we need

Evolution of Linux
• In 1991, Linus Torvalds, a student, while working on Minix
wrote the source code for the kernel and named it Linux.
• Torvalds made the Linux kernel available on the Internet.
• The Linux kernel was combined with the GNU system resulting
in a complete operating system called GNU/Linux because it
was a combination of the GNU system and Linux as the kernel.
• Linux follows the open development model which means that
the current development version of Linux is always open to
everybody.
• Tux, the Linux penguin, is the official mascot.

GNU is a recursive acronym for "GNU's Not Unix!", chosen because GNU's design is Unix-like, but differs
from Unix by being free software and containing no Unix code. Stallman chose the name by using various
plays on words, including the song The Gnu
Introduction to CAE and Arduino C - Lecture
What we need

❑ About Linux
• http://www.linux.org
❑ Distributions
• Red Hat based
• Debian based
• Slackware based
• Mandriva based
Linus Torvalds
• Fedora based
• SUSE based
Introduction to CAE and Arduino C - Lecture
What do we need – ARDUINO IDE?
Introduction to CAE and Arduino C - Lecture
What do we need – ARDUINO IDE?

Installing Libraries
Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

Arduino Starter Kit


Introduction to CAE and Arduino C - Lecture
What do we need?

CAE Linux 2020


Introduction to CAE and Arduino C - Lecture
What do we need?

CAE Linux 2020


Break [10 mins]
Gentle introduction to Linux –
Ubuntu [30mins]
Exploring Linux Command Line Tools
Features and Advantages of Linux

• The features of Linux are: The advantages of Linux are:


• Multi-programming •Reliability
• Time-sharing •Backward compatibility
• Multi-tasking •Simple upgrade and installation
• Virtual memory process
• Shared Libraries •Low total cost of ownership
• POSIX-Compliance •Support for legacy devices
• Samba •GUI interface
• Network Information System (NIS)•Multiple distributors
• Cron Scheduler •Excellent security features
• Office Suites •Support for high user load
• Data archiving utilities •Support for development libraries
• Licensing
• Web server
Exploring Linux Command Line Tools
Features and Advantages of Linux

Linux Architecture
Components of Linux operating system
Exploring Linux Command Line Tools
Features and Advantages of Linux

• The kernel:
• Is the core of Linux operating system program
• Controls the resources of the computer
• Interacts directly with the hardware
• The shell:
• Is a user interface providing services that a user wants
• Protects the user from knowing the intricate hardware
details
• Accepts and interpret text-mode commands
• Linux utilities and application programs:
• Are a collection of programs that service day-to-day
processing requirements
• Are invoked through the shell
Exploring Linux Command Line Tools
Features and Advantages of Linux

Comparing Linux with Unix


• Linux was developed keeping Unix as a
reference model and continue to have the
same basic architecture and features.
• Linux and Unix operating systems differ in:
• Hard disk space requirement
• Availability of shells
• Distributions or variants
• Licensing
Exploring Linux Command Line Tools
Features and Advantages of Linux

Distributions of Linux
• All the distributors use the Linux kernel.
• The distributors add their own utilities and
applications and sell these as a customized package.
• The following are the popular distributors of Linux:
• Red Hat and its variations, such as Linux ES, Linux
AS, Linux WS, Desktop, and Fedora Core
• Mandriva
• Debian (eg Ubuntu)
• SuSE
• Slackware
Exploring Linux Command Line Tools
Features and Advantages of Linux

Introduction to the Shell


• A shell:
• Is a utility program with
the Linux system that
serves as an interface
between the user and the
kernel
• Plays an important role of
command interpretation
for the kernel
• The adjacent figure shows the
architecture of the Linux
operating system.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Features of a Shell
• The shell has the following features:
• Interactive processing
• Background processing
• Input/output redirection
• Pipes
• Shell scripts
• Shell variables
• Programming language constructs
• Command history
• Command alias
• Job control
• The cd spell checker
• File name completion
• Command completion
Exploring Linux Command Line Tools
Features and Advantages of Linux

Shell as a Command Interpreter


• The shell:
• Reads the command
• Locates the file in the directories containing utilities
• Loads the utility into memory
• Executes the utility
Exploring Linux Command Line Tools
Features and Advantages of Linux

Shell as a Command Interpreter (Contd.)


The shell creates a child shell for the execution of a utility

The shell requests the kernel for any hardware interaction


Exploring Linux Command Line Tools
Features and Advantages of Linux

Unix Shells
• Some of the popular Unix Shells are:
• Bourne Shell: sh is the executable filename for
this shell
• C Shell: csh is the executable filename for this
shell
• Korn Shell: The executable filename is ksh
• Restricted Shell: Is typically used for guest
logins
Exploring Linux Command Line Tools
Features and Advantages of Linux

Linux Shells
• Some of the popular shells available in Linux are:
• Bash:
• Is an acronym for ‘Bourne Again Shell’ and is the default shell for most
Linux systems
• Uses the symbolic link sh, which is stored under the /bin directory in Fedora
Core 2
• Tcsh:
• Is an acronym for ‘Tom’s C shell’ also known as the TC shell
• It is an enhancement of the C shell
• Uses the symbolic link csh
• Can be executed by using either csh or tcsh at the shell prompt
• ASH:
• Is usually suitable on machines that have very limited memory
• Uses the symbolic link, bsh in Fedora Core 2
Exploring Linux Command Line Tools
Features and Advantages of Linux

Linux Shells
• bsh – Bourne Shell upon which bas is
built. Not often used in Linux
• csh – the original C Shell. Not often used
• ksh – the Korn Shell (ksh) takes the best
of Bourne Shell and C Shell.
• zsh – Z Shell form Korn Shell
Exploring Linux Command Line Tools
Features and Advantages of Linux

Changing the Default Shell


• The default shell of the user is specified in the /etc/passwd file.
• The chsh command can be used for changing the default shell for the
user
[steve@linuxpc1 /etc]$ chsh 
Changing shell for Steve.
Password:
New shell [/bin/bash]: /bin/csh
Shell changed.
• The full path for the new shell has to be given when changing the
shell.
• After the default shell has been changed from Bash to csh, the entry
for the user, steve, in the passwd file changes as follows
steve:x:503:513:steve walker:/home/steve:/bin/csh
Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell). NB Internal Commands
takes precedence to external commands when
they are same.

• cd– Change the working directory.


Example

cd /home/exercises – exercise directory


cd ῀ (tilde) - stands for home directory
Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell)

• pwd– Display the working directory.

Example
pwd

>/home/exercises – displays exercise directory


Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell)

• echo– Displays a Line of Text.

Example
echo Hello

>Hello– displays string Hello


Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell)

• exec– Execute a program. The new


process created replaces the shell.

Example
exec myprogram
Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell)

• time– Time of operation – how long the


system to execute a command (total
time, CPU time and system time).

Example
time pwd
Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are


built into the shell)

• set– related to the bash operation.

Example
set variable
Exploring Linux Command Line Tools
Features and Advantages of Linux

Internal Commands (Commands that are built into


the shell)

• exit – terminates any shell.


• logout– terminates only login shells Those
created automatically as you initiate a text-
mode login
Example
exit
logout
Exploring Linux Command Line Tools
Features and Advantages of Linux

Command Completion and History


• Command Completion: Type a part of a
command or filename and then press the
TAB key. The shell fills in what it can that is
unique.
• History : Keeps a record of all commands you
type and can be retrieved using the Up and
Down arrow keys (also Ctrl+P and Ctrl +N,
Crtl+R). Type Ctrl+G to terminate .
Exploring Linux Command Line Tools
Features and Advantages of Linux

Environment Variables
• All exported variables are environment variables, some of which are
meaningful to the shell.
• By changing the values of these variables, a user can customize the
environment.
• Some of the environment variables are:
• HOME: Stores the location of the HOME directory of a user
• PATH: Contains a list of colon-delimited path names of directories that
are to be searched for an executable program
• PS1: Contains the shell prompt, the $ symbol. You can change the shell
prompt by setting the value of this variable to the desired prompt
• PS2: Sets a value for the secondary prompt, which is by default >
• LOGNAME: Contains the user’s login name
• SHLVL: Contains the shell level that you are currently working in
• SHELL: Stores the user’s default shell
Exploring Linux Command Line Tools
Features and Advantages of Linux

The env Command


• The env Command enables you to view the list of all the
exported environment variables and their respective values.
• The following are some of the environment variables:
• HOME: Stores the location of the home directory of a user
• PATH: Contains a list of path names of directories that
are to be searched for an executable program
• PS1: Contains the shell prompt, $
• PS2: Sets the value of the secondary prompt
• LOGNAME: Contains the user’s login name
• SHLVL: Contains the shell level of the current shell
• SHELL: Stores user’s default shell
Exploring Linux Command Line Tools
Features and Advantages of Linux

Getting Help
man – Manual
• Text-based help document
• Uses the less pager, Exit with Q
• Organised in sections
1 – Executable programs
2 – System calls
3 – Library calls
4 – Device files
5 – File formats
6 - Games
to
9 – Kernel routine

info– Manual but uses hypertext format


Exploring Linux Command Line Tools
Features and Advantages of Linux

Streams
• Inputs and outputs from programs are
treated as streams
• Standard input
• Standard output
• Standard error
Exploring Linux Command Line Tools
Features and Advantages of Linux

Standard Files
• A computer system consists of mainly three parts:
•The input devices, such as keyboard and mouse,
are used to accept data from the user.
•The output devices, such as monitor and printer,
are used to display/print information or any error
messages that might occur.
•The processing device, such as CPU, processes
the user input according to the specified
instructions, to generate the desired output.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Standard Files (Contd.)


• Standard input file accepts the input from the user for various
commands that need input from the user.
• The keyboard is default source of input and is referred to as the
standard input file.
• Standard output file displays the output of a command to the
user.
• The monitor is default destination of output and is referred to
as the standard output file.
• Standard error file displays the error messages which are
generated during a command execution.
• The error message are displayed on the monitor by default and
therefore monitor acts as standard error file.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Redirection
• Redirection:
• Changes the assignments for the standard input, standard
output, and the standard error
• Enables you to take input to a command from a file other
than the keyboard
• Enables you to write the output of a command or the error
to a disk file or printed, instead of the monitor
• Is of the following three types:
• Input redirection
• Output redirection
• Error redirection
Exploring Linux Command Line Tools
Features and Advantages of Linux

Input Redirection
• The following example illustrates the usage of input
redirection:
$ cat < test1 
•The less than symbol, <, implies input redirection
from the file, test1.
• The above command can also be written using the
file descriptor as:
$ cat 0< test1 
•In the preceding code, 0 indicates input
redirection.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Output Redirection
• The following example illustrates the usage of output redirection:
$ cat test1 > out_test 
• The greater than symbol, >, implies redirection of output to the file, test2.
• In output redirection, the file to which the output is redirected is first created
on the disk as an empty file and then the output is sent to this file.
• If the file already exists, its content is deleted before the output is written to it.
• If you want to append the output to the file, test2, the command is:
$ cat test1 >> out_test 
• The previous commands can also be written using the file descriptor as:
$ cat test1 1> out_test 
$ cat test1 1>>out_test 
Exploring Linux Command Line Tools
Features and Advantages of Linux

Error Redirection
• Error redirection first creates the file to which the error
messages are redirected and then writes the error output to the
file.
• The following example illustrates the usage of error
redirection:
$ cat test_2 2> error-mesg 
• In the preceding command, the file, test_2, does not exist in
the current directory.
• When a user tries to execute the preceding command, Linux
will generate an error message because the execution is
unsuccessful. This message, which would otherwise be
displayed on the monitor (the standard error file), is written
to the file, error-mesg.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Filters
• A filter is a program that takes its input from the
standard input file, processes (or filters) it, and sends
its output to the standard output file.
• Some examples of filters are:
•grep
•cat
•wc
•tr
•cut
Exploring Linux Command Line Tools
Features and Advantages of Linux

The grep Filter


• The grep filter:
• Stands for Global Regular Expression Print.
• Searches a file for a particular pattern of
characters, and displays all lines that contain
that pattern. The pattern that is searched in the
file is referred to as the regular expression.
• Cannot be used without specifying a regular
expression.
• Has the following syntax:
grep [options] pattern [filename]
Exploring Linux Command Line Tools
Features and Advantages of Linux

Specifying Regular Expressions


• Regular expressions can be used to specify simple patterns of
characters to highly complex ones.
• The following table lists some simple patterns:

Regular Expression Pattern

‘A’ The character A


‘F’ The character F
‘New' The word New

• You can also specify complex regular expressions, such as, [], [] with
hyphen, ^, ^ within [], $, . (dot), and \ (backslash).
Exploring Linux Command Line Tools
Features and Advantages of Linux

The wc Filter
• The wc filter:
• Is used to count the number of lines, words, and characters in
a disk file or in the standard input
• Has the following syntax:
wc [option] [filename]
• The following table lists the options of the wc filter:

Option Function

–l Displays the number of lines

–w Displays the number of words

–c Displays the number of characters


Exploring Linux Command Line Tools
Features and Advantages of Linux

The cut Filter


• The cut filter:
• Is useful when specific columns from the output of certain
commands (such as ls, who) need to be extracted
• Has the following syntax:
cut [options] [filename]
• The following table lists the options of the cut filter:

Option Function

-f<column_number(s)> Displays the specified columns

-c<character_number(s)> Displays the specified


characters
-d<column_delimiter> Specifies the column delimiter
Exploring Linux Command Line Tools
Features and Advantages of Linux

The tr Filter
• The tr filter:
• Can be used to translate one set of characters to another
• Can also be used to squeeze repeated occurrences of a
character into one
• Uses the -s option to squeeze several occurrences of a
character into one character. For example,
who > temporary 
$ tr -s " " < temporary 
root tty1 Sep 28 17:02
steve pts/4 Sep 28 19:36 (172.17.55.167)
• Enables you to perform case-conversion
Exploring Linux Command Line Tools
Features and Advantages of Linux

The sort Filter


• The sort filter arranges each line of the standard input in ascending order.
• The following table lists the options of the sort filter:

Option Function
-r Sorts the input in reverse order
-f Arranges the input to the sort filter consisting of digits,
alphabets, and other characters in the ASCII sequence
-n Arranges the numbers also in ASCII sequence
<filename> Sorts the content of the specified file
+pos1 –pos2 Sorts a file in the order of a specific column
-t Creates a file with a different column separator
-o Saves the output of the sort filter to a disk file
Exploring Linux Command Line Tools
Features and Advantages of Linux

Pipes
• Pipes enable you to combine multiple commands and execute
them as a single command. For example,
$ ls | more 
• Pipes are represented using the vertical bar (|), which
indicates to the shell that the output of the command before
the ‘|’ is to be sent as input to the command after the ‘|’.
The following figure shows the working of a pipe:
Exploring Linux Command Line Tools
Features and Advantages of Linux

The tee Command


• The tee command:
• Pipes the standard output of a command to another
command, and also save it on disk for later use or
displays on the standard output
• Creates the file if the the file where data is to be written
does not exist
• Overwrites the content of the files if the file already
exists
• An example of the tee command is:
$ cat temp | tee temp1 temp2 
• The –a (append) option can be used to append the new
content to an existing file.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Modifying Stream of Data Using Sed


• The sed:
• Is basically known as the stream editor
• Can also be used as a filtering utility
• Enables you to read a line from an input file, apply an editing
command to the line, and send the result to standard output file
• Enables you to redirect the output of sed utility to a new file, but
the original file is not modified
• Has the following syntax for modifying data:
sed 'editing_command' [filename]
• The editing commands that can be used with the sed utility are:
• s: Replaces the specified text with a new text
• p: Prints the specified line
• d: Deletes the specified line
• q: Quits the sed utility
Exploring Linux Command Line Tools
Features and Advantages of Linux

Review
1. Summarize features that Linux shells offer to speed up
command entry.
The command history often enables you to retrieve an earlier command that's similar or identical to the
one you want to enter. Tab completion reduces typing effort by letting the shell finish long command
names or filenames. Command-line editing lets you edit a retrieved command or change a typo before
committing the command.

2. Describe the purpose of the man command.


The man command displays the manual page for the keyword (command, filename, system call, or other
feature) that you type. This documentation provides succinct summary information that's useful as a
reference to learn about exact command options or features.

3. Explain the purpose of environment variables.


Environment variables store small pieces of data-program options, information about the computer, and
so on. This information can be read by programs and used to modify program behavior in a way that's
appropriate for the current environment.
Exploring Linux Command Line Tools
Features and Advantages of Linux

Review
4. Describe the difference between standard output and
standard error.
Standard output carries normal program output, whereas standard error carries high-priority output,
such as error messages. The two can be redirected independently of one another.

5. Explain the purpose of pipes.


Pipes tie programs together by feeding the standard output from the first program into the second
program's standard input. They can be used to link together a series of simple programs to perform more
complex tasks than any one of the programs could manage.

6. Summarize the structure of regular expressions.


Regular expressions are strings that describe other strings. They can contain normal alphanumeric
characters, which match the exact same characters, as well as several special symbols and symbol sets
that match multiple different characters. The combination is a powerful pattern-matching tool used by
many Linux programs.
Gentle introduction to Arduino
Microcontroller [20mins]
Gentle introduction to Arduino C
Introduction to Microcontrollers

Microprocessors

❑Microprocessor is an integrated circuit (or chip) which


consists of many digital circuits (could be millions)
❑In PCs, housed on a mother board of the PC
❑Uses external bus interface to interface with memory,
mass storage, system I/O, etc
❑Requires peripheral chips to interface with I/O devices.
❑Developed for use in Personal Computers and
Workstations
❑High speed and large word size (32, 64-bit)
❑RAM in GB
❑Clock speed is in tens of GHz
Gentle introduction to Arduino C
Introduction to Microcontrollers

Microcontrollers
❑ Microcontroller is single chip device containing the processor along with
memory and interface devices on the same integrated circuit chip.
❑ Developed for use in control appliances, automotive, entertainment and
telecommunications industries
❑ Compact and low cost
❑ RAM from 1k to 100k of bytes
❑ Clock speed is in tens of MHz
❑ Uses internal bus to communicate with memory and other devices on the
chip
❑ Processor - used to execute program instructions. Called the Central
Processing Unit (CPU)
❑ Processor contains
❑ Control Unit – Determines timing and sequence operation
❑ Arithmetic Unit – performs logical evaluations and data manipulation
❑ Registers – memory locations inside the CPU that holds internal data
while instructions are being executed
Gentle introduction to Arduino C
Introduction to Microcontrollers

An Atmel-Based Microcontroller Card

CPU RAM
EEPROM Digital I/O

A/D Serial Interface Clock/Timer


Gentle introduction to Arduino C
Introduction to Microcontrollers

An Atmel-Based Microcontroller Card


Microcontroller Flash SRAM EEPROM Clock Digital Analog Voltage
memory (bytes) (bytes) Speed I/O Input
(bytes) Pins Pins

Arduino Uno 32K 2K 1K 16Mhz 14 6 5V

Arduino Nano 32K 2K 1K 16Mhz 14 8 5V

Digispark Pro 16K 2K 1K 16Mhz 14 10 5V

RoboRED 32K 2K 1K 16Mhz 14 6 5/3.3V

ATmega1280 128K 8K 4K 16Mhz 54 16 5V

ATmega2560 256K 8K 4K 16Mhz 54 16 5V

Arduino Leonardo 32K 2.5K 1K 16Mhz 20 12 5V

Arduino Due 512K 96K - 84Mhz 54 12/2 3.3V

ChipKITMax32 512K 128K - 80Mhz 83 16 3.3V


Gentle introduction to Arduino C
Introduction to Microcontrollers

Assembly Language Programming


"Hello World!" in Linux Assembly
section .data
hello: db 'Hello world!',10 ; 'Hello world!' plus a linefeed
character
helloLen: equ $-hello ; Length of the 'Hello world!'
string
; (I'll explain soon)

section .text
global _start

_start:
mov eax,4 ; The system call for write (sys_write)
mov ebx,1 ; File descriptor 1 - standard output
mov ecx,hello ; Put the offset of hello in ecx
mov edx,helloLen ; helloLen is a constant, so we don't need to say
; mov edx,[helloLen] to get it's actual value
int 80h ; Call the kernel

mov eax,1 ; The system call for exit (sys_exit)


mov ebx,0 ; Exit with return code of 0 (no error)
int 80h
Gentle introduction to Arduino C
Introduction to Microcontrollers

ARDUINO

Arduino Uno - The microcontroller


development board that will be at the
heart of your projects. It's a simple
computer, but one that has
no way for you to interact with it yet. You
will be building the circuits and
interfaces for interaction, and telling the
microcontroller how to interface with
other components.
Gentle introduction to Arduino C
[20mins]
Introduction to Arduino C
Building Blocks of Arduino C

Overview
❑ Expressions
❑ Statements
❑ Statement Blocks
❑ Function Blocks
Introduction to Arduino C
Building Blocks of Arduino C

Expressions
❑ An expression is created by combining operands and operators and always
resolves to one value.
❑ An operand is typically a piece of data that is acted upon by and operator
❑ An operator is often a mathematical or logical action that is performed on
one or more operands
Example
a +b addition
m – 3000 subtraction
g<d relational
A+B+C
Introduction to Arduino C
Building Blocks of Arduino C

Statements
❑ A statement is a complete C instruction for the computer.
❑ Statements end with a semicolon (;)
Example
a = b + c; assignment statement
j = 5 + k * 2; assignment statement
❑ A variable is a location in memory
❑ Operator Precedence
Precedence Level Operator

1 * , /, %
2 +, -
Introduction to Arduino C
Building Blocks of Arduino C

Statement Blocks
❑ A statement block consists of one or more statements grouped together so
they are viewed by the compiler as though they are single statement.
Example
If (time >= 5am) {
// next 3 statements form a statement block body
PutOnYourSports Dress(); //function block
GoToTheSportsField(); //function block
StartJogging() //function block
} else {
GoBackToSleep();
}
Introduction to Arduino C
Building Blocks of Arduino C

Function Blocks
❑A Function block is a block of code that is designed
to accomplish a single task.
Example
Void PutOnYourSportsDress(void) {
if (NotDressed) {
PutOnSportsDress();
PutOnRunningShoes();
}
ComeOutOfHostel();
WalkToSportsField();
}
Introduction to Arduino C
The Five Program Steps

Overview
❑ Initialisation Step
❑ Input Step
❑ Process Step
❑ Output Step
❑ Termination Step
Introduction to Arduino C
The Five Program Steps

Initialisation Step
❑ The purpose of the initialization step is to establish
the environment in which the program will run.
❑Background preparations before program execution.
❑ Ports needed are initialized, sensors activated,
thermocouples stabilized, etc
Introduction to Arduino C
The Five Program Steps

Input Step
❑ This is the sequence of program statements that are
necessary to acquire the information needed to solve
the task in hand.
❑ Data can come a sensor, potentiometer, file handle,
database or Wi-Fi, etc
Introduction to Arduino C
The Five Program Steps

Process Step
❑ This is responsible for taking a set of inputs and
processing it to get a new set of data.
❑ The sensor signals are interpreted.
Introduction to Arduino C
The Five Program Steps

Output Step
❑ After the process step has finished its work, new value
is output on some device or sent for further
processing.
❑ Eg The output may cause an LED to display a green
colour under normal condition or red under an
abnormal condition.
Introduction to Arduino C
The Five Program Steps

Termination Step
❑ The termination step has the responsibility of cleaning
up.
❑ In the Arduino C we do not normally use the
termination step.
Introduction to Arduino C
The First Example

Overview
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
// Pin 13 has an LED connected on most Arduino boards. give it a name:
int led = 13; // Step 1 Initialisation Step
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
// Step2-4 Input, Process and Output Steps
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
//Step 5, Termination Step not Used. Program runs forever
Introduction to Arduino C
The First Example

The setup() Function

❑ Every Arduino program must have a setup()


function
❑ It marks the actual start of the program
❑ The purpose of the setup() function is to set
the environment in which the program is run
❑The setup() function is executed once when the
program first starts
Introduction to Arduino C
The First Example

The loop() Function

❑ Every Arduino program must have a


loop() function
❑ The loop() function runs forever until you
remove the power, program is reset or a
component failure
❑ Program step 2-4 usually appear within
the loop()
Introduction to Arduino C
The First Example

Comments
❑ Comments do not form part of C statements and
therefore does not end with semicolon
❑ Single line Comment begin with a pair of slash (//)
characters
// Pin 13 has an LED connected on most Arduino boards.
❑ Multi-line Comments begin with a slash-asterisk pair (/*)
and end with an asterisk-slash pair (*/)
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
Introduction to Arduino C
Arduino C Library

Overview
❑ Visit http://arduino.cc/en/|Reference/HomePage
Introduction to Arduino C
Arduino C Library

pinMode()
Introduction to Arduino C
Arduino C Library

Check Out these!


Structures
❑ Control Structures
❑ Further Syntax
❑Arithmetic Operators
❑Comparison Operators
❑Boolean Operators
❑Pointer Access Operators
❑Bitwise Operators
❑Compound Operators
Introduction to Arduino C
Arduino C Library

Check Out these!

Variables
❑Constants
❑Data Types
❑Conversion
❑Variable Scope and Qualifiers
❑Utilities
Introduction to Arduino C
Arduino C Library

Functions
❑Digital I/O
❑Analog I/O
❑Due & Zero Only
❑Advanced I/O
❑Time
❑Math
❑Trigonometry
❑Characters
❑Random Numbers
❑Bits and Bytes
❑External Interrupts
❑Interrupts
❑Communication
❑USB (32u4 based boards and Due/Zero only)
Introduction to Arduino C
Arduino C Compilers & IDE

Compilers

❑ Arduino C is a sunset of ANSI


C(American National Standard
Institute (ANSI)

❑ Underlying Compiler for Arduino


C is the Open Source C++
Compiler
Introduction to Arduino C
Arduino C Compilers & IDE

Integrated Development Environment


❑ Arduino IDE
❑Others
❑CCS C Compiler
❑MPLAB
❑NetBeans
❑Eclipse
❑CodeLite
❑Quora
❑Kdevelop
❑Anjuta
❑Code Block
❑etc
Gentle introduction to Arduino C
Introduction to Microcontrollers

Review
1. What distinguishes a microcontroller from a microcomputer?
2. Where are program instructions stored in a microcontroller?
3. Which bus handles the transfer of data between CPU and
memory in a PIC microcontroller?
4. How is a PIC MCU ‘programmed’?
5. What is the advantage of storing data in an program memory?
6. What is an interrupt?
7. What are the advantages of programming in assembly
language?
Gentle introduction to Arduino C
Review Questions

1. Name the basic building blocks of a programming language


• Operands, operators
• Expressions
• Statements
• Statement Blocks
• Function Blocks
2. What is a binary operator?
• A binary operator is an operator that requires two operands to
create an expression
3. Why is an understanding of operator procedure important in an
expression?
• Operator precedence dictates the order in which sub-
expressions are evaluated in complex statements. Without this
understanding, it is possible that a complex statement will not
have the sub-expressions evaluated in the order in which you
wish, leading to erroneous results
Gentle introduction to Arduino C
Review Questions

4. Which of the Five Program Steps is least likely to appear in


Arduino programs and why?
• The Termination Step. The reason is because many
microcontroller programs are designed to run forever and may
never reach a termination point unless power is removed or a
component fails.
5. What is the purpose of the /* and */ character pairs?
• This sequence of characters mark the start and the end of a
multi-line comment in a program. They are also useful in
“commenting out” a chunk of code during program testing and
debugging.
6. What does “calling a function” mean?
• Program is transferred from its current place in the program to
the code associated with the function that is to be executed.
Gentle introduction to Arduino C
Review Questions

7. What does “return to the caller” mean?


• Occurs when program control finishes executing the code
associated with a function and program control returns to the
point at which the function was called.

8. When would using delay() be a poor program choice?


• Because delay() prevents communication with any of the
Arduino’s I/O pins while the delay() is being processed. It
would be a bad choice with programs that use interrupt Service
Routines.
Prepare for Laboratory Practical
Tutorial Guide

1. A folder labeled "code" which contains example


programs for many of the chapters in the tutorial. To use
these examples, just click on the file named for the
chapter (e.g. Lesson 4 RGB LED) and your Arduino
application will launch with the sample program already
in it, ready to upload. Remember you may need to
update the Library!
2. A folder labeled Libraries, that contains additional
libraries your Arduino software may need for certain
applications. Chapter 1 of the tutorial explains how to
use these libraries.
3. A folder labeled Datasheet which contains all the
technical datasheets of each components in your kit.

You might also like