Sie sind auf Seite 1von 8

2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.

com



PocketAVRProgrammerHookupGuide
CONTRIBUTORS: JIMB0

FAVORITE 4

Introduction
DoyouneedmorecontroloveryourAVRs?WhetheritsanATmega328,ATmega32U4,ATtiny85,ifitsanAVRtheresagoodchancetheAVRPocketProgrammer
canprogramit.

TherearemanyreasonsforprogrammingyourAVRviaaninsystemprogrammer(ISP).IfyourAVRdoesnthaveabootloaderonit,itsprobablytheonlywayto
loadcode.Ormaybeyouwanttooverwritethebootloadertosqueezeoutsomeextraflashspace.Ormaybeyouwanttopokeatthefusebits,tochangethebrown
outvoltage.Ormaybeyoujustwantafasterandmorereliablecodeupload.

CoveredInThisTutorial
InthistutorialwewillintroduceyoutoalloftheimportantaspectsoftheAVRPocketProgrammer.Itssplitintoaseriesofsections,whichcover:

BoardOverviewAlookatthehardwarecomponentsthatmakeuptheAVRPocketProgrammer.
InstallingDriversHowtoinstalltheAVRPocketProgrammersonaWindowsmachine(MacandLinuxuserscanskipthispage).
ProgrammingviaArduinoHowtousetheubiquitouseasymodeAVRIDEtouploadsketchesviatheAVRPocketProgrammer.
UsingAVRDUDEAmoreadvanced,commandlinebasedapproachtousingtheAVRPocketProgrammer.

RequiredMaterials
Mostimportantly,tofollowalongwiththistutorial,youwillneedanAVRPocketProgrammerandanAVRtoprogram.Ontopofthat,aminiBUSBcableisrequired
toconnecttheProgrammertoyourcomputer.

ThatmicrocontrollertobeprogrammedcanbeanyAVRwith64Korlessofflash.TheATmega328onanArduinoUnoorRedBoardworksperfectly,butthe
ATmega2560ofanArduinoMegadoesnot.

Beyondthat,youmayneedsomethingtointerfacetheProgrammertoyourAVR.Herearesomeusefulaccessories,whichmightmakethejobeasier:

StraightMaleHeadersIfyouhaveanAVRonadevelopmentboardlikeanArduinoProthe2x3(or2x5)ISPheadermaynotbepopulated.Youcanuse
straightmaleheaders(alsoavailableinalongpinnedversion)tomakeatemporarycontactbetweenISPcableandyourdevboard.Thereisalsoa2x3pin
version.
ISPPogoAdapterLiketheheaders,thisISPadapterisdesignedtoprovideatemporaryelectricalconnectionbetweenadapterandAVR.Thisisagreat,
morereliablealternativetotheheaders.
AVRProgrammingAdapterIfyouAVRislivingonabreadboard,youprobablydonthaveaninterfacetothestandard2x3ISPpinout.Thissimplebreakout
boardmakesinterfacingtheprogrammerwithyourbreadboardedcircuitpossible.

SuggestedReading
Whetheryoureabeginnerorexperiencedelectronicsenthusiast,thePocketProgrammershouldbeeasytogetupandrunning.IfyouveprogrammedanArduino
before,youllbewellpreparedforthenextstep.Herearesometutorialswedrecommendreadingbeforecontinuingonwiththisone:

WhatisanArduino?IfyoureunfamiliarwithAVRs,checkoutthistutorialtolearnaboutthemostpopularoneofthelot.
InstallingArduinoArduinoisntrequiredtousetheProgrammer,butitcanmakethingseasier,especiallyifyoustillwanttoprogramyourAVRusingthe
Arduinolibraries.
SerialPeripheralInterface(SPI)ThePocketProgrammerusesanSPIinterfacetosenddatatoandfromtheAVR.Clickthistutorialtolearnthemeanings
behindMOSI,MISO,andSCK.

BoardOverview
BeforewegettousingtheAVRPocketProgrammer,letsquicklyoverviewwhatcomponentsfilltheboardout:

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 1/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com

USBConnectorThisisyourdataandpowerinputtotheProgrammer.AminiBUSBcableplugsinhereandconnectsyourcomputertotheProgrammer.
2x5ISPHeaderThisshroudedheadermateswiththeincludedProgrammingCable,andallowsyoutosendtheprogrammingsignalsouttoyourAVR.Its
polarizedtomakesureyoucantpluganythinginbackwards.
PowerTargetSwitchUnlikealotofISPsoutthere,theAVRPocketProgrammercandeliverpowertotheAVRtobeprogrammed.Flickthisswitchtothe
PowerTargetside,tosend5VtotheAVR.Moreonthisbelow.
ATtiny2313Thisisthechipthatworkstheprogrammingmagic.ItconvertsbetweenUSBandSPItoturncommandsfromyourcomputerintowordsand
instructionstoloadintoyourAVRtobeprogrammed.UnlessyouwanttocustomizetheTinyISPfirmware,youcanleavethischipalone.
TheunpopulatedISPheader,abovetheATtiny2313,isbrokenoutincasethatchipneedstobeprogrammed.Itsmostlyusedinproductionbythose
whoprogramtheprogrammers.
74AC125BufferThischiphelpstoaddsomeprotectiontotheprogrammerbybufferingthedatalineoutputs.AnotherICtomostlyignore.

TheboardalsoincludesavarietyofLEDstoindicatepower,status,anddatatransfers.

AVRISPPinouts
AVRsareprogrammedthroughanSPIinterface.TherearesixuniquesignalsrequiredforcommunicationbetweenISPandAVR:VCC,GND,Reset,MOSI,MISO,
andSCK.

Toroutethosesignalsbetweendevices,therearetwostandardizedconnectorsone6pin,2x3connectorandanother10pin,2x5:

AVRISPpinoutstopview.

TheAVRPocketProgrammerincludesanonboard2x5connector,andtheincludedAVRProgrammingCableterminateswithboth2x5and2x3connectors.

PowerTargetSwitch
IfyoureworkingwithanAVRonabreadboardoraprototype,powermaybehardtocomeby.TheAVRPocketProgrammerallowsyoutoroute5VouttoyourAVR.
Itcandeliverupwardsof500mAbeforetrippingtheonboardPTC.

IftheswitchisinthePowerTargetposition,itwillroute5VouttoyourAVR.Otherwise,iftheswitchispointingtowardsNoPower,nosignalwillbeconnectedtothe
5VpinontheISPconnector.

Becarefulusingthisfeature!Itwilloutput5Vandonly5V!Ifyoureworkingwitha3.3Vor1.8Vsystem,makesurethisswitchisintheNoPowerposition.

InstallingDrivers
DriverinstallationisrequiredonWindowsmachinesonly.IfyoureusingMacorLinux,feelfreetoclickovertothenextsection.Otherwise,followalongbelowas
weoverviewtheinstallationprocess.

Therearetwosetsofinstructionfordriverinstallationonthispage.Thefirstistheeasiest,quickestmethod,andshouldworkformosteveryone.Thesecond
installationprocessisonlyrequiredifthefirstonefailsittakesamoremanualapproachtothedriverinstallation.

InstalltheDriversAutomaticallywithZadig
Tobegin,plugtheAVRPocketProgrammerintoyourcomputer.Uponinitiallyconnectingtheboard,Windowswilltrytoautomaticallyinstallthedrivers.Some
computersmaybelucky,butmostwillturnupwithamessagenotifyingyouthatthedriverinstallfailed.

Clickthelinkbelowtodownloadthedrivers:

DownloadtheZadigUSBtinyDrivers
UseyourfavoriteunzippertoextracttheZIPfile.Dontforgetwhereyouputtheextractedfolder!

AfteryouvepluggedtheAVRPocketProgrammerintoyourcomputerandyourmachinehasrunthroughtheprocessofcheckingforandfailingtoinstalldrivers,
proceedtothezadig_v2.0.1.160folderyoujustunzipped.ThenRunzadig.exe.

ZadigisawonderfultoolthatcaninstallthedriversonjustaboutanyWindowsplatformoutthere.Uponopeningtheprogram,youshouldbegreetedwithawindow
likethis:

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 2/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com
Thereareafewoptionstoverifybeforeinstallingthedriver:

SelectthedeviceThetopdropboxcontrolswhichdeviceyouwanttoinstallthedriverfor.Hopefullyyouonlyhaveoneoptionhere,somethinglike
UnknownDevice#1.Ifyouhavemorethanoneoption,checkyourdevicemanagertoseeifyoucanmakesenseofwhichiswhich(pluggingandunplugging
adeviceusuallyhelps).
SelectthedriverClickthearrowsinthisboxuntilyouhappenuponlibusbwin32(vx.x.x.x),thatsthedriverwewanttoinstall.

Afterverifyingthosetwoselections,clickInstallDriver.Theinstallationprocesscantakeafewminutes,butafteryouvewatchedthescrollbarzoombycountless
times,youshouldbegreetedwithaThedriverwasinstalledsuccessfullymessage.

Ifyouweresuccessful,closeoutoftheZadigprogramandproceedtothenextsection!

IfZadigdidntworkforyou,checkouttheinstructionsbelowforhelpmanuallyinstallingthedrivers.

ManuallyInstallingthelibUSBDrivers
If,forsomereason,Zadigdidntworkforyou.Readtheinstructionsbelowtomanuallyinstallthedrivers.

Note:IfyouareusingaWindows8machine,beforeyoucaninstallthedriversyoullneedtodisabledriversignatureenforcement.Followalongwithourtutorial
toturnthatoverzealoussafetyguardoffforaminute.

Clickthelinkbelowtodownloadthedrivers:

DownloadtheUSBtinyDrivers
UseyourfavoriteunzippertoextracttheZIPfile.Dontforgetwhereyouputtheextractedfolder!

AfteryouvepluggedintheProgrammer,andWindowshasfailedtoinstallthedriver.Followthesestepstoinstallthedriver:

1.OpentheDeviceManagerThereareafewroutestoopenupthedevicemanager.
YoucangototheControlPanel,thenclickHardwareandSound,thenclickDeviceManager.

Or,simplyopentheruntool(pressWindowsKey+R),andrun devmgmt.msc .
2.IntheDeviceManager,youshouldseeanUnknowndevicelistedundertheOtherdevicestree.RightclickUnkownDeviceandselectUpdatedriver
software.

3.ClickBrowsemycomputerfordriversoftwareintheUpdateDiverSoftwareUnknownDevicewindowthatpopsup.

4.ClickBrowseandnavigatetothe../usbtinyisp_libusbwin32_1.2.1.0folderyoujustdownloaded.ThenclickNext.

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 3/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com
5.Windowswillbegininstallingthedriver,andthenimmediatelynotifyyouthatthedriverisntsigned.ClickInstallthisdriversoftwareanywayoption,to
proceedwiththeinstallation.

6.Afterafewmoments,thedrivershouldsuccessfullyinstall.YoullbepromptedwithaWindowshassusccessfullyupdatedyourdriversoftwarewindow.Close
that,andyoullseeaUSBtinyentrypopulatedintheDeviceManager,undertheLibUSBWin32Devicestree.

Congratulations!Proceedovertothenextsection,andwellstartusingtheProgrammer!

Breatheeasynow!OnceyouveinstalledtheUSBTinyProgrammerdriversonyourcomputer,youshouldnteverhavetodoitagain.Nowitstimetoprogram
something!

ProgrammingviaArduino
Arduinohasabuiltintoolthatallowsyoutouploadyoursketchviaaprogrammerinsteadoftheserialbootloader.IfyourejusttakingyourfirststepstowardISPing
yourArduinocompatibleAVR,thisisagoodplacetostart.

ConnecttheProgrammer
First,letsconnecttheprogrammertoourArduino.MostArduinosbreakoutthestandardized2x3ISPheadertowardstheedgeoftheboard.Plugthe2x5connector
endofincludedprogrammingcableintoyourAVRPocketProgrammer,thenconnecttheother,2x3endintoyourArduino.

Notethenotchontheconnectorfacingthesamedirectionaspin1(markedwithasmallwhitelinehere)onthe2x3Arduinoconnector.

WhenconnectingtheprogrammingcabletoyouArduino,makesureyoumatchupthepolarity!Thecablehasanotchononesideoftheplastichousing.This
shouldpointtowardspin1oftheArduinosISPheader.Pin1isusuallyindicatedbyastripenexttotheholeorpin.

IfyourArduinodoesnthavetheISPpinspopulated,checkoutthebottomsectionofthispageforsometipsandtricksweveusedthroughtheyears.

PoweringTarget
Whileconnectingyourprogrammer,doublechecktomakesurethePowerTargetswitchisinthecorrectposition.TheprogrammercanpoweryourArduinoalone!
Ifyouwantittohandlethattask,slideitovertothePowerTargetposition.

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 4/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com

ThePowerTargetfeatureisespeciallyusefulifyouonlyhaveoneUSBslot/cableavailable.

UnplugyourArduinofromUSBifyouregoingtopoweritviatheProgrammeryoudontwanttocreateanyuglyreversecurrentflowsthroughyourpower
sources.

ProgrammingviaArduino
NowthattheprogrammerisconnectedtoyourArduino,openuptheIDE.ThenopenanexamplesketchlikeBlink(File>Examples>1.Basics>Blink).

Beforeuploading,weneedtotellArduinowhichprogrammerwereusing.GouptoTools>ProgrammerandselectUSBtinyISP.

AlsomakesureyouvesettheBoardoptioncorrectly!Theserialportselectionisntrequiredforuploadingthesketch,butisstillnecessaryifyouredoing
anythingwiththeserialmonitor.

Touploadthesketchusingtheprogrammeryouselected,gotoFile>UploadUsingProgrammer.Ifyoullbedoingthisalot,getusedtopressingCTRL+SHIFT+U
(COMMAND+SHIFT+UonMac).

TheArduinowillrunthroughitsnormalprocessofcompiling.Afterthesketchcompiles,theProgrammerwillstartlightingupblueeverywheretheD+andD
LEDswilllightup,andsowilltheStat2LED.WhentheStat2LEDturnsoff,theuploadwillbefinished.CheckthestatusareaofyourArduinoIDEtoverifythatthe
sketchisDoneuploading.

Ifyouveuploadedasketchviatheprogrammer,youvealsowipedoffthebootloader.IfyoueverwanttoputtheserialbootloaderbackonyourArduino,checkout
thenextsection.

ProgrammingaBootloader
TheArduinoIDEalsohasafeaturebuiltintoallowyouto(re)uploadabootloadertotheAVR.Hereshow:

MakesureyouvesettheBoardoptioncorrectlyamongotherthings,thatwillsetwhichbootloaderyoullbeuploading.Then,simplynavigateuptoTools>Burn
Bootloaderattheverybottomofthemenu.

Thisprocessmaytakeaminuteorso.NotonlywillthebootloaderbewrittenintotheflashofyourAVR,thefusebits(settingtheclockspeed,bootloaderspace,etc),
andlockbits(barringthebootloaderfromoverwritingitself)willalsobe(re)set.

ThebootloaderuploadprocessiscompletewhentheBurningbootloadertoI/Oboard(thismaytakeaminute)messageturnstoDoneburningbootloader.It
reallydoestakeawhileitsnotlyingwhenitsaysitmaytakeaminute.

PogoPinsortheAngledHeaderPress
MostArduinoboardsshouldhavemalepinspopulatedonthis2x3connector.Ifyourboarddoesnthavepinsshootingoutofthoseholes,thereareafewoptions.

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 5/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com
Youcansolderacouplestripsof3straightmaleheadersinthere,togetthebest,mostreliableconnection.Butifyouwanttoavoidsoldering,youcanusethose
sameheaders(longheadersworkbetterforthis),pluggingthelongendintotheprogrammingcableandpushingtheshortendintotheemptyholes,whileangling
themtomakecontactonallsixpins.

AnothersolderlessoptionistousetheISPPogoAdapter,whichwillaffordyouamorereliableelectricalconnection.

BothofthesemethodscanbetrickyyouhavetoholdthosepinssteadywhilethecodeuploadstoyourArduinobuttheyreagoodsolderless,temporaryoption.

UsingAVRDUDE
IfyourelookingformorecontroloveryourAVRPocketProgrammerandtheAVRitsconnectedtofollowalongbelow.WelldemonstratehowtouseAVRDUDE,
anopensourcecommandlinewonderutilityforreading,writingandmanipulatingAVRs.

IfyouhaveArduino,thenyoualreadyhaveAVRDUDEinstalleditsthetoolArduinousesunderthehoodtouploadsketches.IfyouneedtoinstallAVRDUDE
separately,checkoutthedownloaddocumentation.

SanityCheckDeviceSignatureVerification
AVRDUDEisacommandlinetool,so,inordertouseit,youllneedtoopenuptheCommandPrompt(Windows)orTerminal(Mac/Linux).

TomakesureAVRDUDEisworking,andyourAVRPocketProgrammerisconnectedcorrectly,itsgoodtodoalittlesanitycheckfirst.Typethisintoyourcommand
prompt:

avrdudecusbtinypatmega328p

(Note:ThisisallassumingyouhaveanATmega328Pconnectedattheotherendofyourprogrammer.Ifyouhaveadifferenttypeofmicrocontroller,youllneedto
formulateaslightlydifferentcommand,checktheSpecifyAVRDevicesectionbelow.)

Ifeverythingisconnectedcorrectly,youshouldgetaresponselikethis:

ThisbasiccommanddefinestheprogrammertypeyoureusingandtheAVRitstalkingto.AVRDUDEwillattempttoreadtheDeviceSignaturefromyourAVR,
whichisdifferentforeachAVRtypeoutthere.EveryATmega328Pshouldhaveadevicesignatureof 0x1E950F .

FlashProgramming
Nowthatyouveverifiedthateverythingisinworkingorder,youcandoallsortsofmemoryreadingandwritingwithAVRDUDE.Themainpieceofmemoryyou
probablywanttowriteisflashthenonvolatilememorywheretheprogramsarestored.

Thiscommandwillperformabasicwritetoflash(usingthisHEXfileasanexample):

avrdudecusbtinypatmega328pUflash:w:blink.hex

Writingtoflashwilltakealittlelongerthanreadingthesignaturebits.Youllseeatextstatusbarscrollbyasthedeviceisread,writtento,andverified.

The U optioncommandhandlesallofthememoryreadsandwrites.Wetellitwewanttoworkwith flash memory,doawritewith w ,andthentellitthelocationof


thehexfilewewanttowrite.

FlashReading

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 6/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com
The U commandcanalsobeusedtoreadthememorycontentsofanAVR.Acommandlikebelow,forexample,willreadthecontentsofyourAVRandstorethem
intoafilecalledmystery.hex.

avrdudecusbtinypatmega328pUflash:r:mystery.hex:r

ThisisincrediblyusefulifyouwanttocopythecontentsofoneArduinotoanother.Ormaybeyoureamasochist,andyouwanttotryreverseengineeringthe
mysterycodeinanAVR.

UsefulOptions
HerearejustafewlastAVRDUDEtipsandtricksbeforeweturnyoulooseontheAVRworld.

SpecifyAVRDevice
TwooptionsrequiredforusingAVRDUDEaretheprogrammertypeandAVRdevicespecification.Theprogrammerdefinition,assumingyoureusingtheAVR
PocketProgrammer,willbe cusbtiny .IfyouneedtouseadifferentprogrammercheckoutthispageandCTRL+Ftocprogrammerid.

TheAVRdevicetypeisdefinedwiththe p option.WeveshownafewexampleswiththeATmega328P,butwhatifyoureusinganATtiny85?Inthatcase,youll
wanttoput pt85 instead.CheckoutthetopofthispageforanexhaustivelistofcompatibleAVRdevicetypes.

VerboseOutput
Addingone,ormore v stoyourAVRDUDEcommandwillenablevariouslevelsofverbositytotheaction.Thisishandyifyouneedasummaryofyourconfiguration
options,oranindepthviewintowhatdataisbeingsenttoyourAVR.

Theresplentymorewherethatcamefrom.CheckouttheAVRDUDEOptionDocumentationfortheentirelistofcommands.

ResourcesandGoingFurther
HerearesomemoreAVRPocketProgrammerrelatedresources,shouldyouneedthem:

AVRPocketProgrammerGitHubRepositoryHereyoullfindeverythingfromPCBdesignfiles,andfirmwaretocustomenclosuredesigns.
AVRPocketProgrammerSchematic
AVRPocketProgrammerFirmware
AVRDUDEManual

GoingFurther
Wevegotplentymoretutorialswherethatcamefrom.Ifyourelookingformorestufftolearn,orarelookingforsomeprojectinspiration,checkoutthesetutorials!

InstallinganArduinoBootloaderUseyourAVRPocketProgrammertoloadabootloaderontoanArduino.Thistutorialwillteachyouwhatabootloaderis,
whyyouwouldneedtoinstall/reinstallit,andgoovertheprocessofdoingso.
WirelessArduinoProgrammingwithElectricImpIfyourefeelingconstrainedbytheUSBcables,checkoutthistutorialwhereweuploadcodetoanArduino
wirelessly!
TinyAVRProgrammerHookupGuideIfyourelookingtoprogramATtiny85sspecifically,checkouttheTinyAVRProgrammer.
UsingtheArduinoProMini3.3VIfyourealreadydirectlyprogrammingyourArduino,takeitastepfurtherwiththeArduinoProMini.
WirelessXBee/AVRBootloadingUseyourAVRPocketProgrammertouploadacustombootloader,thenwirelesslyprogramyourArduino.

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 7/8
2017510 PocketAVRProgrammerHookupGuidelearn.sparkfun.com

https://learn.sparkfun.com/tutorials/pocketavrprogrammerhookupguide?_ga=2.114536128.656176168.14944205042014964188.1494416947 8/8