Arduino
Arduino
http://www.adafruit.com/index.php?main_page=popup_image&pID=50
ATmega328 Features
http://www.atmel.com/Images/Atmel-8271-8-bit-AVR-Microcontrol
ler-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet.pdf
Arduino Uno R3
ATmega16u2 replaces FT232RL for USB-serial communication
http://www.adafruit.com/index.php?main_page=popup_image&pID=50
See: http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-uno-faq
Arduino Due Note: 3.3 V !!
http://www.adafruit.com/index.php?main_page=popup_image&pID=1076
See: http://arduino.cc/en/Main/ArduinoBoardDue
Arduino Duemilanove/Uno Features
Microcontroller ATmega168/328
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
16 KB (ATmega168) or 32 KB (ATmega328) of which 2
Flash Memory
KB used by bootloader
SRAM 1 KB (ATmega168) or 2 KB (ATmega328)
EEPROM 512 bytes (ATmega168) or 1 KB (ATmega328)
Clock Speed 16 MHz
http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove
http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf
ATmega328 Microcontroller
Pin
Pin number
name
Special
functio
n
Note the
limitations!
p. 316 Source:http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega328P
Absolute Maximums
Inpu
t
Outp
ut
Setting the Pin Data Direction
Arduino
pinMode(pin_no., dir)
Ex. Make Arduino pin 3 (PD3) an output
pinMode(3, OUTPUT);
pinMode(PIN_D3, OUTPUT); // with me106.h
time?
Yes! Answer coming later
Pin Voltages
Microcontrollers are fundamentally digital
devices. For digital IO pins:
Information is coded in two discrete states:
HIGH or LOW (logic: 1 or 0)
Voltages
TTL
5 V (for HIGH)
0 V (for LOW)
3.3 V CMOS
3.3 V (for HIGH)
0 V (for LOW)
Pin Used as an Output
Turn on an LED, which is
ATmega328
connected to pin Arduino pin 0
(PD0) (note the resistor!) Ardui
What should the data no
pin 0
direction be for pin 0 (PD0)? (PD0)
pinMode(____, ____);
Turn on the LED
digitalWrite(0,HIGH);
Turn off the LED
digitalWrite(0,LOW);
Recall the question:
Is there a way change the data direction for a set of
pins all at the same time?
All the work of MCU happens through registers
(special memory locations)
Registers on the Atmega328 are 8-bits wide
The data direction register (DDRx) handles the
data directions for pins in PORTx
Source:http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega328P p. 93
Data Direction Register
If the bit is zero -> pin will be an input
Making a bit to be zero == clearing the bit
If the bit is one -> pin will be an output
Making a bit to be one == setting the bit
To change the data direction for a set of pins
belonging to PORTx at the same time:
1. Determine which bits need to be set and cleared in
DDRx
2. Store the binary number or its equivalent (in an
alternate base, such as hex) into DDRx
ATmega328 Registers of Interest
See the ATmega328 data sheet, pp. 76-94
For digital IO, the important registers are:
DDRx
Data Direction bit in DDRx register (read/write)
PORTx
PORTx PORTx data register (read/write)
PINx
PINx PINx register (read only)
Example 1
Make Arduino pins 3, 5, and 7 (PD3, PD5, and
PD7) to be outputs
Arduino approach Alternate approach