Getting Started with the: Wind Energy Challenge

advertisement
Microcontroller Hands-on
Workshop
Ahmad Manshad
New Mexico State University
Institute of Electrical and Electronics Engineers
October 24, 2009
Agenda for Today






Workshop procedures
Robot competition
Make teams
Intro to Microcontrollers (Arduino)
Build LED circuit w/ arduino
Control LED using Potentiometer
2
Workshop Guidelines
Goal:
Learn how to use the Arduino microcontroller and design an
autonomous sumo wrestling robot.
Workshops:
 Workshops will take place every Saturday at 1pm. Last workshop will
be November 28.
 Get into teams of 2-3 students
 Each workshop will cover a different topic: today will be an intro to
Arduino and digital/analog inputs and outputs.
3
General Rules
1) Equipment must be returned by the end of the
workshop
2) Parts may not be cannot be taken unless
authorized.
3) Try not to break anything!
4) Have Fun!
4
Autonomous Sumo Wrestling Robot
Competition
1) Two robots are placed in a ring.
2) The robots try to avoid falling out or avoid being
pushed out by the opponent robot.
3) The first robot that touches outside of the ring
loses the round.
4) Robot must be autonomous
5
Teams
Get into groups of
2 – 3 students
per team!!!
6
Today’s Kit
1. Arduino Microcontroller
2. USB Cable
3. Red LED
4. Potentiometer
7
What is an Arduino?

Open Source Physical Computing Platform


open source: free to inspect & modify
Tiny computer you can program

Completely stand-alone, talks to other devices

Can run off a battery

Can talk to other computers, cell phones, etc.
8
What is an Arduino?

Very similar to Basic Stamp

but cheaper, faster, & open

Uses ATmega8 microcontroller chip

Basic Stamp uses PIC microcontroller chip.

PICs and ATmega8 are very comparable,
one’s not necessarily better than the other
9
What is an Arduino?

Why not just use a bare ATmega8 chip?

Arduino is also a standardized “bootloader”

A tiny program that loads other programs

A bootloader is akin to an BIOS on a real computer. It handles the
startup of the chip

After 5 seconds, your program runs
10
What is an Arduino?

Capabilities




8 kBytes of Flash program memory
1 kByte of RAM
12 MHz
Inputs and Outputs


13 digital input/output pins
5 analog input pins

Digital I/O can read switches and buttons, control LEDs and motors

Analog input can read knobs or other varying sensors
11
What is an Arduino?

But how do you program it?

Write programs on your PC



Download them into the Arduino board
Arduino board can then be used by itself
No keyboard, mouse or display
12
What is an Arduino?
Test
LED
Digital Input/Output
Power
LED
TX/RX
LEDs
Reset
Button
Analog Input
13
What is an Arduino?
Test
LED
Digital Input/Output
Power
LED
Reset
Button
Analog Input
14
Digital and Analog

Digital – only has two values: on/off

Analog – has many (infinite) values
15
Arduino Software
Upload
to Board
Compile
Status
Area
16
Using the Arduino


Programs are called “sketches”
Load up example sketch “led_blink”
17
Using the Arduino





Write program
Compile (check for errors)
Reset board
Upload to board
Try it out with “led_blink”!
When uploading, TX/RX lights will flash as data
is transferred
 Then the board resets, pin 13 will flash fast again
 Finally, your program will run

18
Blinking LED Circuit
Wiring Diagram
Schematic
19
Blinking LED Program
20
Arduino Sketch Structure
 Declare variables at top
 Initialize
• setup() – run once at beginning, set pins
 Running
• loop() – run repeatedly, after setup()
21
Arduino Language

Language is standard C (but made easy)

Lots of useful functions






pinMode() – set a pin as input or output
digitalWrite() – set a digital pin high/low
digitalRead() – read a digital pin’s state
analogRead() – read an analog pin
analogWrite() – write an “analog” PWM value
delay() – wait an amount of time
22
Development Cycle

Make as many changes as you want

Edit ➝ compile ➝ upload ➝ run
23
Questions or
Comments?
24
Download