Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino John Marcoux Christopher Lesch Thomas Dodge Unless otherwise noted, all information and pictures came from:

Similar presentations


Presentation on theme: "Arduino John Marcoux Christopher Lesch Thomas Dodge Unless otherwise noted, all information and pictures came from:"— Presentation transcript:

1 Arduino John Marcoux Christopher Lesch Thomas Dodge Unless otherwise noted, all information and pictures came from: http://www.arduino.cc/

2 Overview What is the Arduino? o Basics o Product Information Hardware Overview o Arduino Uno Programming Overview o Simple Example o Interrupts http://www.robotgear.com.au/Cache/Files/ProductImageOriginals/1122_Arduin o%20Uno%20-%20with%20quarter.jpg

3 What is the Arduino? Arduino is a customizable electronic prototyping platform (microcontroller) Intended for artists and designers, or anyone looking to use a microcontroller Very easy to use Many choices Arduino Mega 2560 Arduino Ethernet

4 Open-Sourced All of its software can be downloaded for free, as well as all of its hardware design files Website: Explains how to use all of its material, including many step by step tutorials Simple things like LEDs, switches Using Pulse Width Modulation (built in functions) Interfacing directly with...  potientometers  piezoresistors  accelerometers  ultrasonic range finders Easy to Implement (imported)

5 Basics Simple enough to be used by someone with little to no knowledge of programming or circuits Comprehensive enough to incorporate projects which interface with many different types of peripherals Runs cross platform (Windows, Linux, Mac) Can be powered via USB, or external power supply (AC to DC adapter or battery)

6 Example

7 Hardware

8 ATmega16U2 MU

9 ATmega328P MU

10

11

12

13

14

15

16

17 Arduino UnoSmartFusion Digital I/O Pins14 (6 PWM)130 Analog Input Pins624 Flash Memory32 KB256 KB SRAM2 KB64 KB (+ more) EEPROM1 KBNone Clock Speed16 MHz100 MHz Cost~$30.00$99 Image and information taken from: http://www.actel.com/documents/SmartFusion_DS.PDF

18 So Where is Everything?

19

20

21

22 16 MHz Crystal 16MHz Resonator

23 So Where is Everything?

24 Programming Basics Supports C language in free IDE Example commands: o digitalWrite(pin#, HIGH or LOW); o digitalRead(pin#); o Serial.println("stuff"); o TIMSK2 |= 1; //enable OVF interrupt for timer 2 Code structure: o setup{ //code that runs once } o void loop{ //main code }

25 Simple Example void setup() { Serial.begin(9600); pinMode(4, OUTPUT); pinMode(2, INPUT); } void loop() { int sensorValue = digitalRead(2); Serial.println(sensorValue, DEC); if(sensorValue) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } Code from Arduino.cc Video by TheEquationSlayer (me!) http://www.youtube.com/watch?v=1Hhr4xX6Ois &feature=colike

26 Interrupts Enabled and masked with sei() and cli() By default, no nested interrupts Hardware provides two "external" interrupts o Only on digital pins 2 and 3 o attachInterrupt( 0 or 1, handler name, trigger mode) Lower addresses have higher priority. Not all 26 interrupts shown here! Table 11-1 from official documentation. Available at Arduino.cc

27 Simple Example with Interrupt #include volatile int sensorValue = 0; void setup() { Serial.begin(9600); pinMode(4, OUTPUT); pinMode(2, INPUT); //INT0 sei(); //Enable all INTs //Set interrupt. 0 means pin2, 1 means pin3 attachInterrupt(0, INT0_handler, CHANGE); } void loop() { //Wait for voltage change on pin2 } void INT0_handler() { Serial.println("Interrupt INT0!"); sensorValue = digitalRead(2); if(sensorValue) digitalWrite(4, HIGH); else digitalWrite(4, LOW); } Code by Tdodge

28 Just the Tip of the Iceburg! Debouncing? What if we want more than two interrupts? How do we use timers? Download more slides and visit Arduino.cc! http://tinyurl.com/6qjllky (mediafire)

29 Questions?

30 Simple Debouncer void interruptHandler() { unsigned long this_INT = millis(); if(this_INT - last_INT > 300) { Serial.println("An INT!"); value = ~value; digitalWrite(13, value); } last_INT = this_INT; } millis returns milliseconds since program setup. Takes ~50 days to overflow! this_INT stores current time. last_INT can be a global that stores when the last interrupt happened. If last interrupt was more than 300ms ago, go ahead and perform interrupt. By Thomas, although I probably saw this on a forum at Arduino.cc

31 Pin Change Interrupts Can be mapped to any pin More complex: o Only 3 address vectors o Triggered on rising and falling edges o Handler must sort out pin/type Limited libraries o Best to modify registers yourself o Follow documentation Table from official documentation.

32 Pin Change Interrupt Example http://www.youtube.com/watch?v=XWGOVgqt0gw& feature=colike

33 Pin Change Interrupt Example #include int ledPin = 8; //pin for LED int pin4_PCINT2 = 4; int pin5_PCINT2 = 5; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); pinMode(pin4_PCINT2, INPUT); pinMode(pin5_PCINT2, INPUT); sei(); PCICR |= (1 << 2); //enable PCINT2 //declare pins 4&5 as PCINT2 //on any change they will fire PCINT2 PCMSK2 |= (1 << 4); PCMSK2 |= (1 << 5); } ISR(PCINT2_vect) { if(digitalRead(pin4_PCINT2)) digitalWrite(ledPin, HIGH); else if(digitalRead(pin5_PCINT2)) digitalWrite(ledPin, LOW); } void loop() { //Wait for voltage change delay(100); //100ms delay } Code by thd!

34 Timers 3 hardware timers with PWM support Clocked internally or externally Example: Timer 2 o 8-bit o Two compare registers with interrupts o non-PWM or fast PWM modes o Read count from TCNT2 o Write compare value to OCR2A or OCR2B o TIMSK2 devoted to enabling compare interrupts and overflow interrupts.

35 Timer Example http://www.youtube.com/watch?v=N_ug38DxTW0&f eature=colike

36 Timer Interrupt Example #include int ledPin = 8; volatile int compAval = 10; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); sei(); //Enable interrupts TCCR2A |= 3; //Fast PWM mode 3. TCCR2A |= (3 << 6); //fire INT on Compare match TCNT2 = 0; //initialize Timer2 to 0 OCR2A = compAval; //Set compare A value TIMSK2 |= (1 << 1); //Enable CompA interrupt TIMSK2 |= 1; //Enable OVF interrupt TCCR2B |= 7; //Clock select. Internal, prescale 1024~64us } ISR(TIMER2_COMPA_vect) { digitalWrite(ledPin, HIGH); } ISR(TIMER2_OVF_vect) { digitalWrite(ledPin, LOW); compAval = compAval + 4; if(compAval > 254) compAval = 10; OCR2A = compAval; } void loop() { //Serial.println(TCNT2, DEC); } Code by Tom D!


Download ppt "Arduino John Marcoux Christopher Lesch Thomas Dodge Unless otherwise noted, all information and pictures came from:"

Similar presentations


Ads by Google