You are on page 1of 5

11/09/2016

cHowtostartprogrammingamicrocontroller?StackOverflow

signup

login

tour

help

Dismiss

AnnouncingStackOverflowDocumentation
WestartedwithQ&A.Technicaldocumentationisnext,andweneedyourhelp.
Whetheryou'reabeginneroranexperienceddeveloper,youcancontribute.

Signupandstarthelping

LearnmoreaboutDocumentation

Howtostartprogrammingamicrocontroller?[closed]
IhavedevelopedsoftwareinC++,Java,PHP,.NETandnowIaminterestingtolearntoprogrammaterialthings.Iwouldliketoprograma
systemthatcouldinteractwithIR,LCDandtobeabletoresuseoldprintermotorstouseit,etc.
Myproblemis,wheretostart?IhavesearchedthewebandhavefoundanopensourceboardcalledArduinobuthowtogetotherelectronic
componentstogether?WhatbookortutorialshouldIdotobeabletocreateasmallproject?
c arduino microcontroller electronics
editedApr30'12at3:18

askedSep17'08at0:50

casperOne
57.8k

10

PatrickDesjardins
125

202

69.7k

68

238

306

closedasnotconstructivebycasperOneApr30'12at3:18
Asitcurrentlystands,thisquestionisnotagoodfitforourQ&Aformat.Weexpectanswerstobesupportedbyfacts,references,orexpertise,butthisquestionwill
likelysolicitdebate,arguments,polling,orextendeddiscussion.Ifyoufeelthatthisquestioncanbeimprovedandpossiblyreopened,visitthehelpcenterforguidance.
Ifthisquestioncanberewordedtofittherulesinthehelpcenter,pleaseeditthequestion.

AddingtocommentselsewhereI'dliketosuggesttoreadabookcalled" SoYouWannaBeanEmbedded

Engineer:TheGuidetoEmbeddedEngineering,FromConsultancytotheCorporateLadder".It'dgiveyou
someclue.avarApr15'09at5:22

14Answers

Parallaxisnotoriouslyoverpriced.Theygetawaywithitbecausetheyselltheirstuffto
educationalinstitutionswhodon'tknowanybetter.
TheArduinoisagoodstart,gothroughafewoftheirexamples(click'Learning'ontheArduino
site)andseewhatpartstheyrequire.Myfavoritehobbyelectronicsonlineshopissparkfun.com.
They'vegottonsofpartsdesignedtointerfacewiththingsliketheArduino.
YoucanprogramtheminC,C++,orAVRAssembly.PersonallyI'dsayavoidtheBASICones,
theyarewayslowerandifyou'realreadyintoprogrammingit'snotworththehassle.
(FYI,theArduinoisbasicallyaboardandsoftwarelibrarydesignedaroundthewonderfulAVR
microcontroller)
answeredSep17'08at1:09

davr
11.4k

14

61

94

Greatanswer!justtoaddabit,similartoArduino,thereistheFreeduinoproject:freeduino.org

GeorgeProfenzaJun3'10at21:17
Personallysparkfunisbitoverpriced...youcanfindmanythingsmuchcheaperthroughebayoraliexpress..

ifyouarewillingtowaitalittleextratimeastheyusuallyshipfromchina.ButtherearemanyUSsellers
thathavegoodpricingonarduinosensorsetcButthatsjustmytwocents.jasonFeb26'13at4:07

I'ddefinitelysecondtheArduinosuggestion.Theyarecheap,thereareseveralsupplierssince
thehardwareisopensource(althoughthenameisn't),theIDEisfree,youprogramtheminC,
andthey'reeasytohookuptojustaboutanything.Theboardhas12digitalI/Opins(twoofwhich
doubleasserialcommunicationpins)andsix12bitA/DconverterI/Opins(whichcanalsobe

http://stackoverflow.com/questions/78744/howtostartprogrammingamicrocontroller

1/5

11/09/2016

cHowtostartprogrammingamicrocontroller?StackOverflow

configuredasdigitalpins).Itcanhandlepulsewidthmodulation(PWM)formotorandservo
control,interrupts,I2Cinterfaces,andmostboardscaneitherrunstandaloneorofftheUSBport.
CommunicationtothecomputerishandledbyanFTDIserialUSBdriver.
InadditiontoSparkfun.com,alsocheckoutwww.adafruit.comforsomecheap,smallUSB
"Boarduino"boardsandseveralniceprototypingshieldsforthefullsizedArduino.
ThemainArduinosite(Arduino.cc )hasprettymucheveryreferenceandtutorialyouneedtoget
started.
Hereisthe"Hello,World!"ofArduinoprogrammingasanexampleofhoweasyitis.Theprogram
blinksanLEDattachedtodigitalpin13:
intledPin=13;//LEDconnectedtodigitalpin13
voidsetup()
{
pinMode(ledPin,OUTPUT);//setsthedigitalpinasoutput
}
voidloop()
{
digitalWrite(ledPin,HIGH);//setstheLEDon
delay(1000);//waitsforasecond
digitalWrite(ledPin,LOW);//setstheLEDoff
delay(1000);//waitsforasecond
}

BasicallyeveryArduinoprogramhasasetup()functionthatrunswhenthepowerisappliedor
theboardisresetandaloop()functionthatrunsforever.Ofcourse,youalsohavetimersand
interruptfunctions,oryourcanusetheloop()forpollinginputsandthencallouttootherfunctions.
TheArduinoIDEsitsontopofGCCandusesthesamelibrariesandincludesthatyouwoulduse
ifyouwerewritingabarebonesprogramfortheAtmegamicrocontroller.Thismeansthat(a)it
hidesthehardpartsaslongasyouwantitto(bootloaders,fuses,etc.),(b)youcangettothe
internalsoftheprogramifyouwantto,and(c)youcanutilizealargeselectionoflibrariesthatare
outthereforthisfamilyofmicrocontrollers.
editedSep17'08at16:05

answeredSep17'08at4:33

CMPalmer
5,729

30

46

Well,thefieldofmicrocontrollersisquitebig.Youhaveseveralbrands,eachonesportingafull
rangeofcontrollers,withvaryingdegreesofcapacity,complexityandability.
Thatsaid,thewaytostartwithmostmicrocontrollersisbyreadingthemanufacturers'manual.
Asopposedto"normal"programming,wheremostprogrammersgobystandardsandrulesand
bestpracticesandframeworks,etc.microcontrollerprogrammingisstilldoneprettymuchas
programmingwasdoneintheearly1980s:byreadingacontroller'smanual,reproducing
examples,andextendingfromthere.
Microchip'smanuals ,forexample,areexcellent.Theyalsohaveaverygoodcommunity ,and
providesomelibrarieswith"standard"functionsyoumightliketouse(likemath,I/O,doingserial
I/Ousingtwopins,andsoon).AlotofthepeopleworkingwithPICsisquiteopenandnormally
sharetheirsourcecodeiftheythinkitmightbeofusetosomeoneelse.
Therearesomechoicesyouhavetomakebeforebeginning.Thefirstoneiswhatlanguageare
yougoingtouse.Youhavethreeoptions:
1.Assembly:Mostmanufacturersprovidefreeorquitecheapdevelopmentkitsfortheir
microcontrollers(MCUsforshort).Thisisthemostpowerfuloption,andtheoneyoushould
useifyoufeelcomfortable.Italsowillteachyoualotaboutcomputersingeneral.
2.Somethingelse:Ifyou'dratherusesomethinglikeC,you'llhavetopayquiteabitofmoney
forthecompiler(althoughthereisatleastoneopensourceoptionforsomeofthedevice),
andyouhavetoconsiderthecodeproducedbythehighlevellanguagesnormallytakesalot
ofspace/memoryinthedevice.Also,dependingonthestandardlibrary,you'llendup
programmingafairamountofthefunctionalityyourselfanyway.
3.Basic/Pascallikelanguage:someMCUscomewithanBasic/Pascallikeinterpreter.These
aregreattostartdoingsome"toy"projects,andgettingthefeelingofhowthisthingswork.
Then,youhavetodecidewhatkindofdeviceyouwanttouse.Pricesperunitvarygreatly
dependingonmaker,whetheritisPROM,EPROM,EEPROM,howmuchmemoryithas,how
muchstorageithas,howmanyprogrammablepins,etc.
Myrecommendation,forstarters,wouldbe:
1.Trytofindafree"burner"ontheInternetifyouwanttoexperiencethethrillofprogramming
yourMCUsusingsomethingyoubuilt.Thereareplentyavailableoutthere,justgooglefor
"simplePICburner"orsimilar.Ifthat'snotarequirement,thenyoucanbuyaburner,butit
willcostyouafairbitofmoney.
2.GetoneEEPROMversionoftheMCUyouthinkyouaregoingtousethemost.Thiswill
saveyoutheproblemofhavingtothrowawaya$5pieceofhardwarejustbecauseyou
haveabuginyourcode.
3.BuyabunchofthePROMversionoftheMCU.Theyarecheap,andyou'llneedthem.And
onceyougetstarted,you'llwanttoputanMCUeverywhere.

http://stackoverflow.com/questions/78744/howtostartprogrammingamicrocontroller

2/5

11/09/2016

cHowtostartprogrammingamicrocontroller?StackOverflow

4.LearnhowtouseTheEmulator.MostSDKscomewithanemulatoryoucanusetotestyour
ideasbeforecommittingthemtoPROM.
5.Findyourselfsomesimpleandinterestingfirstproject.ImustemphasizetheSIMPLEthere.
Ifyoutrytocomeupwithawaytocontrolyourmicrowaveovenusingaremotecontrol
straightaway,bereadyforalongperiodoflearning.
Well,hopethishelpsyou!Ifyouwantanymoreinformation,I'maroundthecorner,justwhistle!:)
editedFeb13'11at17:29

answeredSep17'08at1:35

Tyler
7,332

dguaraglia
15

41

3,617

16

22

IrecentlystartedlearningmicrocontrollerprogrammingusingtheArduino.Ipurchasedthe
ArduinoStarterPack fromadafruit.comandwalkedthroughtheirintroductorytutorials .Theirkit
comeswithsomebasicelectronics(LEDs,buttons,photoresistor)whichgiveyousomethingsto
experimentrightoffthebat.
IfyoualreadyknowC/C++youwillbeabletostartcreatingusefulandinterestingprojectswithin
hours.
TheArduinoisalsogreatbecauseonceyougetfamiliarwithityoucanexpandtowritingrawC
onanyoftheAtmelAVRlineofmicrocontrollers withease.
IalsorecommendTheElectronicsGoldminewhereyoucanpurchaseassortmentsofelectronics
forprettycheaptogetagoodstartersettoworkwith.
editedNov18'10at23:29

answeredSep19'08at0:46

PeterMortensen
10.2k

13

69

EricLathrop
107

1,090

18

TheBASICstampseriesisveryinteresting.Theyhavealotofnicesimplecontrolboardstoget
youstartedandtheprogrammingisdirtsimple.ThecontrolleractuallyexecutesBASIC.While
thatmightnotexcitealotofpeople,writingmicrocontrollercodetakestimetogetthehangofit.
Thissystemisgreattogetyourfeetwet.Thenwhenyouhavesomenicecool(andsimple)
projectrunningyoucanmoveontoothermorechallengingcontrollers.Thesewillbemostlikely
assemblyorCprogrammed.Debuggingwillbeyourgreatestchallenge.
ParallaxBASICStamp
answeredSep17'08at1:03

JohnDyer
1,303

15

19

Thisisprobablyoverkillforwhatyouaretryingtodo,butprogramminganFPGAbasedsystem
canbefun.TheVHDLlanguageismorelikewiringupcircuitsthanwritingCcode.ANexys2
boardcanbeboughtfor$130.
answeredApr15'09at7:01

Austin
1,633

11

11

EverythingyouneedforstartupinArduinoandelectronicscanbefoundhere:
http://www.smileymicros.com.IfIrememberwell,thebookauthorhas/hadacolumnforArduino
newbiesinoneofelectronicmagazines.Besidesthat,ingeneralyoushouldlearnI2C,SPI,1wire
andtrytointerfacesensorswithsuchinterfaces.Readalotofdatasheetsofsuchsensorsand
trytounderstandeverythinginthem.Askquestionswhenstuck.LearnMODBUS
(RTU/ASCII/TCP)orsimilarprotocolthatcanopenyourdevicetotheworldonceyouembeditin
thedevice.Learngeneralelectronicsandtrytointerfacerelays,triacs,stepmotors,servos,what
ispullupandpulldown,whatissourcingandsinking,howtodrawschematicsandconnect
basicdriverstoyourMCU.
answeredNov19'10at7:56

avra
3,259

17

Ialsohavetheimpressionthatyouneedtostartfrombasicmicrocontrollerarchitecturethings.
PICisgoodtostartwith,becausethebasicmodelsandearliestseriescanbeveryusefulthey
havenottoomuchextrafunctionalitysoyouwillnotbelostwithextrasconcentratingonbasics
whichisgood.
Afterthisyouneedtounderstandlotsofthingsaboutmemoryorganizationandprogram
executionincontextofmicrocontrollerlifecycleandtimingmodels.Afterthisyoucangoforward
withstartinganalysisofbasicsassemblerexamplesforaconcretemicrocontrollerandmoving
forwardwithmoreadvancedtechniques.ThenyoucanmovetomoreadvancedseriesofPIC

http://stackoverflow.com/questions/78744/howtostartprogrammingamicrocontroller

3/5

11/09/2016

cHowtostartprogrammingamicrocontroller?StackOverflow

withDACandothermoduleswhicharethecommonformostofmodernmicrocontrollers,buton
thePICyoucangetlotsofbasicswithoutadditionalpainwhichwillworkprettythesameforall
otherchips.
editedOct30'11at19:12

answeredSep17'08at1:09

PeterMortensen
10.2k

13

69

dimarzionist
107

7,233

14

20

Everymicrocontrollerisdifferent.TheBASICstampisverypopularamonghobbyists,because
youcanprogramitinahighlevellanguage.
Forlowerlevelwork,oneextremelycommonchoiceisthePIC,acheap(<$4)andfast
(~20MHz)chipwithalmostnoonboardmemory.Youcanfindalistofdevelopmentenvironments
onWikipedia.
Ifyouneedtobuyelectroniccomponentstogowithyourmicrocontroller,DigiKey isanexcellent
placetostart.
editedJun11'12at18:58

answeredSep17'08at1:04

PeterMortensen
10.2k

13

69

emk
107

39.3k

28

44

Ihavetwosuggestions.
1.Stampmicrocontrollersaregreatintroductorychips.YoucanpickupthekitsoneBaycheap
(<$30typically).IcanalsorecommendtheStamp2CommunicationsandControlProjects
bookbyTomPetruzzellishttp://www.amazon.com/STAMP2CommunicationsControl
Projects/dp/0071411976/ref=sr_11_1?ie=UTF8&qid=1221613350&sr=111
2.Microchip(www.microship.com)makestheStampmicrocontroller.Theyalsoofferfree
samplesfromtheirwebsiteincludingshipping.Ipickedupacouplemicroswithbuiltin
radiostodosometwowayRFcommunications(notWIFI).Anothergreatmicrocontroller
manufacturerisDallasSemiconductorhttp://www.maximic.com/andtheyalsoshipoutfree
samplestoo.Dallas/MaximalsohasanEngineeringJournalthattheywillmailfreetoyour
addressandthejournalhastonsofsampleimplementations,usingtheirchipsofcourse,
fromwhichyoucangroklotsofgoodinformationfromaswell.
answeredSep17'08at1:08

Eric
869

20

34

Thisbookhaveaterribleratingonamazon:P PatrickDesjardins Sep17'08at12:30

CheckoutPhysicalComputingbyDanO'Sullivan:http://itp.nyu.edu/~dbo3/physical/physical.html
HealsohaslinkstoBasicStamp,BX24,BasicAtom,andPIC"QuickReferences".
Arduinoisagreatplatformwithalarge,supportivecommunity.Irecommendit.
answeredSep17'08at2:22

msutherl
353

17

AnothervotefortheArduinowhichisverycool.WithanArduinoboard,aonewiretemperature
sensorandHyperterminal,youcanstarttorecorddataabouttheworldaroundyou.Hookup
Processingandyoucanlogthedata,graphit,analyseitinExcel,whatever.Neat.
answeredJul10'09at7:43

jford
142

Ifyou'reabitelectronicsenthusiast,youcouldbuildyouowndevelopmentsystem.Itcouldbe
morecomplicatedbutit'salotmorefun.
SeehereasimpledevelopmentsystemforPIC16F628Amicroncontrollers,includingfull
schematicsandPCB:http://www.bobtech.ro/proiecte/microcontrolere/1bobdemosistempentru
dezvoltareaplicatiicumicrocontroler
Features:
12I/OwithpushbuttonsforinputsandLEDsforoutputs
RS232serialportinterfaceforPC
infraredremotecontrolsensor
onboardICSPprogrammingconnector

http://stackoverflow.com/questions/78744/howtostartprogrammingamicrocontroller

4/5

11/09/2016

cHowtostartprogrammingamicrocontroller?StackOverflow

optionalonboard9Vbattery(fordemopurposes)
onboard+5Vpowersupplyformicrocontrollerandexternalperipherals
Forprogramming,youcanuseBobProgICSPPICprogrammer
FollowthelinkforprogrammerschematicsandPCB.
Software:
(free)MPLABIDEfromMicrochipfordevelopmentinCorASMlanguage
(free)ICProgflashprogrammingsoftwaretousefortheICSPprogrammer
answeredOct12'11at19:32

BobTech
11

Onasidenote:
Ifyoudon'twanttogetyourhandsdirtysolderingalotofstufforarenotelectricallyinclinedtodo
so(likeme),trylookingintoPLC's .
TheyareindustrialhardwarecontrollerswithmodulesforalmosteverytasksuchasdigitalI/O's,
analogI/O's,steppermotorcontrollers,serialI/O,Ethernet,etc.Youcanprogramthemin
differentways,assemblerlike,graphicalandatexteditorwithcodelookinglikeamixofPascal
andBasic.Theyhavebuiltinmultitaskingandusuallyperformprettywell,buttheyareabitmore
expensivethanaregularmicrocontroller.IalwaysrecommendWagoandtheir750841controller.
editedNov18'10at23:25

answeredApr15'09at6:50

PeterMortensen
10.2k

13

69

NiklasWinde
107

979

http://stackoverflow.com/questions/78744/howtostartprogrammingamicrocontroller

15

33

5/5