Anda di halaman 1dari 33

The Arduino

Platform
ARDUINO ENVIRONMENT
Arduino Board
A development board/ Open-source
prototyping board
8-bit microcontroller
Programming hardware
USB programming interface
I/O pins
Microcontrollers
ATmega328 is the processor programmed by
the user
Atmega16U2 handles USB communication
Firmware
Two types of code executing on a simple
microcontroller:
Application Code
Executes the systems main functionality
We write this code
Firmware
Low-level Code: supports the main function
USB interface, power modes, reset, etc
Direct programming - Bootloader
Firmware on a microcontroller
Allows the flash and EEPROM to be
programmed
Manages USB communication, since
application programming is via USB
In-Circuit Serial Programming (ICSP)
A special programming method to program
the firmware
Needed because the bootloader cant
reprogram itself
Technical Specifications
Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
32 KB (ATmega328P)
Flash Memory
of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
Length 68.6 mm
Width 53.4 mm
Weight 25 g
ARDUINO TOOLCHAIN
Arduino Software
Arduino IDE
Software environment
Cross-compiler
Debugger
Simulator
Programmer
Arduino Software
Combine and Transform
All program files are combined into one
An #include is added to reference basic
Arduino Libraries
Function prototypes are added
A main() function is created
Compile and Link
avr-gcc is invoked to cross compile the code
Resulting code executes on AVR, not Intel
Generates an object file (.o)
Object file is linked to Arduino Library
Functions
Hex File Creation and Programming
avr-objcopy is invoked to change the format of
the executable file
A .hex file is generated from the .elf file
Arduino Programs
A program is called a sketch
C++ program using Arduino Library functions
C++ is a superset of C
All C Programs are legal C++
C++ also includes classes
Object-Oriented Programming (OOP)
Organize your code through encapsulation
Group together data and functions that are
related
User-defined type is specific to an application
Classes and Members
Example - Class Student
Declaration of a variable creates an object
. operator used to access members Data
and Functions
Functions can be defined inside the class
Advantages of OOP
All data is contained in one object
Reduced number of parameters
Point-specific functions are easily identified
Classes in Libraries
Ethernet.begin(mac);
Serial.begin(speed);
Client.print(Hello);
Serial.print(Hello);
PINS OF THE ARDUINO UNO
Pins
Pins are wires connected to the
microcontroller
Pins are the interface of the microcontroller
Pin voltages are controlled by a sketch
Pin voltages can be read by a sketch
Output Pins
Output pins are controlled by the Arduino
Voltage is determined by your sketch
Other components can be controlled through
outputs
Input Pins
Input pins are controlled by other components
Arduino reads the voltage on the pins
Allows it to respond to events and data
Digital vs. Analog
Some pins are digital-only
Read digital input, write digital output
0 volts (Gnd) or 5 V
Some pins can be analog inputs
Can read analog voltages on the pin
Useful for analog sensors
No pins can generate an analog output
INPUT AND OUTPUT

Software Instructions used in


Arduino sketches
Input/ Output (I/O)
These functions allow access to the pins
void pinMode(pin, mode)
Sets a pin to act as either an input or an
output
pin is the number of the pin
0 to 13 for the Digital pins
A0 to A5 for the Analog pins
mode is the I/O mode the pin is set to:
INPUT, OUTPUT, INPUT_PULLUP (input with
reversed polarity)
Digital Input
int digitalRead(pin)
Returns the state of an input pin
Returns either LOW (0 volts) or HIGH (5 volts)

Example:
int pinval;
pinval=digitalRead(3);
Digital Output
void digitalWrite(pin, value)
Assigns the state of an output pin
Assigns either LOW (0 volts) or HIGH (5 volts)

Example:
digitalWrite(3,HIGH);
Analog Input
int analogRead(pin)
Returns the state of an analog input pin
Returns an integer from 0 to 1023 because of
10-bit ADC (A to D Converter)
0 for 0 volts, 1023 for 5 volts
Example:
int pinval;
pinval = analogRead(A3);
Pin must be an Analog pin
Delay function
void delay(t)
Pauses the program for t milliseconds
Useful for human interaction
Arduino Shields
Special-purpose shields
Daughter boards
Unique functionalities
Easy to attach
Good libraries provided

Anda mungkin juga menyukai