Movatterモバイル変換


[0]ホーム

URL:


Uploaded byrtnmsn
PPTX, PDF29 views

Introduction To Arduino-converted for s.pptx

The document provides a comprehensive introduction to the Arduino microcontroller and its application in complex systems, detailing components such as the Atmega328P microcontroller and various Arduino models. It outlines the Arduino IDE, programming structure, and includes hands-on activities for users to implement basic tasks such as controlling LEDs, servos, and analog inputs. The document also explains advanced concepts like serial communication, PWM, and interfacing with other devices using I2C and SPI protocols.

Embed presentation

Download to read offline
INTRODUCTION TO THE ARDUINOMICROCONTROLLERHands-on Research in Complex SystemsShanghai Jiao Tong UniversityJune 17 – 29, 2012Instructor: Thomas E. Murphy (University of Maryland)Assisted by: Hien Dao (UMD), Caitlin Williams (UMD) and徐浩 (SJTU)
What is a Microcontroller(µC, MCU)• Computer on a single integrated chip– Processor (CPU)– Memory (RAM / ROM / Flash)– I/O ports (USB, I2C, SPI,ADC)• Common microcontroller families:– Intel: 4004, 8008, etc.– Atmel: AT andAVR– Microchip: PIC– ARM: (multiple manufacturers)• Used in:– Cellphones,– Toys– Household appliances– Cars– Cameras
The ATmega328P Microcontroller(used by the Arduino)• AVR 8-bit RISC architecture• Available in DIP package• Up to 20 MHz clock• 32kB flash memory• 1 kB SRAM• 23 programmable I/Ochannels• Six 10-bit ADC inputs• Three timers/counters• Six PWM outputs
What is Arduino Not?• It is not a chip (IC)• It is not a board (PCB)• It is not a company or a manufacturer• It is not a programming language• It is not a computer architecture(although it involves all of these things...)
So what is Arduino?It’s a movement, not a microcontroller:• Founded by Massimo Banzi and DavidCuartielles in 2005• Based on “Wiring Platform”, which dates to2003• Open-source hardware platform• Open source development environment– Easy-to learn language and libraries (basedon Wiring language)– Integrated development environment (basedon Processing programming environment)– Available for Windows / Mac / Linux
The Many Flavors of Arduino• Arduino Uno• Arduino Leonardo• Arduino LilyPad• Arduino Mega• Arduino Nano• Arduino Mini• Arduino Mini Pro• Arduino BT
Arduino-like Systems• Cortino (ARM)• Xduino (ARM)• LeafLabs Maple(ARM)• BeagleBoard (Linux)• Wiring Board(Arduinopredecessor)
Arduino Add-ons (Shields)• TFT Touch Screen• Data logger• Motor/Servo shield• Ethernet shield• Audio wave shield• Cellular/GSM shield• WiFi shield• Proto-shield• ...many more
Where to Get an Arduino Board• Purchase from online vendor (availableworldwide)– Sparkfun– Adafruit– DFRobot• ... or build your own– PC board– Solderless breadboardhttp://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard
Getting to know the Arduino:Electrical Inputs and Outputs14 digital inputs/outputs(6 PWM outputs)6 analoginputsDC voltagesupply(IN/OUT)USB connectionAC/DC adapterjack• Input voltage: 7-12 V(USB, DC plug, or Vin)• Max output current per pin: 40 mAATmega328P16 MHz clockVoltage regulatorLEDResetButtonPowerindicator
Download and Install• Download Arduino compiler and development environment from:http://arduino.cc/en/Main/Software• Current version: 1.0.1• Available for:– Windows– MacOX– Linux• No installer needed... just unzip to a convenient location• Before running Arduino, plug in your board using USB cable(external power is not necessary)• When USB device is not recognized, navigate to and select theappopriate driver from the installation directory• Run Arduino
Select your Board
Select Serial Port
Elements of the Arduino IDE• Text editor– syntax and keywordcoloring– automaticindentation– programmingshortcuts• Compiler• Hardware Interface– Uploading programs– Communicating withArduino via USB
Using the Arduino IDEName of sketchCompile sketchUpload to boardNewOpenSaveSerial MonitorProgram areaMessages /Errors
Arduino ReferenceArduino Reference is installed locallyor available online at http://arduino.cc/
Arduino Sketch Structure• void setup()– Will be executedonly when theprogram begins(or reset buttonis pressed)• void loop()– Will be executedrepeatedlyvoid setup() {// put your setup code here, to run once:}void loop() {// put your main code here, to run repeatedly:}Text that follows // is a comment(ignored by compiler)Useful IDE Shortcut: Press Ctrl‐/to comment (or uncomment) aselected portion of your program.
• Load the “Blink” example(FileExamplesBasicsBlink)Activity 1: LED Blinkvoid setup() {// i n i t i a li ze the digital pin as an output.// Pin 13 has an LED connected on most Arduino boards:pinMode(13, OUTPUT);}// set the LED on// wait for a second// set the LED off// wait for a secondvoid loop() {digitalWrite(13, HIGH);delay(1000);digitalWrite(13, LOW);delay(1000);}• Compile, then upload the program• Congratulations! you are now blinkers!Use pin 13 as digital outputSet output high (+5V)Wait 1000 millisecondsSet output low (0V)
Now connect your own LEDAnatomy of an LED:http://www.wikipedia.org/Notes:• Resistor is needed to limit current• Resistor and LED may beinterchanged(but polarity of LED is important)• Pin 13 is special: has built-inresistor and LED• Change program and upload
Aside: Using a SolderlessBreadboardConnected togetherConnected together300 mils
Example: Using a SolderlessBreadboard
• Change the blink rate– how fast can the LED blink (before you canno longer perceive the blinking?)• How would you make the LED dimmer?– (...without changing the resistor?)Experimenting
Digital Input: Reading Switchesand Buttons// Use pin 11 for digital out// Use pin 12 for digital input// Enable pull‐up resistorvoid setup() {pinMode(11, OUTPUT);pinMode(12, INPUT);digitalWrite(12, HIGH);}// read state of pin 12// set state of pin 11 (LED)// wait for a 1/10 secondvoid loop() {boolean state;state = digitalRead(12);digitalWrite(11, state);delay(100);}Writing HIGH to an input pin:enables an internal pull-up resistor• Turn on/off LED based on switch• Pin 12 reads LOWwhen switch is closed• Pin 12 reads HIGH when switch is open (pull-up)Without the internal pull-up resistor,unconnected digital inputs couldread either high or low
Activity 2: Seven-SegmentDisplay• Write a that program that counts from 0 to9 and displays the result on a seven-segment LED display• Consider writing a function:void writeDigit(int n)that writes a single digit
Seven-Segment Display TableDigit ABCDEFGA B C D E F G0 0×7E on on on on on on off1 0×30 off on on off off off off2 0×6D on on off on on off on3 0×79 on on on on off off on4 0×33 off on on off off on on5 0×5B on off on on off on on6 0×5F on off on on on on on7 0×70 on on on off off off off8 0×7F on on on on on on on9 0×7B on on on on off on onUseful:• bitRead(x,n)Get the value of the nth bit of an integer xExample:– bitRead(0x7E,7); // returns 1 (see table above)
Serial Communication - Writing• Serial.begin(baud)Initialize serial port for communication (and sets baudrate)Example:– Serial.begin(9600); // 9600 baud• Serial.print(val), Serial.print(val,fmt)Prints data to the serial portExamples:– Serial.print(“Hi”); // print a string– Serial.print(78); // works with numbers, too– Serial.print(variable); // works with variables– Serial.print(78,BIN); // will print 1001110• Serial.println(val)Same as Serial.print(), but withline-feedNote: Serial.end() commandis usually unnecessary, unlessyou need to use pins 0 & 1IMPORTANT:USB serialcommunication isshared withArduino pins 0and 1 (RX/TX)Format can be:BIN, HEX, OCT,or an integerspecifying thenumber of digitsto display
Activity 3: Hello World!• Write an Arduinoprogram that prints themessage “Hello world”to the serial port• ...whenever you pressa switch/button• Use the Serial Monitorto see the output(Ctrl-Shift-M)• Try increasing baudrateSerial Monitor:Make sure this agrees with yourprogram, i.e., Serial.begin(9600);
Serial Communication - Reading• Serial.available()Returns the number of bytes available to be read, if anyExample:i f (Serial.available() > 0) {data = Serial.read();}To read data from serial port:••••letter = Serial.read()letters = Serial.readBytesUntil(character, buffer, length)number = Serial.parseInt()number = Serial.parseFloat( )
Activity 4 – User ControlledBlinker• When available (Serial.available), read an integerfrom the serial port (Serial.parseInt), and use theresult to change the blink rate of the LED (pin 13)Useful:• constrain(x,a,b)Constrains the variable x to be from a to bExamples:– constrain(5,1,10); // returns 5– constrain(50,1,10); // returns 10– constrain(0,1,10); // returns 1
Analog Input and Sensors• Six analog inputs:A0, A1, A2, A3, A4, A5• AREF = Reference voltage(default = +5 V)• 10 bit resolution:– returns an integer from 0 to1023– result is proportional to thepin voltage• All voltages are measuredrelative to GNDAnalog InputsReference Voltage (optional)Note: If you need additionaldigital I/O, the analog pins can bere-assigned for digital use:pinMode(A0, OUTPUT);
Reading Analog Values• value = analogRead(pin)Reads the analog measurement on pinReturns integer between 0 and 1023• analogReference(type)type can be:– DEFAULT - the default analog reference of 5 volts (on5V Arduino boards)– INTERNAL – Built-in reference voltage (1.1 V)– EXTERNAL – AREF input pinNote: Do NOT use pinMode(A0, INPUT) unless you want touse A0 for DIGITAL input.
Aside: Potentiometers(variable resistors, rheostats)
Activity 5 – Volume Knob• Connect the potentiometer from 5V to GND• Use analogRead(A0) to measure the voltage on the center pin• Set the LED blink rate depending on the reading
Activity 6 – ArduinoThermometer• Build a circuit and write a sketch toread and report the temperature at1 second intervals
Data Logging Ideas• m i l l i s ( )Returns the number of milliseconds elapsed sinceprogram started (or reset)Time functions• setTime(hr,min,sec,day,month,yr)• hour(), minute(), day(), month(), year()Real-time Clock (RTC):• Use an external, battery-powered chip (e.g., DS1307) toprovide clockNote: this uses the Time library:#include <Time.h>
Activity 7 – Arduino Nightlight• CdS Photoresistor:resistance depends on ambientlight level• Build a circuit and write a sketch that turnson an LED whenever it gets darkHint: connect the photoresistor in a voltagedivider
Analog Output?• Most microcontrollers haveonly digital outputs• Pulse-width Modulation:Analog variables can berepresented by the duty-cycle (or pulse-width) of adigital signalhttp://arduino.cc/en/Tutorial/PWM
PulseWidth Modulation (PWM)• analogWrite(pin,val)set the PWM fraction:– val = 0: always off– val = 255: always on• Remember to designate pinfor digital output:pinMode(pin,OUTPUT);(usually in setup)• Default PWM frequency:– 16 MHz / 215 = 488.28125 HzPWM available on pins 3, 5, 6, 9, 10, 11Note: the PWM frequency andresolution can be changed byre-configuring the timers
Activity 8 – PWM LED Dimmer• Use PWM to control the brightness of an LED– connect LED to pin 3, 5, 6, 9, 10 or 11– remember to use 220 Ω current-limiting resistor• Set the brightness from the serial port, orpotentiometer• Watch the output on an oscilloscopeUseful:• newValue = map(oldValue, a, b, c, d)Converts/maps a number in the range (a:b) to a new number inthe range (c:d)Example:– newValue = map(oldValue,0,1023,0,255);
• Change your program to sinusoidallymodulate the intensity of the LED, at a 1Hz rate– Hint: use the millis(), s i n ( ) , andanalogWrite() functionsActivity 8 – PWM LED Dimmer(cont’d)
Servomotors• Standard servo:– PWM duty cycle controls direction:– 0% duty cycle  0 degrees– 100% duty cycle  180 degrees• Continuous-rotation servo:– duty cycle sets speed and/or directionhttp://www.parallax.com/
Activity 9 – Servomotor Control• Build a program that turns a servomotorfrom 0 to 180 degrees, based onpotentiometer reading• Report setting to the serial monitor
Solid State Switching - MOSFETsGDSD• Logic-level MOSFET(requires only 5 V)• Acts like a voltage-controlled switch• Works with PWM!
Activity 10 – PWM Speed Control• Build a circuit to control the speed of amotor using a PWM-controlled MOSFET• Enter the speed (PWM setting) from theserial port (Serial.parseInt)
Controlling Relays andSolenoids• Electromechanically-actuated switch• Provides electricalisolation• Typically few msresponse timeNote: Arduino cannot supplyenough current to drive relay coil
Relay Driver Circuit• NPN transistor: acts like a current-controlled switch• MOSFET will also work• Diode prevents back-EMF (associated with inductiveloads)• Coil voltage supply and Arduino share common GND
Activity 11: Bidirectional MotorDriver• Build a circuit (and write an Arduinosketch) that will use a DPDT relay tochange the direction of a DC motor:Note: this is called an H-bridge circuit.It can also be made with transistors
Communication: I2C, SPI• I2C (Inter-Integrated Circuit)– Developed by Phillips– Speed = 100 kHz, 400 kHz, and 3.4 MHz (notsupported by Arduino)– Two bi-directional lines: SDA, SCL– Multiple slaves can share same bus• SPI (Serial Peripheral Interface Bus)– Speed = 1-100 MHz (clock/device limited)– Four-wire bus: SCLK, MOSI, MISO, SS– Multiple slaves can share same bus(but each needs a dedicated SS, slave select)
Connecting Multiple Devices(I2C and SPI)http://en.wikipedia.org/Master with three SPI slaves:Master (µC) with three I2C slaves:
SPI and I2C on the ArduinoSPI pins:• SCK = serial clock• MISO = master in, slave out• MOSI = master out slave in• SS = slave selectI2C pins:• SDA = data line• SCL = clock lineSS (10)MOSI (11)MISO (12)SCK (13)SDA (A4) SCL (A5)
Basic Arduino I2C CommandsCOMMAND EXPLANATIONWire.begin() Join the I2C bus as master (usuallyinvoked in setup)Wire.beginTransmission(address) Begin communicating to a slavedeviceWire.write(byte) Write one byte to I2C bus (afterrequest)Wire.endTransmission(address) End transmission to slave deviceNote: you must include the Wire library:#include <Wire.h>Note: pinMode() not neededfor I2C on pins A4 andA5
Example: MCP4725 12-bit DACMCP4725 write command (taken from data sheet)7-bit I2C address(1100000)command power down mode(010) (00)data bits (MSB  LSB)Wire.beginTransmission(B1100000);Wire.write(B01000000);Wire.write(data >> 4);// Byte 1 (Initiate communication)// Byte 2 (command and power down mode)// Byte 3 (send bits D11..D4)Arduino program segment:Note: binary numbers are preceded by B:B1100000 = 96Wire.write((data &B00001111) << 4); // Byte 4 (send bits D3..D0)Wire.endTransmission();Remember: you must include the Wire library at the top:#include <Wire.h>and you must also use Wire.begin() insetupdata >> 4: shift bits left by four positions
Additional I2C CommandsCOMMAND EXPLANATIONWire.begin() Join the I2C bus as master (usually invokedin setup)Wire.begin(address) Join the I2C bus as slave, with addressspecified (usually invoked in setup)Wire.beginTransmission(address) Begin communicating to a slave deviceWire.write(byte) Write one byte to I2C bus (after request)Wire.write(bytes,length) Write length bytes to I2C busWire.endTransmission(address) End transmission to slave deviceWire.requestFrom(address, quantity)Wire.requestFrom(address, quantity, stop)Request bytes (quantity) from slaveWire.available() The number of bytes available for readingWire.read() Reads a byte that was transmitted from aslave. (Preceded by Wire.requestFrom)Note: you must include the Wire library:#include <Wire.h>Note: pinMode() not neededfor I2C on pins A4 andA5
Activity 12: Sawtooth Wave• Program the MCP4725 DAC to produce asawtooth (ramp) wave:– What is the frequency of the sawtooth wave?– Can you make f = 100 Hz?Note: the I2C bus requires pull-up resistors on SCL and SDA(provided on the board)MCP4725breakoutboard:http://www.sparkfun.com/
Basic Arduino SPI CommandsCOMMAND EXPLANATIONSPI.begin() Initializes the SPI bus, setting SCK,MOSI, and SS to outputs, pullingSCK and MOSI low and SS high.byteIn = SPI.transfer(byteOut) Transfer one byte (both send andreceive) returns the received byteNote: you must include the SPI library:#include <SPI.h>Note: pinMode() not needed. It isautomatically configured in SPI.begin()
Additional Arduino SPICommandsCOMMAND EXPLANATIONSPI.begin() Initializes the SPI bus, setting SCK, MOSI, and SS tooutputs, pulling SCK and MOSI low and SS high.SPI.end() Disables the SPI bus (leaving pin modes unchanged) – incase you need to use pins 10-13 againSPI.setBitOrder(order) Set bit order for SPIorder = {LSBFIRST, MSBFIRST}SPI.setClockDivider(divider) Set the SPI clock dividerdivider = {2, 4, 8, 16, 32, 64, 128}SPI clock speed = 16 MHz/dividerSPI.setDataMode(mode) Set the SPI data modemode = {SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3}SPI.transfer(byte) Transfer one byte (both send and receive)returns the received byteNote: you must include the SPI library:#include <SPI.h>Note: pinMode() not needed
Example: AD5206 DigitalPotentiometerFeatures:• six independent, 3-wiper potentiometers• 8-bit precision(256 possible levels)• Available in 10kΩ,50kΩ and 100kΩ• Programmedthrough SPI interfaceFunctional block diagram:
AD5206 Write SequenceSPI.begin(); // in it ia lize SPI ( in setup). . .digitalWrite(SS,LOW); // hold SS pin low to select chipSPI.transfer(potnumber); // determine which pot (0..5)SPI.transfer(wipervalue); // transfer 8‐bit wiper settingdigitalWrite(SS,HIGH); // de‐select the chipArduino program segment:Note: same as SS(slave select)Note: same as MOSI(master out slave in)
Activity 13: ProgrammableVoltage Divider• Use the AD5206 to build a programmablevoltage divider• Allow the user to set the resistance fromthe serial port• Measure resistance with an Ohm meter,or using analogRead()
AD5206: Summary of Pins andCommandsSCK (13) MISO (12) MOSI (11) SS (10)digitalWrite(SS,LOW); // hold SS pin low to select chipSPI.transfer(potnumber); // determine which pot (0..5)SPI.transfer(wipervalue); // transfer 8‐bit wiper settingdigitalWrite(SS,HIGH); // de‐select the chipRemember: SPI.begin() needed in setup() and #include <SPI.h>

Recommended

PPTX
Arduino slides
PDF
introductiontoarduino-111120102058-phpapp02.pdf
PPTX
Introduction to Arduino Microcontroller
PPT
01 Intro to the Arduino and it's basics.ppt
PPTX
Arduino Workshop Slides
PDF
Starting with Arduino
PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
PPTX
Arduino . .
PPTX
PPTX
Arduino Slides With Neopixels
PPT
Arduino is an open-source electronics platform that has an easy-to-use physic...
PPTX
Introduction to the Arduino
PPT
Fundamentals of programming Arduino-Wk2.ppt
PDF
02 Sensors and Actuators Understand .pdf
PDF
Ardx experimenters-guide-web
PPTX
Introduction to Arduino Webinar
PDF
Arduino spooky projects_class1
PDF
Arduino experimenters guide ARDX
PPT
Intro to Arduino
PDF
arduino
 
PDF
Arduino programming part1
PPTX
Intro to Arduino.ppt
PDF
Making things sense - Day 1 (May 2011)
PPTX
arduinoedit.pptx
PPT
Arduino wk2
PPTX
Basic arduino components and more things about arduino
PPTX
Micro_Controllers_lab1_Intro_to_Arduino.pptx
 
PPTX
coverpage for acr on professional code of ethics.pptx
PDF
4S-SKYlight 1 Steel pdf for aluminuim sheet .pdf

More Related Content

PPTX
Arduino slides
PDF
introductiontoarduino-111120102058-phpapp02.pdf
PPTX
Introduction to Arduino Microcontroller
PPT
01 Intro to the Arduino and it's basics.ppt
PPTX
Arduino Workshop Slides
PDF
Starting with Arduino
PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino slides
introductiontoarduino-111120102058-phpapp02.pdf
Introduction to Arduino Microcontroller
01 Intro to the Arduino and it's basics.ppt
Arduino Workshop Slides
Starting with Arduino
Arduino_CSE ece ppt for working and principal of arduino.ppt

Similar to Introduction To Arduino-converted for s.pptx

PPTX
Arduino . .
PPTX
PPTX
Arduino Slides With Neopixels
PPT
Arduino is an open-source electronics platform that has an easy-to-use physic...
PPTX
Introduction to the Arduino
PPT
Fundamentals of programming Arduino-Wk2.ppt
PDF
02 Sensors and Actuators Understand .pdf
PDF
Ardx experimenters-guide-web
PPTX
Introduction to Arduino Webinar
PDF
Arduino spooky projects_class1
PDF
Arduino experimenters guide ARDX
PPT
Intro to Arduino
PDF
arduino
 
PDF
Arduino programming part1
PPTX
Intro to Arduino.ppt
PDF
Making things sense - Day 1 (May 2011)
PPTX
arduinoedit.pptx
PPT
Arduino wk2
PPTX
Basic arduino components and more things about arduino
PPTX
Micro_Controllers_lab1_Intro_to_Arduino.pptx
 
Arduino . .
Arduino Slides With Neopixels
Arduino is an open-source electronics platform that has an easy-to-use physic...
Introduction to the Arduino
Fundamentals of programming Arduino-Wk2.ppt
02 Sensors and Actuators Understand .pdf
Ardx experimenters-guide-web
Introduction to Arduino Webinar
Arduino spooky projects_class1
Arduino experimenters guide ARDX
Intro to Arduino
arduino
 
Arduino programming part1
Intro to Arduino.ppt
Making things sense - Day 1 (May 2011)
arduinoedit.pptx
Arduino wk2
Basic arduino components and more things about arduino
Micro_Controllers_lab1_Intro_to_Arduino.pptx
 

Recently uploaded

PPTX
coverpage for acr on professional code of ethics.pptx
PDF
4S-SKYlight 1 Steel pdf for aluminuim sheet .pdf
PDF
SYS Office Portfolio - Trust the SYStem!
PPSX
Gas Turbine simulation in thermoflow software PRO Overview.ppsx
PPTX
aaabbbcccdddeeeefffggghhcute kitties.pptx
PPTX
Lectwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwure 8.pptx
PDF
mahad home wifi 6 setup presentation system.pdf
PDF
Advanced Computational Intelligence: An International Journal (ACII)
PDF
Designing_the_AI_Cosmos_with_Indian_Values.pdf
PDF
Chapter _4_Shaft Design_Key_Bearing_M_E_Design.pdf
PDF
Art and Visual Perception: A PSYCHOLOGY OF THE CREATIVE EYE
PPTX
Chapter4_Initiation_of_Sediment_Motion_v2[1].pptx
PPTX
Dropshare 6.8.0 Crack for macOS Download
PPTX
Become a Professional UI/UX Designer by Learning How to Create Beautiful, Use...
PDF
Cultural dimensions and global web user interface design
PPT
THEORY OF ARCHITECTURE - LECTURE NOTES FOR REFERENCE
PDF
induction and two in one event with party
PDF
Farm-structures-housing-cow-calves-youngstock_compressed.pdf
PDF
Morgenbooster_Drakonheart_Designing_for_creative_kids.pdf
PPTX
Chapt_4[1].ppt very interseting and important
coverpage for acr on professional code of ethics.pptx
4S-SKYlight 1 Steel pdf for aluminuim sheet .pdf
SYS Office Portfolio - Trust the SYStem!
Gas Turbine simulation in thermoflow software PRO Overview.ppsx
aaabbbcccdddeeeefffggghhcute kitties.pptx
Lectwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwure 8.pptx
mahad home wifi 6 setup presentation system.pdf
Advanced Computational Intelligence: An International Journal (ACII)
Designing_the_AI_Cosmos_with_Indian_Values.pdf
Chapter _4_Shaft Design_Key_Bearing_M_E_Design.pdf
Art and Visual Perception: A PSYCHOLOGY OF THE CREATIVE EYE
Chapter4_Initiation_of_Sediment_Motion_v2[1].pptx
Dropshare 6.8.0 Crack for macOS Download
Become a Professional UI/UX Designer by Learning How to Create Beautiful, Use...
Cultural dimensions and global web user interface design
THEORY OF ARCHITECTURE - LECTURE NOTES FOR REFERENCE
induction and two in one event with party
Farm-structures-housing-cow-calves-youngstock_compressed.pdf
Morgenbooster_Drakonheart_Designing_for_creative_kids.pdf
Chapt_4[1].ppt very interseting and important

Introduction To Arduino-converted for s.pptx

  • 1.
    INTRODUCTION TO THEARDUINOMICROCONTROLLERHands-on Research in Complex SystemsShanghai Jiao Tong UniversityJune 17 – 29, 2012Instructor: Thomas E. Murphy (University of Maryland)Assisted by: Hien Dao (UMD), Caitlin Williams (UMD) and徐浩 (SJTU)
  • 2.
    What is aMicrocontroller(µC, MCU)• Computer on a single integrated chip– Processor (CPU)– Memory (RAM / ROM / Flash)– I/O ports (USB, I2C, SPI,ADC)• Common microcontroller families:– Intel: 4004, 8008, etc.– Atmel: AT andAVR– Microchip: PIC– ARM: (multiple manufacturers)• Used in:– Cellphones,– Toys– Household appliances– Cars– Cameras
  • 3.
    The ATmega328P Microcontroller(usedby the Arduino)• AVR 8-bit RISC architecture• Available in DIP package• Up to 20 MHz clock• 32kB flash memory• 1 kB SRAM• 23 programmable I/Ochannels• Six 10-bit ADC inputs• Three timers/counters• Six PWM outputs
  • 4.
    What is ArduinoNot?• It is not a chip (IC)• It is not a board (PCB)• It is not a company or a manufacturer• It is not a programming language• It is not a computer architecture(although it involves all of these things...)
  • 5.
    So what isArduino?It’s a movement, not a microcontroller:• Founded by Massimo Banzi and DavidCuartielles in 2005• Based on “Wiring Platform”, which dates to2003• Open-source hardware platform• Open source development environment– Easy-to learn language and libraries (basedon Wiring language)– Integrated development environment (basedon Processing programming environment)– Available for Windows / Mac / Linux
  • 6.
    The Many Flavorsof Arduino• Arduino Uno• Arduino Leonardo• Arduino LilyPad• Arduino Mega• Arduino Nano• Arduino Mini• Arduino Mini Pro• Arduino BT
  • 7.
    Arduino-like Systems• Cortino(ARM)• Xduino (ARM)• LeafLabs Maple(ARM)• BeagleBoard (Linux)• Wiring Board(Arduinopredecessor)
  • 8.
    Arduino Add-ons (Shields)•TFT Touch Screen• Data logger• Motor/Servo shield• Ethernet shield• Audio wave shield• Cellular/GSM shield• WiFi shield• Proto-shield• ...many more
  • 9.
    Where to Getan Arduino Board• Purchase from online vendor (availableworldwide)– Sparkfun– Adafruit– DFRobot• ... or build your own– PC board– Solderless breadboardhttp://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard
  • 10.
    Getting to knowthe Arduino:Electrical Inputs and Outputs14 digital inputs/outputs(6 PWM outputs)6 analoginputsDC voltagesupply(IN/OUT)USB connectionAC/DC adapterjack• Input voltage: 7-12 V(USB, DC plug, or Vin)• Max output current per pin: 40 mAATmega328P16 MHz clockVoltage regulatorLEDResetButtonPowerindicator
  • 11.
    Download and Install•Download Arduino compiler and development environment from:http://arduino.cc/en/Main/Software• Current version: 1.0.1• Available for:– Windows– MacOX– Linux• No installer needed... just unzip to a convenient location• Before running Arduino, plug in your board using USB cable(external power is not necessary)• When USB device is not recognized, navigate to and select theappopriate driver from the installation directory• Run Arduino
  • 12.
  • 13.
  • 14.
    Elements of theArduino IDE• Text editor– syntax and keywordcoloring– automaticindentation– programmingshortcuts• Compiler• Hardware Interface– Uploading programs– Communicating withArduino via USB
  • 15.
    Using the ArduinoIDEName of sketchCompile sketchUpload to boardNewOpenSaveSerial MonitorProgram areaMessages /Errors
  • 16.
    Arduino ReferenceArduino Referenceis installed locallyor available online at http://arduino.cc/
  • 17.
    Arduino Sketch Structure•void setup()– Will be executedonly when theprogram begins(or reset buttonis pressed)• void loop()– Will be executedrepeatedlyvoid setup() {// put your setup code here, to run once:}void loop() {// put your main code here, to run repeatedly:}Text that follows // is a comment(ignored by compiler)Useful IDE Shortcut: Press Ctrl‐/to comment (or uncomment) aselected portion of your program.
  • 18.
    • Load the“Blink” example(FileExamplesBasicsBlink)Activity 1: LED Blinkvoid setup() {// i n i t i a li ze the digital pin as an output.// Pin 13 has an LED connected on most Arduino boards:pinMode(13, OUTPUT);}// set the LED on// wait for a second// set the LED off// wait for a secondvoid loop() {digitalWrite(13, HIGH);delay(1000);digitalWrite(13, LOW);delay(1000);}• Compile, then upload the program• Congratulations! you are now blinkers!Use pin 13 as digital outputSet output high (+5V)Wait 1000 millisecondsSet output low (0V)
  • 19.
    Now connect yourown LEDAnatomy of an LED:http://www.wikipedia.org/Notes:• Resistor is needed to limit current• Resistor and LED may beinterchanged(but polarity of LED is important)• Pin 13 is special: has built-inresistor and LED• Change program and upload
  • 20.
    Aside: Using aSolderlessBreadboardConnected togetherConnected together300 mils
  • 21.
    Example: Using aSolderlessBreadboard
  • 22.
    • Change theblink rate– how fast can the LED blink (before you canno longer perceive the blinking?)• How would you make the LED dimmer?– (...without changing the resistor?)Experimenting
  • 23.
    Digital Input: ReadingSwitchesand Buttons// Use pin 11 for digital out// Use pin 12 for digital input// Enable pull‐up resistorvoid setup() {pinMode(11, OUTPUT);pinMode(12, INPUT);digitalWrite(12, HIGH);}// read state of pin 12// set state of pin 11 (LED)// wait for a 1/10 secondvoid loop() {boolean state;state = digitalRead(12);digitalWrite(11, state);delay(100);}Writing HIGH to an input pin:enables an internal pull-up resistor• Turn on/off LED based on switch• Pin 12 reads LOWwhen switch is closed• Pin 12 reads HIGH when switch is open (pull-up)Without the internal pull-up resistor,unconnected digital inputs couldread either high or low
  • 24.
    Activity 2: Seven-SegmentDisplay•Write a that program that counts from 0 to9 and displays the result on a seven-segment LED display• Consider writing a function:void writeDigit(int n)that writes a single digit
  • 25.
    Seven-Segment Display TableDigitABCDEFGA B C D E F G0 0×7E on on on on on on off1 0×30 off on on off off off off2 0×6D on on off on on off on3 0×79 on on on on off off on4 0×33 off on on off off on on5 0×5B on off on on off on on6 0×5F on off on on on on on7 0×70 on on on off off off off8 0×7F on on on on on on on9 0×7B on on on on off on onUseful:• bitRead(x,n)Get the value of the nth bit of an integer xExample:– bitRead(0x7E,7); // returns 1 (see table above)
  • 26.
    Serial Communication -Writing• Serial.begin(baud)Initialize serial port for communication (and sets baudrate)Example:– Serial.begin(9600); // 9600 baud• Serial.print(val), Serial.print(val,fmt)Prints data to the serial portExamples:– Serial.print(“Hi”); // print a string– Serial.print(78); // works with numbers, too– Serial.print(variable); // works with variables– Serial.print(78,BIN); // will print 1001110• Serial.println(val)Same as Serial.print(), but withline-feedNote: Serial.end() commandis usually unnecessary, unlessyou need to use pins 0 & 1IMPORTANT:USB serialcommunication isshared withArduino pins 0and 1 (RX/TX)Format can be:BIN, HEX, OCT,or an integerspecifying thenumber of digitsto display
  • 27.
    Activity 3: HelloWorld!• Write an Arduinoprogram that prints themessage “Hello world”to the serial port• ...whenever you pressa switch/button• Use the Serial Monitorto see the output(Ctrl-Shift-M)• Try increasing baudrateSerial Monitor:Make sure this agrees with yourprogram, i.e., Serial.begin(9600);
  • 28.
    Serial Communication -Reading• Serial.available()Returns the number of bytes available to be read, if anyExample:i f (Serial.available() > 0) {data = Serial.read();}To read data from serial port:••••letter = Serial.read()letters = Serial.readBytesUntil(character, buffer, length)number = Serial.parseInt()number = Serial.parseFloat( )
  • 29.
    Activity 4 –User ControlledBlinker• When available (Serial.available), read an integerfrom the serial port (Serial.parseInt), and use theresult to change the blink rate of the LED (pin 13)Useful:• constrain(x,a,b)Constrains the variable x to be from a to bExamples:– constrain(5,1,10); // returns 5– constrain(50,1,10); // returns 10– constrain(0,1,10); // returns 1
  • 30.
    Analog Input andSensors• Six analog inputs:A0, A1, A2, A3, A4, A5• AREF = Reference voltage(default = +5 V)• 10 bit resolution:– returns an integer from 0 to1023– result is proportional to thepin voltage• All voltages are measuredrelative to GNDAnalog InputsReference Voltage (optional)Note: If you need additionaldigital I/O, the analog pins can bere-assigned for digital use:pinMode(A0, OUTPUT);
  • 31.
    Reading Analog Values•value = analogRead(pin)Reads the analog measurement on pinReturns integer between 0 and 1023• analogReference(type)type can be:– DEFAULT - the default analog reference of 5 volts (on5V Arduino boards)– INTERNAL – Built-in reference voltage (1.1 V)– EXTERNAL – AREF input pinNote: Do NOT use pinMode(A0, INPUT) unless you want touse A0 for DIGITAL input.
  • 32.
  • 33.
    Activity 5 –Volume Knob• Connect the potentiometer from 5V to GND• Use analogRead(A0) to measure the voltage on the center pin• Set the LED blink rate depending on the reading
  • 34.
    Activity 6 –ArduinoThermometer• Build a circuit and write a sketch toread and report the temperature at1 second intervals
  • 35.
    Data Logging Ideas•m i l l i s ( )Returns the number of milliseconds elapsed sinceprogram started (or reset)Time functions• setTime(hr,min,sec,day,month,yr)• hour(), minute(), day(), month(), year()Real-time Clock (RTC):• Use an external, battery-powered chip (e.g., DS1307) toprovide clockNote: this uses the Time library:#include <Time.h>
  • 36.
    Activity 7 –Arduino Nightlight• CdS Photoresistor:resistance depends on ambientlight level• Build a circuit and write a sketch that turnson an LED whenever it gets darkHint: connect the photoresistor in a voltagedivider
  • 37.
    Analog Output?• Mostmicrocontrollers haveonly digital outputs• Pulse-width Modulation:Analog variables can berepresented by the duty-cycle (or pulse-width) of adigital signalhttp://arduino.cc/en/Tutorial/PWM
  • 38.
    PulseWidth Modulation (PWM)•analogWrite(pin,val)set the PWM fraction:– val = 0: always off– val = 255: always on• Remember to designate pinfor digital output:pinMode(pin,OUTPUT);(usually in setup)• Default PWM frequency:– 16 MHz / 215 = 488.28125 HzPWM available on pins 3, 5, 6, 9, 10, 11Note: the PWM frequency andresolution can be changed byre-configuring the timers
  • 39.
    Activity 8 –PWM LED Dimmer• Use PWM to control the brightness of an LED– connect LED to pin 3, 5, 6, 9, 10 or 11– remember to use 220 Ω current-limiting resistor• Set the brightness from the serial port, orpotentiometer• Watch the output on an oscilloscopeUseful:• newValue = map(oldValue, a, b, c, d)Converts/maps a number in the range (a:b) to a new number inthe range (c:d)Example:– newValue = map(oldValue,0,1023,0,255);
  • 40.
    • Change yourprogram to sinusoidallymodulate the intensity of the LED, at a 1Hz rate– Hint: use the millis(), s i n ( ) , andanalogWrite() functionsActivity 8 – PWM LED Dimmer(cont’d)
  • 41.
    Servomotors• Standard servo:–PWM duty cycle controls direction:– 0% duty cycle  0 degrees– 100% duty cycle  180 degrees• Continuous-rotation servo:– duty cycle sets speed and/or directionhttp://www.parallax.com/
  • 42.
    Activity 9 –Servomotor Control• Build a program that turns a servomotorfrom 0 to 180 degrees, based onpotentiometer reading• Report setting to the serial monitor
  • 43.
    Solid State Switching- MOSFETsGDSD• Logic-level MOSFET(requires only 5 V)• Acts like a voltage-controlled switch• Works with PWM!
  • 44.
    Activity 10 –PWM Speed Control• Build a circuit to control the speed of amotor using a PWM-controlled MOSFET• Enter the speed (PWM setting) from theserial port (Serial.parseInt)
  • 45.
    Controlling Relays andSolenoids•Electromechanically-actuated switch• Provides electricalisolation• Typically few msresponse timeNote: Arduino cannot supplyenough current to drive relay coil
  • 46.
    Relay Driver Circuit•NPN transistor: acts like a current-controlled switch• MOSFET will also work• Diode prevents back-EMF (associated with inductiveloads)• Coil voltage supply and Arduino share common GND
  • 47.
    Activity 11: BidirectionalMotorDriver• Build a circuit (and write an Arduinosketch) that will use a DPDT relay tochange the direction of a DC motor:Note: this is called an H-bridge circuit.It can also be made with transistors
  • 48.
    Communication: I2C, SPI•I2C (Inter-Integrated Circuit)– Developed by Phillips– Speed = 100 kHz, 400 kHz, and 3.4 MHz (notsupported by Arduino)– Two bi-directional lines: SDA, SCL– Multiple slaves can share same bus• SPI (Serial Peripheral Interface Bus)– Speed = 1-100 MHz (clock/device limited)– Four-wire bus: SCLK, MOSI, MISO, SS– Multiple slaves can share same bus(but each needs a dedicated SS, slave select)
  • 49.
    Connecting Multiple Devices(I2Cand SPI)http://en.wikipedia.org/Master with three SPI slaves:Master (µC) with three I2C slaves:
  • 50.
    SPI and I2Con the ArduinoSPI pins:• SCK = serial clock• MISO = master in, slave out• MOSI = master out slave in• SS = slave selectI2C pins:• SDA = data line• SCL = clock lineSS (10)MOSI (11)MISO (12)SCK (13)SDA (A4) SCL (A5)
  • 51.
    Basic Arduino I2CCommandsCOMMAND EXPLANATIONWire.begin() Join the I2C bus as master (usuallyinvoked in setup)Wire.beginTransmission(address) Begin communicating to a slavedeviceWire.write(byte) Write one byte to I2C bus (afterrequest)Wire.endTransmission(address) End transmission to slave deviceNote: you must include the Wire library:#include <Wire.h>Note: pinMode() not neededfor I2C on pins A4 andA5
  • 52.
    Example: MCP4725 12-bitDACMCP4725 write command (taken from data sheet)7-bit I2C address(1100000)command power down mode(010) (00)data bits (MSB  LSB)Wire.beginTransmission(B1100000);Wire.write(B01000000);Wire.write(data >> 4);// Byte 1 (Initiate communication)// Byte 2 (command and power down mode)// Byte 3 (send bits D11..D4)Arduino program segment:Note: binary numbers are preceded by B:B1100000 = 96Wire.write((data &B00001111) << 4); // Byte 4 (send bits D3..D0)Wire.endTransmission();Remember: you must include the Wire library at the top:#include <Wire.h>and you must also use Wire.begin() insetupdata >> 4: shift bits left by four positions
  • 53.
    Additional I2C CommandsCOMMANDEXPLANATIONWire.begin() Join the I2C bus as master (usually invokedin setup)Wire.begin(address) Join the I2C bus as slave, with addressspecified (usually invoked in setup)Wire.beginTransmission(address) Begin communicating to a slave deviceWire.write(byte) Write one byte to I2C bus (after request)Wire.write(bytes,length) Write length bytes to I2C busWire.endTransmission(address) End transmission to slave deviceWire.requestFrom(address, quantity)Wire.requestFrom(address, quantity, stop)Request bytes (quantity) from slaveWire.available() The number of bytes available for readingWire.read() Reads a byte that was transmitted from aslave. (Preceded by Wire.requestFrom)Note: you must include the Wire library:#include <Wire.h>Note: pinMode() not neededfor I2C on pins A4 andA5
  • 54.
    Activity 12: SawtoothWave• Program the MCP4725 DAC to produce asawtooth (ramp) wave:– What is the frequency of the sawtooth wave?– Can you make f = 100 Hz?Note: the I2C bus requires pull-up resistors on SCL and SDA(provided on the board)MCP4725breakoutboard:http://www.sparkfun.com/
  • 55.
    Basic Arduino SPICommandsCOMMAND EXPLANATIONSPI.begin() Initializes the SPI bus, setting SCK,MOSI, and SS to outputs, pullingSCK and MOSI low and SS high.byteIn = SPI.transfer(byteOut) Transfer one byte (both send andreceive) returns the received byteNote: you must include the SPI library:#include <SPI.h>Note: pinMode() not needed. It isautomatically configured in SPI.begin()
  • 56.
    Additional Arduino SPICommandsCOMMANDEXPLANATIONSPI.begin() Initializes the SPI bus, setting SCK, MOSI, and SS tooutputs, pulling SCK and MOSI low and SS high.SPI.end() Disables the SPI bus (leaving pin modes unchanged) – incase you need to use pins 10-13 againSPI.setBitOrder(order) Set bit order for SPIorder = {LSBFIRST, MSBFIRST}SPI.setClockDivider(divider) Set the SPI clock dividerdivider = {2, 4, 8, 16, 32, 64, 128}SPI clock speed = 16 MHz/dividerSPI.setDataMode(mode) Set the SPI data modemode = {SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3}SPI.transfer(byte) Transfer one byte (both send and receive)returns the received byteNote: you must include the SPI library:#include <SPI.h>Note: pinMode() not needed
  • 57.
    Example: AD5206 DigitalPotentiometerFeatures:•six independent, 3-wiper potentiometers• 8-bit precision(256 possible levels)• Available in 10kΩ,50kΩ and 100kΩ• Programmedthrough SPI interfaceFunctional block diagram:
  • 58.
    AD5206 Write SequenceSPI.begin();// in it ia lize SPI ( in setup). . .digitalWrite(SS,LOW); // hold SS pin low to select chipSPI.transfer(potnumber); // determine which pot (0..5)SPI.transfer(wipervalue); // transfer 8‐bit wiper settingdigitalWrite(SS,HIGH); // de‐select the chipArduino program segment:Note: same as SS(slave select)Note: same as MOSI(master out slave in)
  • 59.
    Activity 13: ProgrammableVoltageDivider• Use the AD5206 to build a programmablevoltage divider• Allow the user to set the resistance fromthe serial port• Measure resistance with an Ohm meter,or using analogRead()
  • 60.
    AD5206: Summary ofPins andCommandsSCK (13) MISO (12) MOSI (11) SS (10)digitalWrite(SS,LOW); // hold SS pin low to select chipSPI.transfer(potnumber); // determine which pot (0..5)SPI.transfer(wipervalue); // transfer 8‐bit wiper settingdigitalWrite(SS,HIGH); // de‐select the chipRemember: SPI.begin() needed in setup() and #include <SPI.h>

[8]ページ先頭

©2009-2025 Movatter.jp