Escolar Documentos
Profissional Documentos
Cultura Documentos
Programming Beginning
with Arduino
CharlieMooney
Microcontrollers
Tiny,selfcontainedcomputersinanIC
Oftencontainperipherals
Differentpackagesavailible
Vastarrayofsizeandpoweravailible
Sensory Input
Robotsneedtobeabletorecieveinputfromthe
worldintheformofsensoryinput.
Microcontrollershandlethisinput.
Thousandsofsophisticatedsensorsavailiable
Pressure/Force Sensors
GPS Locators
Gyroscopes
Wheel Encoders
Accelerometers
Ultrasonic Rangefinders
Arduino
DevelopmentboardfortheATMega328
Inludes
Programmer,
VoltageRegulators
SeraltoUSBConverter
CHEAP$30!Haseverythingyouneed!
Arduino C Template
voidsetup(){
//Setupstufftoonlyrunonceatthebeginning
}
voidloop()
{
//Thisfunctiongetscalledindefinatly
}
Peripherals
AnalogtoDigitalConverters(ADC)
Counters/Timers(TMRx)
PWMModules(CCP/PWM)
SerialPorts(UART)
Many,manymore....
Digital I/O
OnlyHIGHandLOWvalues
Eachpinconfigurabletodoinputoroutput
pinMode(pinNumber,pinState)
pinMode(13,INPUT)
pinMode(13,OUTPUT)
Output
Input
digitalWrite(pinNumber,HIGH/LOW)
intval=digitalRead(pinNumber)
CommunicatewithothermicrocontrollersorPC's
Asynch.communication
Arduinolibrariesmakeitextremelyeasy
Serial.begin(baudRate)
Serial.println(StringToSend)
intbytesWaiting=Serial.Availible()
CharincomingData=Serial.read()
Takeanalogvoltageasinputononeofthepins
Returndigitalrepresentationtoprogram
Differentnumbersofbitschangeprecision.
Light Sensors
Photoresistors
ExtremelySimpletoUse
Resistancechangeswithlight
Measurevoltageoverthesensorwith
anADC,andyou'redone
Manymorecomplicatedsensors
simulatethisbehaviorforsimplicity
//PrintsensorvaluetotheSerial
Serial.println(sensorValue);
}
CreatePWMsignalsonoutputpins
MeasurePWMsignalsoninputpins
CCPstandsforCapture/Compare
WhatisPWM,anyway?
Transmitanalogvaluesusingasingledigitalinput/
outputpinthroughcarefultiming.
APWMsignalconsistsoftwovalues
Period:howlongbeforethesignalrepeats
PulseWidth:howlongthesignalisHIGHbeforeit
goesLOW.
DutyCycle:%oftimethesignalisHIGH,or
(PulseWidth/Period)
PWM In Robotics
Theaveragevoltage(DutyCycle*Voltage)canbe
usedtocontrolthespeedofDCmotors.
Innaccurate,poorstrength,braking,andother
problemsexist.
ServoMotorsandSpeedControllers.
Servo Motors
DCMotorwithgearsallowforhightorque
EmbeddedmicrocontrollermonitorsPWMinput
andmotorposition.
Varypulsewidthtochangepositionofmotor
Speed Controllers
Embeddedmicrocontrollervariesvoltageonoutput
linesbasedonPWMinput.
Resultsinconstantvoltagetomotorsratherthan
intermittent.
Allowasecond,morepowerful,powersupplyto
drivelargemotors.
Alterpuslewidthtochangethespeedofthemotor
AnalogWrite(Pin,DutyCycle)
DutyCycle=00%,12750%,255100%
Pincanbe3,5,6,9,10,or11
Frequencyofabout490Htz
Otherperiodsarepossible,butnotwithAnalogWrite
Useful Resources
RobotPartsandExcellentForums
www.TrossenRobotics.com
Electricalparts,sensors,andmicrocontrollers
www.Sparkfun.com
ArduinoDevelopmentPlatform
www.ardiono.cc