1bac4d66844a313c8aa2958adb5d9e54.ppt
- Количество слайдов: 39
Introduction to Arduino Microcontrollers Jeff Mc. Raven jamcraven@yahoo. com
Overview n Background Microcontroller defined/Why Arduino's? n Types of Arduino microcontrollers n What To Get (Hardware and Software) n Arduino C n Electronic Circuits n Projects n Blinking light(s) n Reading inputs (variable resistors) n
Microcontrollers – One Definition Programmers work in the virtual world. n Machinery works in the physical world. n How does one connect the virtual world to the physical world? n Enter the microcontroller. n A microcontroller is basically a small-scale computer with generalized (and programmable) inputs and outputs. n The inputs and outputs can be manipulated by and can manipulate the physical world. n
Arduino – Official Definition n Taken from the official web site (arduino. cc): n Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.
Why Arduino? n For whatever reason, Arduino microcontrollers have become the de facto standard. n n Make Magazine features many projects using Arduino microcontrollers. Strives for the balance between ease of use and usefulness. Programming languages seen as major obstacle. n Arduino C is a greatly simplified version of C++. n n Inexpensive ($35 retail).
Arduino Types n Many different versions Number of input/output channels n Form factor n Processor n Leonardo n Due n Micro n Lily. Pad n Esplora n Uno n
Leonardo Compared to the Uno, a slight upgrade. n Built in USB compatibility n n n Presents to PC as a mouse or keyboard Bugs?
Due Much faster processor, many more pins n Operates on 3. 3 volts n Similar to the Mega n
Micro When size matters: Micro, Nano, Mini n Includes all functionality of the Leonardo n Easily usable on a breadboard n
Lily. Pad n Lily. Pad is popular for clothing-based projects.
Esplora Game controller n Includes joystick, four buttons, linear potentiometer (slider), microphone, light sensor, temperature sensor, three-axis accelerometer. n Not the standard set of IO pins. n
Arduino Uno Close Up n The pins are in three groups: Invented in 2010 n 14 digital pins n 6 analog pins n power n
Where to Start Get an Arduino (starter kit) n Download the compiler n Connect the controller n Configure the compiler n Connect the circuit n Write the program n Get frustrated/Debug/Get it to work n Get excited and immediately start next project n (sleep is for wimps)
Arduino Starter Kits n Start with a combo pack (starter kit) n n Includes a microcontroller, wire, LED's, sensors, etc. www. adafruit. com/products/68 ($65) n www. sparkfun. com https: //www. sparkfun. com/products/11576 ($99. 95) n Radio Shack Make Ultimate Microcontroller Pack w/ Arduino Kit ($119. 99) n www. makershed. com http: //www. makershed. com/Ultimate_Arduino_Microcontroller_Pack_p/msump 1. htm ($150)
What to Get – My Recommendation n Required: n n n n Arduino (such as Uno) USB A-B (printer) cable Breadboard Hookup wire LED's Resistors Sensors Switches n Good Idea: n n n Capacitors Transistors DC motor/servo Relay Advanced: n n Soldering iron & solder Heat shrink tubing 9 V battery adapter Bench power supply
Arduino Compiler n Download current compiler from: arduino. cc/en/Main/software Arrogantly refers to itself as an IDE (Ha!). n Run the software installer. n Written in Java, it is fairly slow. n Visit playground. arduino. cc/Main/ Development. Tools for alternatives to the base arduino IDE
Configuring the Arduino Compiler Defaults to COM 1, will probably need to change the COM port setting (my work PC uses 7). n Appears in Device Manager (Win 7) under Ports as a Comm port. n
Arduino Program Development Based on C++ without 80% of the instructions. n A handful of new commands. n Programs are called 'sketches'. n Sketches need two functions: n void setup( ) n void loop( ) n setup( ) runs first and once. n loop( ) runs over and over, until power is lost or a new sketch is loaded. n
Arduino C Arduino sketches are centered around the pins on an Arduino board. n Arduino sketches always loop. n n n void loop( ) {} is equivalent to while(1) { } The pins can be thought of as global variables.
Arduino C Specific Functions n pin. Mode(pin, mode) Designates the specified pin for input or output n digital. Write(pin, value) Sends a voltage level to the designated pin n digital. Read(pin) Reads the current voltage level from the designated pin n analog versions of above n n analog. Read's range is 0 to 1023 serial commands n print, println, write
Compiler Features n n n Numerous sample sketches are included in the compiler Located under File, Examples Once a sketch is written, it is uploaded by clicking on File, Upload, or by pressing
Arduino C is Derived from C++ n These programs blink an LED on pin 13 n avr-libc #include
Basic Electric Circuit Every circuit (electric or electronic) must have at least a power source and a load. n The simplest circuit is a light. n Plug in the light, and it lights up. n Unplug it, the light goes out. n Electricity flows from the power source, through the load (the light) and then back to the power source. n
Basic LED Circuit Connect the positive (+) lead of a power source to the long leg of an LED. n Connect other leg of the LED to a resistor. n High resistance means a darker light. n Low resistance means brighter light. n No resistance means a burned out LED. n n Connect other leg of the resistor to the negative lead of the power source.
Let the Good Times Roll! n At this point we have: Purchased a starter kit, including the Arduino n Connected and configured the Arduino n Connected a simple LED circuit n n Let's write some code!
Blink Sketch void setup( ) { Connected to pin. Mode(13, OUTPUT); one end of the circuit } void loop( ) { digital. Write(13, HIGH); delay(1000); digital. Write(13, LOW); delay(1000); } Connected to other end of the circuit
4 LED Blink Sketch void setup( ) { pin. Mode(1, OUTPUT); pin. Mode(3, OUTPUT); pin. Mode(5, OUTPUT); pin. Mode(7, OUTPUT); } void loop( ) { digital. Write(1, HIGH); delay (200); digital. Write(1, LOW); digital. Write(3, HIGH); delay (200); digital. Write(3, LOW); digital. Write(5, HIGH); delay (200); digital. Write(5, LOW); digital. Write(7, HIGH); delay (200); digital. Write(7, LOW); }
So What? Great. Blinking lights. Not impressed. n Only covered output thus far. n Can use analog inputs to detect a physical phenomena. n
Inputs n Digital inputs will come to the Arduino as either on or off (HIGH or LOW, respectively). HIGH is 5 VDC. n LOW is 0 VDC. n n Analog inputs will come to the Arduino as a range of numbers, based upon the electrical characteristics of the circuit. 0 to 1023 n. 0049 V per digit (4. 9 m. V) n Read time is 100 microseconds (10, 000 a second) n
Analog Input A potentiometer (variable resistor) is connected to analog pin 0 to an Arduino. n Values presented to pin 0 will vary depending upon the resistance of the potentiometer. n
Analog Input-Application The variable resistor can be replaced with a sensor. n For example, a photo resistor. n n Depending upon the light level at the photo resistor: n Turn on a light n Increase or decrease the brightness of an LED (or an LED array) n Most sensors are simply variable resistors, but vary their resistance based on some physical characteristic.
Sensors can be both binary or a range. n Usually, sensors that measure a range of values vary their resistance to reflect their detection. n Arduinos can only sense voltages, not resistances. n Sensors that only vary their resistances require a circuit called a voltage divider to provide the Arduino a voltage. n
Common Sensors n n n Dials on a radio are simply potentiometers Temperature Light Angle Switches n n did the user throw a switch or push a button? Accelerometer (measures motion and tilt) n n Infrared sensor & light Hall effect sensor and magnet Ball tilt sensor (for measuring orientation) Force
“Competitors”to the Arduino n PIC controller n n Microcontroller programmed with C or assembler Alternatives to the Arduino line Pinguino – PIC controller n MSP 430 – Texas Instruments; $4. 30 n Others: customs, Teensy, etc. n Netduino n Computers n Raspberry Pi n Beagle. Bones – TI; has computer and controller n
Netduino n n Microcontroller and development tools created by Microsoft to work with the. NET Micro Framework. VASTLY better development environment. n n n Differences n n visualmicro. com Other alternatives Pins on a Netduino are 3. 3 V (not 5). Netduinos have a much faster processor. 60 K of RAM (versus an Uno's 2 K). Largely compatible with the Arduino, but it is not a drop-in replacement (can fry it).
Raspberry Pi Low end computer, not a controller n Uses Debian Linux n n n Arch Linux ARM, Fedora, Free. BSD, Slackware… Programmed with Python n BBC BASIC, C, Perl As it is a computer and not a controller, its role in these projects is different. n Hierarchy: computers controllers, controllers control hardware. n
Shields are circuit boards that plug into the top of an Arduino. n They extend the capabilities of an Arduino. n Examples: n Ethernet n GPS n Motor n Prototype n n shieldlist. org
Conclusion The Arduino microcontroller is a low cost way to enter into the hobby of robotics. n The Arduino has two plusses over any other: n The user community n Extensive online library of code and projects n Viewed as the "base" system, upon which all other microcontrollers are built. Compatibility. n So get a kit, and start ushering in the inevitable takeover of our robotic overlords! n
Introduction to Arduino Microcontrollers Jeff Mc. Raven jamcraven@yahoo. com