Arduino
Arduino
Arduino
A
sn
ea
k
pe
ek
int
o
th
e
Ar
du
ino
W
orl
d
Contents
What is Arduino microcontroller?................................................................................3
Components in an Arduino UNO................................................................................. 4
Power (USB / Barrel Jack)......................................................................................... 4
Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)...................................................4
GND (3):.................................................................................................................. 4
5V (4) & 3.3V (5):.................................................................................................... 4
Analog (6):............................................................................................................... 4
Digital (7):............................................................................................................... 4
PWM (8):.................................................................................................................. 4
AREF (9):................................................................................................................. 4
Reset Button............................................................................................................ 4
Power LED Indicator................................................................................................ 5
TX RX LEDs.............................................................................................................. 5
Main IC.................................................................................................................... 5
Voltage Regulator.................................................................................................... 5
Clock....................................................................................................................... 5
Random access memory (RAM)............................................................................... 5
EEPROM................................................................................................................... 5
Arduino microcontrollers Vs. Microprocessors............................................................6
A Microcontroller..................................................................................................... 6
A Microprocessor..................................................................................................... 6
How does Arduino microcontrollers processors work? (instruction cycle)..................7
More Details:........................................................................................................... 7
Registers Used:.................................................................................................... 7
Steps:...................................................................................................................... 8
Fetch Cycle........................................................................................................... 8
Decode the Instruction......................................................................................... 8
Read the effective address...................................................................................8
Execute the Instruction:(Step 4 of the Instruction Cycle is the Execute Cycle).. . .8
Coding language and software................................................................................... 9
Machine Code could probably be considered the lowest level programming
language.................................................................................................................... 9
1 | Page
Assembly language is at the level of telling the processor what to do. There is
still a conversion step towards machine code............................................................9
C is a step up from assembler, because you get to specify what you want to do
in slightly more abstract terms, but you're still fairly close to the metal....................9
C++ does everything that C can do but adds the capability to abstract things
away into classes....................................................................................................... 9
Java/C# do similar things to C++ in a way, but without the opportunity to do
everything you can do in C (like pointer manipulation in Java's case [thanks Joe!]).
They have garbage collection though, which you have to do manually in C++.........9
Python/Ruby are even higher level, and let you forget about a lot of the details
that you would need to specify in something like Java or C#.....................................9
Integrated development environment.....................................................................9
IDEs for Arduino:(Most common two)....................................................................10
Embedded Code Life Cycle:................................................................................... 10
Embedded Code Main Parts:..................................................................................11
What is an embedded System?................................................................................12
Definition and Example............................................................................................ 12
Features of Arduino.................................................................................................. 13
Digital input and output............................................................................................ 14
ADC (analogue to digital conversions)......................................................................15
Timers and interrupts............................................................................................... 16
Bit logic operations................................................................................................... 17
Pointers.................................................................................................................... 18
PWM......................................................................................................................... 19
Communication........................................................................................................ 20
Open source libraries................................................................................................ 21
How to simulate projects.......................................................................................... 22
Using Portus............................................................................................................. 23
Example................................................................................................................... 24
References Used:...................................................................................................... 25
2 | Page
3 | Page
GND (3): Short for Ground. There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
Digital (7): Across from the analog pins are the digital pins (0 through 13 on the
UNO). These pins can be used for both digital input and digital output.
AREF (9): Stands for Analog Reference. Most of the time you can leave this pin
alone. It is sometimes used to set an external reference voltage (between 0 and 5
Volts) as the upper limit for the analog input pins.
Reset Button
the Arduino has a reset button (10). Pushing it will temporarily connect the reset pin
to ground and restart any code that is loaded on the Arduino.
TX RX LEDs
TX is short for transmit, RX is short for receive. These markings appear quite a bit in
electronics to indicate the pins responsible for serial communication. In our case,
there are two places on the Arduino UNO where TX and RX appear once by digital
pins 0 and 1, and a second time next to the TX and RX indicator LEDs (12). These
LEDs will give us some nice visual indications whenever our Arduino is receiving or
transmitting data (like when were loading a new program onto the board).
Main IC
Integrated Circuit (13). Think of it as the brains of our Arduino. The main IC is
usually from the ATmega line of ICs from the ATMEL company. This can be
important, as you may need to know the IC type (along with your board type) before
loading up a new program from the Arduino software. This information can usually
be found in writing on the top side of the IC. If you want to know more about the
difference between various ICs, reading the datasheets is often a good idea.
Voltage Regulator
The voltage regulator (14) does exactly what it says it controls the amount of
voltage that is let into the Arduino board. Think of it as a kind of gatekeeper; it will
turn away an extra voltage that might harm the circuit. Of course, it has its limits,
so dont hook up your Arduino to anything greater than 20 volts.
5 | Page
Clock
A clock that provides timing pulses that control the pacing of program instructions
as they are executed one at a time by the CPU.
EEPROM
A special type of memory that holds the program that runs on a microcontroller.
EEPROM stands for Electrically Erasable Programmable Read-Only Memory, but that
wont be on the test.
6 | Page
A computer on a chip.
It differs from normal desktop or laptop
computers in that a microcontroller is an
application specific computer that usually
runs a single program performing dedicated
task(s) while the latter two are general
purpose computers that can run numerous
programs depending on a users needs. A
microcontroller contains on chip CPU,
input/output interface, memory, clock,
timer, and an assortment of other
peripherals.
A Microprocessor
-
7 | Page
8 | Page
An instruction cycle (sometimes called fetch-decodeexecute cycle) is the basic operation cycle of a
computer.
More Details:
Registers Used:
1- Program counter (PC) - an incrementing counter that
keeps track of the memory address of the instruction
that is to be executed next or in other words, holds the
address of the instruction to be executed next.
2- Memory address register (MAR) - holds the address of a
memory block to be read from or written to.
3- Memory data register (MDR) - a two-way register that
holds data fetched from memory (and ready for the
CPU to process) or data waiting to be stored in
memory. (This is also known as the memory buffer
register (MBR).)
4- Instruction register (IR) - a temporary holding ground
Figure 5 detailed instructions cycle
for the instruction that has just been fetched from
memory.
5- Control unit (CU) - decodes the program instruction in the IR,
selecting machine resources such as a data source register and a particular
arithmetic operation, and coordinates activation of those resources.
6- Arithmetic logic unit (ALU) - performs mathematical and logical operations.
9 | Page
Steps:
Fetch Cycle. This step is the same for each instruction.
1- The CPU sends PC to the MAR and sends a READ command on the control bus
2- In response to the read command (with address equal to PC), the memory
returns the data stored at the memory location indicated by PC on the data
bus.
3- The CPU copies the data from the data bus into its MDR.
4- A fraction of a second later, the CPU copies the data from the MDR to the
Instruction Register (IR)
5- The PC is incremented so that it points to the following instruction in memory.
This step prepares the CPU for the next cycle.
The Control Unit fetches the instruction's address from the Memory Unit
10 | P a g e
C++ does everything that C can do but adds the capability to abstract things
away into classes.
Python/Ruby are even higher level, and let you forget about a lot of the
details that you would need to specify in something like Java or C#.
SQL is even higher level (it's declarative). Just say "Give me all the items in
the table sorted by age" and it will work out the most efficient way to carry
this out for you.
11 | P a g e
ARDUINO
Atmel Studio
Coding
PreProces
sing
Compiling
Assemblin
g
Linking
Binary
Conversti
on
12 | P a g e
13 | P a g e
Example
14 | P a g e
Features of Arduino.
Arduino Microcontrollers can do
we are going to discuss some
explanation in which a real time
might be combination of some
mentioned.
a lot of things
basics only for
application
features
(Its a 1 or 0)
detects if a
specific
higher than
detect the
voltage is lower
will detect the
voltage is above/below a
threshold. If the voltage is
some value, the computer will
digital input as high/set/1. If the
than some value, the computer
digital input as low/clear/0.
allows you to
computer. If the
to be high, the
(generally
computer
is connected to
voltage.
Digital Example:
const int buttonPin = 2;
pushbutton pin
const int ledPin = 13;
LED pin
// the
// the
number of the
number of the
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
Figure 13 Digital Example
15 | P a g e
Analog to digital conversions are dependent on the system voltage. Because we predominantly use
the 10-bit ADC of the Arduino on a 5V system, we can simplify this equation slightly:
If your system is 3.3V, you simply change 5V out with 3.3V in the equation. If your system is 3.3V
and your ADC is reporting 512, what is the voltage measured? It is approximately 1.65V.
If the analog voltage is 2.12V what will the ADC report as a value?
16 | P a g e
17 | P a g e
Types of interrupt:
Reset
Timer
Hardware
external
Interrupts
Serial
Software
Edge
triggered
Level
triggered
18 | P a g e
Interrupt example:
#include < avr/io.h > // Definition of interrupt names
#include < avr/interrupt.h > // ISR interrupt service
routine
value = digitalRead(sensePin);}
void setup() {
Serial.begin(9600);
Serial.println("Initializing ihandler"); // sets the digital pin as output
pinMode(ledPin, OUTPUT); // read from the sense pin
pinMode(sensePin, INPUT);
Serial.println("Processing initialization"); // Global Enable INT0 interrupt
GICR |= ( 1 < < INT0); // Signal change triggers interrupt
MCUCR |= ( 1 << ISC00);
MCUCR |= ( 0 << ISC01);
Serial.println("Finished initialization");}
void loop() {if (value) { Serial.println("Value high!");digitalWrite(ledPin, HIGH);
} else { Serial.println("Value low!"); digitalWrite(ledPin, LOW); }
delay(100);}
19 | P a g e
Timers:
The Arduino 'delay' function is both a blessing and a curse. Its great for showing
beginners how to make an LED flash. But as soon as you get more complex and
start slowing down your 'loop' function you will run into problems.
The disadvantage of the delay approach is that nothing else can go on while the
'delay' is happening. You cannot update a display, or check for key presses for
example.
-
operand1
0 1 0 1
operand2
---------0 0 0 1
In Arduino, the type int is a 16-bit value, so using & between two int expressions
causes 16 simultaneous AND operations to occur. In a code fragment like:
int a = 92;
// in binary: 0000000001011100
int b = 101;
// in binary: 0000000001100101
0000000001000100, or 68 in decimal.
Each of the 16 bits in a and b are processed by using the bitwise AND, and all 16
resulting bits are stored in c, resulting in the value 01000100 in binary, which is 68
in decimal.
One of the most common uses of bitwise AND is to select a particular bit (or bits)
from an integer value, often called masking. See below for an example
Bitwise OR (|)
The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, |
operates independently each bit in its two surrounding integer expressions, but
what it does is different (of course). The bitwise OR of two bits is 1 if either or both
of the input bits is 1, otherwise it is 0. In other words:
0 0 1 1
operand1
20 | P a g e
0 1 0 1
operand2
---------0 1 1 1
operand1
0 1 0 1
operand2
---------0 1 1 0
// binary: 1100
int y = 10;
// binary: 1010
Communication.
-
Arduino Supports:
o Serial
o Bluetooth
o GSM/GPRS
o KNX/EIB
o Wi-Fi
21 | P a g e
PWM.
Pulse Width Modulation, or PWM, is a technique for getting analog results with
digital means.
Digital control is used to create a square wave, a signal switched between on and
off. This on-off pattern can simulate voltages in between full on
and off
by changing the portion of the time the signal
spends on versus the time that the signal spends
off.
The duration of "on time" is called the pulse width.
To get varying analog values, you change, or
modulate, that pulse width. If you repeat this onoff pattern fast enough with an LED for example,
the result is as if the signal is a steady voltage
between 0 and 5v controlling the brightness of the
LED.
PWM Example:
int led = 9;
attached to
int brightness = 0;
int fadeAmount = 5;
LED by
the
23 | P a g e
Libraries are a collection of code that makes it easy for you to connect to a
sensor, display, module, etc. For example, the built-in Liquid Crystal library
makes it easy to talk to character LCD displays. There are hundreds of
additional libraries available on the Internet for download. The built-in
libraries and some of these additional libraries are listed in the reference. To
use the additional libraries, you will need to install them.
24 | P a g e
Advantage of being an open source is that its always updating where coding
becomes easier as functions are everywhere when you have internet.
25 | P a g e
26 | P a g e
References Used:
-
https://en.wikipedia.org/wiki/Arduino
https://learn.sparkfun.com/tutorials/what-is-an-arduino
https://en.wikipedia.org/wiki/Instruction_cycle
http://www.dummies.com/how-to/content/electronics-componentsintroducing-microcontroller.html
http://stackoverflow.com/questions/3468068/low-mid-high-level-languagewhats-the-difference
http://www.arduino.cc/en/Main/FAQ
https://en.wikipedia.org/wiki/Embedded_system
http://www.slideshare.net/abhisheksutrave/embedded-systems-in-automobile
https://labjack.com/support/faq/what-are-digital-io
https://learn.sparkfun.com/tutorials/analog-to-digital-conversion
https://www.arduino.cc/en/Tutorial/AnalogInput
https://www.arduino.cc/en/Tutorial/Button
https://gonium.net/md/2006/12/20/handling-external-interrupts-with-arduino/
https://www.arduino.cc/en/Reference/BitwiseAnd
http://www.labcenter.com/products/vsm/arduino.cfm
http://playground.arduino.cc/Code/PIDAutotuneLibrary
27 | P a g e