Lecture 6 Introduction to the ATmega328 and Arduino, CSE P567, University of Washington, http://courses.cs.washington.edu/courses/csep567/10wi/lectures/lect ures.html. Intro to Arduino, Linz Craig, Nick Poole, Prashanta Aryal, Theo Simpson, Tai Johnson, and Eli Santistevan, Sparkfun Electronics. Beginning C for Arduino, Jack Purdum, Ph.D., Technology in Action, 2012. 2012
Topics Objectives
Programming the Arduino Uno Rev3 (cont.) Creating project on Atmel Studio
PWR IN
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Di it l I\O Digital
PWM(3, 5, 6, 9, 10, 11)
Analog INPUTS
5 6
Example-- Fading
Challenge a Change the rate of the fading in and out. There are at least two different ways to do this can you figure them out? Challenge b Use 2 (or more) LEDs so that one fades in as the other one fades out. out
to Digital Pin Pi 9
Digital Input
Connect digital input to your Arduino using Pins # 0 13 (Although pins # 0 & 1 are also used for programming) Digital Input needs a pinMode command: pinMode (pinNumber, INPUT); Make sure to use ALL CAPS for INPUT To get a digital reading: int buttonState = digitalRead (pinNumber); Digital Input values are only HIGH (On) or LOW (Off)
Digital Sensors
Digital sensors are more straight forward than Analog No matter what the sensor there are only two settings: On and Off Signal is always either HIGH (On) or LOW (Off) Voltage signal for HIGH will be a little less than 5V on your Uno Voltage signal for LOW will be 0V on most systems
Boolean Operators
<Boolean> Description
( ( ( ( ( (
) ) ) ) ) )
( ( ( ( ( (
) ) ) ) ) )
is equal? is not equal? q greater than greater than or equal less than less than or equal
http://opensourcehardwarejunkies.com/tutorial-03-
analogRead()
Arduino uses a 10 10-bit bit A/D Converter: this means that you get input values from 0 to t 1023
0V 0 5 V 1023
Ex:
int sensorValue = analogRead(A0);
Initializes the Serial Communication Arduino dedicates Digital I/O pin # 0 to receiving and Digital I/O pin #1 to transmit.
D Development l tT Tools l
Atmel Studio 6 is the integrated development environment (IDE) for developing and debugging embedded applications based on Atmel AVR and ARM Cortex-M microcontrollers (MCUs) in C/C++ and assembly code code. The IDE brings together an editor with assisted code writing, a wizard for quickly creating new projects, the Atmel Software Framework with free source code library, a GNU C/C++ Compiler, a powerful simulator, and the front-end for all Atmel programmers and in-circuit debuggers.
2102444 Introduction to Embedded Systems 30
31
32
35
36
Example 1
38
Example 2 Exercise
#include #i l d < <avr/io.h> /i h> #include <util/delay.h> int main(void) { DDRB = 0xff; while (1) { f (int for (i t i = 1; 1 i<= i< 128; 128 i = i*2) { PORTB = i; _delay_loop_2(30000); } for (int i = 128; i> 1; i -= i/2) { PORTB = i; _delay_loop_2(30000); } } } 2102444 Introduction to Embedded Systems 39 40
1. Code Atmel Studio 6.1 Tool Chain Arduino Setup Video 2. Atmel studio PORT Code void setup() { DDRB = B00011111; } void loop() { PORTB = 1; } 3. Datasheet Atmel PORT ON/OFF O O LED P ORT O