Unit IV - Programming the Arduino and AVR Microcontrollers
Unit IV - Programming the Arduino and AVR Microcontrollers
Arduino LilyPad
DIY Arduino
Arduino Uno
5
Arduino uno
• What does it have?
• 14 Digital In/Out pins (6 can be used as PWM)
• 6 Analog Inputs
• A USB Connection
• A Power Jack
• Reset Button
• On-board LED
• SCL/SDA pins (Serial Clock/ Serial Data pins)
• In short, it contains everything needed to support the microcontroller; simply connect it
to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started.
6
USB
PWR IN
(to Computer)
RESET
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)
Analog
INPUTS
7
How to code in arduino
8
How to code in arduino
9
Program your arduino
10
Program your arduino
• The Arduino Uno can be
programmed with the Arduino
software. Select "Arduino Uno
from the Tools > Board menu
(according to the
microcontroller on your board).
• All the peripheral connected
with Computers are using
Serial Port.
• You can check port for Arduino
Uno in Device Manger.
11
Input vs output
12
6 Major concepts
• digitalWrite()
• analogWrite()
• digitalRead()
• If (statements) / Boolean
• analogRead
• Serial Communication
13
Analog vs digital
5V 5V
0V 0V
14
Analog vs digital
15
Serial communication
• “Serial” because data is broken into bits, each sent one
after another in a single wire.
• The two LEDs near the USB connector blink when data is
transmitted.
• RX blinks when the Arduino is receiving data.
• TX blinks when the Arduino is transmitting data
Compile
Status Message
IDE Preferences
dialog
The Arduino Executable Image
• Executable Arduino software (the executable image described earlier) typically
consists of three primary components:
• The sketch created by a developer,
• The libraries used to access the various functions of an AVR, and
• the runtime code that contains a main() function and a loop for the application
software to execute within.
• The tools and software components involved in creating executable code for an AVR
microcontroller can be divided into two primary categories:
host development tools and
runtime compilation sources, and
the target-side executable binary code for the AVR microcontroller.
Figure shows a block diagram of the primary Arduino software components, and includes the
user-supplied program (sketch) to show how things fit into a complete executable binary image.
The Arduino Software Build Process
Arduino software
organization
There are five main steps in the Arduino build process when using the IDE:
Source preparation
• The IDE also attempts to create function prototypes for any functions other
than setup() and loop() found in the sketch.
• These are placed at the top of the sketch file, immediately after any
comments or preprocessor statements (#include and #define) but before any
other types of statements.
Compilation
• Arduino uses the AVR-GCC compiler suite to translate the source code into
binary files called object files. These are not immediately executable, but
must be processed by the tool called the linker before the Arduino hardware