
Transcription
Introduction to ArduinoWith ArduBlock & LilyPad DevBrian HuangEducation [email protected]
Pre-Class Surveyhttp://bit.ly/14Xk3Ek
ResourcesThis PPT ArduBlock Download & Installation http://www.ardublock.com/
General RulesRaise your hand if you have a question.Be respectful.When I raise my hand Share your findings with the people nearyou.Poke around, experiment, and have fun Imagine, create, and play!!!
ObjectivesProvide a thorough introduction to the Arduinoprogramming environment.Develop a use of simple functions to interactwith the LEDs, light sensor, push button, andbuzzer on the Protosnap Pro Mini.
Arduino LilyPad Protosnap DevWhat is it?What can it do?Who cares?
What is it?Heart of it – ATMega328 (a 4 microcontroller)Open SourceHigh tolerance for ESD and “bad” electronicspractices Provides easy way to interact with a computerphysically – a.k.a. physical computing
What can it do?- Great for prototypingideas- Great to teach Intro toProgramming Arduino(no assembly required!)- Lots and lots of options!- Large pads can be sewable
Who cares?Hackers / !!
Physical Computing
Components, Silk Screen & PinsWhat is all this?the BrainATmega328Temp.SensorLightSensorBuzzer /Speaker
Actual Pin-outs
ArduBlockIntroduction to ProgrammingScratch-like interfaceClear transition to text-based coding
Block OrganizationControl
Block OrganizationPins
Block OrganizationNumbers/Constants
Block OrganizationOperators
Block OrganizationOperators
Block OrganizationUtilities
Block OrganizationUtilities I2C
Understanding Input vs. OutputReferenced from the perspective of the microcontroller (electrical board).Inputs is a signal / informationOutput is any signal exiting thegoing into the board.board.Almost all systems that use physical computing will havesome form of outputWhat are some examples of Outputs?
Startup Arduino IDEDouble-click on eitherthe Arduino Icon orwherever youinstalled (saved) theArduino program.
Plug it in
Lesson #0 – Configuring Arduino1. Setup Board(LilyPad Arduino w/ ATmega328)2. Setup COM PortPC – Highest COM #Mac – /dev/tty.usbserial-A####xXx
Settings: Tools Board
Settings: Tools Serial Port
Other Board Types
Load ArduBlock
Lesson #0 – Test Upload
Check for Status Messages
Let’s get to hacking Lesson #1 – Blinking an LED“Hello World” of Physical ComputingPsuedo-code – how should this work?TurnLED ONWaitTurnLEDOFFWaitRinse &Repeat
Let’s get to hacking Lesson #1 – Blinking an LED“Hello World” of Physical Computing
LED Pins161817
How are Analog Pins reallyidentified?Digital Pins are numbered 0 to 13.Analog Input Pins are A0 to A5.A0A1A2A3A4A5 14 15 16 17 18 19
Alright? Let’s blink!Challenge 1a – Blink multiple LEDsPlan out a pattern – can you make it?Challenge 1b – Blink to mimic a heartbeatChallenge 1c – Multiple LEDS – KnightRider style
Save your Project Save early, Saveoften! Enumerate youriterations – (e.g.blink 10.adp,blink 11.adp,blink 12.adp )
Concept: Analog vs. DigitalMicrocontrollers are digital devices – ON or OFF.An Analog signal is anything that can be a fullrange of values. What are some examples?Think of like a ramp or a hill.
Concept: Analog vs. DigitalTo create an analog signal, themicrocontroller uses a technique calledPWM.Pins 3, 5, 6, 9, 10, 11 are capable of producing anAnalog OutputPulse Width Modulation (PWM)
Color Mixing with 3 LEDsanalogWrite()Challenge 2a:1) How do you turn on the RED LED?2) Experiment with different values – what do you observehappens?3) How do you turn on the GREEN or the BLUE LED?
Color Mixing with 3 LEDsTri-color LEDThe RGB LED is a CommonAnode (means the positive sideof the LED is all tied to Vcc).5VThe signal line is connected to thebottom of each LED.Don’t worry - it’s just a differentmethod of completing a circuit!Pin9Pin11Pin10
Color Mixing with 3 LEDsanalogWrite()Challenge 2b:Experiment with different values of Red, Green, and Blueto create a couple different colors.Write down the values you used. Check these valueswith www.colorpicker.comChallenge 2c:Create a unique lighting display that integrates a blink,fade, or a switching of colors. Be prepared to have aname for your art piece and show this to the rest of theclass.
Save your Project #2
Concept: If(), If() – else conditional logic
Concept: If(), If() – else conditional logic
A Simple ExampleDIGINPUT 2Try this bit of code.What do you think will happen?Test it and write down yourobservations.
digital InputsButtons / Slide SwitchesAnalog Pin MappingWhat aboutthis?Analog PinA0A1A2A3A4A5A6Digital I/O ID 14151617181920INPUT A5INPUT A5(a.k.a. 19)
digital InputsButtons / Slide SwitchesSame asPin A5Challenge 3a:Re-arrange the blocks or add new ones to: Turn ON an LED when the button is pressed. Otherwise blink continuously
digital InputsButtons / Slide SwitchesChallenge 3b:Now, using the button / switch – to start a disco/light changingpatternChallenge 3c:Now, using the button / switch – to turn on and off the VIBEmotor.
Serial MonitorSerial printcommandAnymessage“glue”Data
Example
Open up Serial Monitor
Reading theLight Sensor?
ChallengeUse the light sensor input to affect the blinkrate of the LEDs.Use the light sensor input to affect the speedof a “knight-rider” or cylon display.Use the light sensor to .
Save your Project #3Sensors
Making MusicSetting up the Speaker
Making MusicLet’s Play a song Twinkle-Twinkle:CC GG AA G FF EE DD C GGHappy Birthday:GGAGCBGGAGDCGGGECCBAHot Cross Buns:B A G B A G G G G G A A A A B A GMary Had A Little Lamb:B A G A BB B AA A BB B B A G A BBBB AAA BAG.
Musical Notes / FrequenciesNoteFrequency (Hz)NoteFrequency 659698739783830880932987
Save your Project #4Tone
Getting started with Arduino
Additional fun.comhttp://www.arduino.cchttp://www.bildr.org
SparkFun Tutorials and Projects- GardenBot:www.sparkfun.com/news/598- High Altitude Balloon:www.sparkfun.com/tutorials/180- GPS Clock:www.sparkfun.com/tutorials/47- Earthquake Data Logger:www.sparkfun.com/tutorials/235
Thousands of Amazing ideas The Cat Defender http://www.plasma2002.com/blenderdefender/List of projects at Sparkfun:http://goo.gl/2M3AM
Questions?
Feedback?Before leaving, please fill out a quick surveyso that I can get your e-mail and a littleinfo about your familiarity with Arduino /Sparkfun.Thanks!http://bit.ly/ZAmDMk
www.sparkfun.com6175 Longbow Drive, Suite 200Boulder, Colorado 80301
Buttons / Slide SwitchesDigital Input, Pull-up Resistors, anddigitalRead()DIGINPUT
Buttons / Slide SwitchesDigital Input, Pull-up Resistors, anddigitalRead()DIGINPUT
blink_12.adp ) Concept: Analog vs. Digital Microcontrollers are digital devices - ON or OFF. An Analog signal is anything that can be a full range of values. What are some examples? Think of like a ramp or a hill. Concept: Analog vs. Digital To create an analog signal, the