1 Arduino 23

Embed Size (px)

Citation preview

  • 8/18/2019 1 Arduino 23

    1/42

    What is a Microcontroller

    • A small computer on a single chip• containing a processor, memory, and input/output

    •  Typically "embedded" inside some device that theycontrol

  • 8/18/2019 1 Arduino 23

    2/42

    What is a DevelopmentBoard

    • A printed circuitboard designed tofacilitate wor

    with a particularmicrocontroller!

    •  Typical components include

    • power circuit• programming interface• basic input# usually buttons and

    $%Ds

    • &/' pins

  • 8/18/2019 1 Arduino 23

    3/42

    Arduino Development Board

    Making-robots-with-arduino.pdf 

    Ana

    log

    INPUTS

    Digital I\OPWM(3, 5, 6, 9, 10, 11)

    PWR INUSB (to o!"#t$%)

    I&

    POW'R5 3*3 +ND

    R'S'T

  • 8/18/2019 1 Arduino 23

    4/42

    Di(erent Arduino Boards

    • )*'

    • $%'*A+D'

    • D)%

    •  )*•  T+%

    • -%+'

    • M&.+'• %0$'+A

    • 1 many more

  • 8/18/2019 1 Arduino 23

    5/42

    ample peci2cationArduino )no

    • Microcontroller: AT mega 328

    • perating !oltage "!

    • #nput !oltage $recommended% &-'2!

    • #nput !oltage $limits% (-2)!• *igital #+ ,ins ' $of which ( proide ,/M output%

    •  Analog #nput ,ins (

    • *0 0urrent per #+ ,in ) mA

    • *0 0urrent for 3.3! ,in ") mA

    • 1lash Memor 32 4 $of which )." 4 used b boot loader%

    • 56AM 2 4 $ATmega328%

    • 77,6M ' 4 $ATmega328%

    • 0lock 5peed '( M9

  • 8/18/2019 1 Arduino 23

    6/42

     The Arduino Microcontroller Atmel

  • 8/18/2019 1 Arduino 23

    7/42

    What is the Arduino

    todbot.com+blog+bionicarduino

  • 8/18/2019 1 Arduino 23

    8/42

    3etting tarted

    • .hec out http//arduino!cc/en/3uide/4ome0age

    1. Download & install the Arduino environment(IDE)

    2. Connect the board to your computer via the!" cable

    #. I$ needed% install the drivers (not needed in lab)

    . 'aunch the Arduino IDE

    . "elect your board

    . "elect your serial port

    *. +pen the blin, e-ample

    . pload the pro/ram

    http://arduino.cc/en/Guide/HomePagehttp://arduino.cc/en/Guide/HomePage

  • 8/18/2019 1 Arduino 23

    9/42

    .onnect the )B .able

  • 8/18/2019 1 Arduino 23

    10/42

    Arduino &D%

  • 8/18/2019 1 Arduino 23

    11/42

  • 8/18/2019 1 Arduino 23

    12/42

    .

    'M0&$%

    )0$'

    AD

    *%W

    '0%*

    A

    5%

  • 8/18/2019 1 Arduino 23

    13/42

    elect erial 0ort and Board

  • 8/18/2019 1 Arduino 23

    14/42

    tatus Messages

  • 8/18/2019 1 Arduino 23

    15/42

    todbot.com+blog+bionicarduino

    A $ittl Bit Ab t

  • 8/18/2019 1 Arduino 23

    16/42

    A $ittle Bit About0rogramming

    • .ode is casesensitive

    • tatements are

    commands andmust end with asemi6colon

    • .ommentsfollow a // orbegin with /7and end with 7/

    • loop and setup

    http://www.cebuelectronics.com/blog/basic-arduino-programming-notes/structurehttp://www.cebuelectronics.com/blog/basic-arduino-programming-notes/structure

  • 8/18/2019 1 Arduino 23

    17/42

     Terminology

  • 8/18/2019 1 Arduino 23

    18/42

    Digital &/8

    pinMode( pin, mode)ets pin to either INPUT or OUTPUT

    digitalRead( pin)+eads HIGH or LOW from a pin

    digitalWrite( pin, value)Writes HIGH or LOW to a pin

    %lectronic stu('utput pins can provide 98 mA of current

    Writing HIGH to an input pin installs a :8;  

    www.mikroe.com+chapters+iew+'

  • 8/18/2019 1 Arduino 23

    19/42

  • 8/18/2019 1 Arduino 23

    20/42

    5ariables

    Basic variable types

    Boolean

    &nteger

    .haracter

  • 8/18/2019 1 Arduino 23

    21/42

    Declaring 5ariables

    Boolean booleanvariableName;

    &nteger int variableName;

    .haracter charvariableName;

    trin strin Name [ ];

  • 8/18/2019 1 Arduino 23

    22/42

    Assigning 5ariables

     ;Boolean variableName =true;

     ;or variableName = false;

     ;&nteger variableName =

    32767; ;or variableName = -32768;

     ;.haracter variableName =

    ‘A;

    5 i bl

  • 8/18/2019 1 Arduino 23

    23/42

    5ariable copeWhere you declare your variablesmatters

  • 8/18/2019 1 Arduino 23

    24/42

    etup

    voi' setu# ( ) * +

     The setup function comes before

    the loop function and isnecessary

    for all Arduino setches

  • 8/18/2019 1 Arduino 23

    25/42

    #f 5tatementsif ( this is true ) { do this; }

     

  • 8/18/2019 1 Arduino 23

    26/42

    #f if  ( this is true ) { do this; }

     

  • 8/18/2019 1 Arduino 23

    27/42

    0onditionalif ( this is true ) { do this; }

     

  • 8/18/2019 1 Arduino 23

    28/42

     Actionif ( this is true ) { do this; }

     

  • 8/18/2019 1 Arduino 23

    29/42

    7lseelse { do this; }

     

  • 8/18/2019 1 Arduino 23

    30/42

    4asic 6epetition

    • loop

    • 1or 

    • while

  • 8/18/2019 1 Arduino 23

    31/42

    4asic 6epetition

    void loop ( ) { }

  • 8/18/2019 1 Arduino 23

    32/42

    4asic 6epetition

    void loop ( ) { }

  • 8/18/2019 1 Arduino 23

    33/42

    4asic 6epetition

    void  loop ( ) { }

  • 8/18/2019 1 Arduino 23

    34/42

    4asic 6epetition

    for (int count = 0; count

  • 8/18/2019 1 Arduino 23

    35/42

    4asic 6epetition

    for (int count = 0; count

  • 8/18/2019 1 Arduino 23

    36/42

    4asic 6epetition

    for (int count = 0; count

  • 8/18/2019 1 Arduino 23

    37/42

    4asic 6epetition

    for  ( int count = 0; count

  • 8/18/2019 1 Arduino 23

    38/42

    4asic 6epetition

    for  (int count = 0; count

  • 8/18/2019 1 Arduino 23

    39/42

    4asic 6epetition

    for  (int count = 0; count

  • 8/18/2019 1 Arduino 23

    40/42

    4asic 6epetition

    for  (int count = 0; count

  • 8/18/2019 1 Arduino 23

    41/42

    4asic 6epetition

    while (  count

  • 8/18/2019 1 Arduino 23

    42/42

    4asic 6epetition

    while (  count