Vous êtes sur la page 1sur 8

ControllingaDotMatrixLEDDisplay withaMicrocontroller

ByMattStabile UniversityofCaliforniaSantaBarbara MediaArtsandTechnology MAT200CWinter2008 Abstract Atutorialonthebasicsofchoosingand settingupamicrocontrollertocontrolan LEDmatrixisprovided.Fundamentalsof LEDmatricesandmicrocontrollersarefirst covered,followedbytipsonmakingthe necessaryinterconnectionsbetweenthe two.Relevantsoftwarefordevelopmentis surveyedandfinallysomeexamplecodeis providedfortestingtheLEDmatrix. Introduction Thispaperwillprovideacomprehensive tutorialonhowtodriveandcontroladot matrixLightEmittingDiode(LED)display withamicrocontroller.Thedisplayusedisa commerciallyavailablePCBmount8x8dot matrixRGBLEDdisplay,withatotalof192 individualLEDsthatarecontrolledby32 controlsignals.Themicrocontrollerusedis anAtmelATMega128;however,thecontrol

andprogrammingwillbeexplainedin generaltermsaswelltoallowfor adaptationtoanycomparable microcontrollerorLEDmatrix.

Figure1:8x8DotMatrixLEDDisplay TheDotMatrixLEDDisplay AnLEDMatrixconsistsofanarrayofLEDs whichareinterconnectedsuchthatthe positiveterminal(anode)ofeachLEDinthe samecolumnareconnectedtogetherand thenegativeterminal(cathode)ofeachLED inthesamerowareconnectedtogether. Notethatthiscouldbetheotherway aroundaswell,withthepositiveterminals connectedtotherowsandthenegative terminalsconnectedtothecolumns.Figure 2showsaschematicforatypical8x8 matrixwithsinglecolorLEDs.

ineachrowandcolumn,itisnotpossibleto controleachindividualLEDatthesame time.Instead,thematrixiscontrolledby cyclingthrougheachrowveryquicklywhile triggeringthecorrectcolumnpinstolight thedesiredLEDsforthatparticularrow.If theswitchingisdoneataquickenough rate,therewillbenovisibleflickerandthe Figure2:8x8LEDMatrixSchematic AnLEDdotmatrixdisplay(dotrefersto thecircularlensesinfrontoftheLEDs)can alsocomewithmultipleLEDsofvarying colorsbehindeachdotinthematrix.For example,thematrixusedinthisprojecthas aRed,GreenandBlueLEDbehindeachdot inthe8x8grid.Aconfigurationwith multipleLEDsbehindeachdotaddsanother controlpintoeverycolumn(positive terminal)foreachadditionalcolorofLED, whiletherows(negativeterminals)arestill allconnectedtogether.ThereforeanRGB matrixhas32controlpinscomparedtothe 16pinsseeninFigure2. Whenchoosingamicrocontrollerthatwill ControllingtheLEDMatrix SincealloftheindividualLEDsinamatrix sharetheirnegativeandpositiveterminals meettherequirementsnecessaryfor controllinganLEDmatrix,thespecifications thatmustbemetarethoseofthenumber LEDmatrixdisplaywillappeartohaveeach LEDturnedonatthesametime.Thisworks becauseoftheprincipleknownas PersistenceofVision,whichisthetheory thattheretinaofthehumaneyeretainsan imageforaboutatenthofasecond.Thus anLEDmatrixmustbeveryprecisely controlled,withtheRowsbeingscanned throughsequentiallyatarategreaterthan about40Hz(tobesafe)whilesendingout thecolumndataattheexactsamerate. Thiskindofcontrolismosteasily accomplishedwiththeaidofa microcontroller,plussomeadditional components. Choosingamicrocontroller

ofI/Opinsavailable,theamountofcurrent thateachpincansourceandsinkandthe speedatwhichthemicrocontrollercan sendoutcontrolsignals.Anotheroption thatonemightdesireisthatofanonboard AnalogtoDigitalConverterforsamplingan inputsignal(suchasanaudiowaveform) whichcantheninfluencethecontrolsignals beingsenttotheLEDs. Moderndaymicrocontroller technologyhasmadetheissueofcontrol signalspeedandavailableI/Opinsalmost trivialforthisapplication.Almosteverychip onthemarketnowhasupwardsof32I/O pinsavailableandalmostalloperateat speedsgreaterthan10MHz,whichallows forcontrolsignalstobesentatratesmuch greaterthanthe40Hzthatisrequiredto satisfythePersistenceofVisionprinciple. Forexample,themicroprocessorthatI choseranatanoperatingspeedof16MHz andintheloopofcodethatcycledthrough therowsIwasstillabletoputa2msdelay betweeneachiteration,meaningthatthere wasaguaranteed16msofdelayinmycode (excludingtheactualcodeexecutiontime) andstillnovisibleflickeronthematrix display.Upuntilrecentyears,18decoder chips(whichallowthe8rowspinstobe

controlledbyjust3I/Opins)werealmost alwaysusedtominimizethenumberofI/O pinsrequiredonthemicrocontroller; however,withthelargeamountofI/Opins availableonalmostallmicrosnow,these chipsseemlikeanunnecessary complicationtothedesign. Thefinalspecificationthatmustbe metisthatofcurrentconsumption, meaningthattheamountofcurrentthat eachI/Opincansourceandsinkisgreater thantheamountofcurrentneededto illuminatearowofLEDs.Thesenumbers mustbedeterminedfromthespecifications sheetoftheLEDmatrixinconjunctionwith themicrocontrollersmaximumcurrent values.Thisspecificationisalsoeasilymet inmostsituationsthough,duetothewayin whichweareswitchingtheLEDsoffandon insucharapidmanner.Whenatypical currentspecificationisgivenontheLED matrixdatasheet(usuallyaround20mAper LED),thespecisforsteadystate consumption(continuouslyon).Sincethe LEDsarebeingswitchedonandoffso quickly,ourcurrentconsumptionisactually muchlowerduetothecurrentdraws continuouslytransientstate.WiththeLEDs fullyswitching,Iobservedtheretobeonly

aboutathirdofthecurrentbeingdrawnas comparedtotheLEDsconsumptionata steadystate.Tobesafe,aDarlington transistorarrayisalmostalwaysusedin betweenthecathodesoftheLEDsandthe microcontrollerI/OPins.TheDarlington transistorarrayisanICthatisanarrayof8


grounded NPN transistors which serve as a current sink, enabling more current to be drawn through the LEDs safely. The array has a dual purpose in that it also inverts the signal on the pins, so when we send a positive control signal, it is actually completing the Ground connection as is needed to turn on the LEDs. Bias resistors must also be calculated and inserted in between each I/O pin on the microcontroller and the anode pins on the LED matrix. Bias resistors are calculated by referring to the Electrical Characteristics table on the LED matrixs data sheet. Each differently colored LED has a voltage that it prefers to be biased at for correct operation, somewhere usually between 2 5 Volts. The voltage on the I/O pins of most microcontrollers is a standard 5 Volts, so using Ohms law with the desired voltage and current specs will yield a correct bias resistor value for each column of LEDs.

Puttingitalltogether Withallofthespecificationsmet,now comesthefunpartofwiringthewhole matrixup.Thisinvolvesfabricatingmany cablesastheRGBmatrixrequires32control signals,whichfirsthavetogofromthe microcontrollertoaboardwiththebias resistorsandDarlingtontransistorarray, andthenfromtheretothe32pinsonthe backofthematrix.

Figure3:BlockDiagramofConnections

TheAtmelmicrocontrollerusedinthis projecthasitsI/OpinsgroupedinPorts with8I/OpinseachplusaVccpinand Groundpin.ThusIchosetoassignoneport forcontrollingtheswitchingofthe8row pins,oneportforthe8RedColumnpins, oneforthe8Greenpinsandoneforthe8 Bluepins.Thisseparationofcolors,rows, andcolumnsalsomakestheprogramming

moresimpleandintuitive.Themosttime consumingpartofwiringupthematrixis mappingthepinsfromthemicrocontroller portstothePCBmountpinsonthebackof thematrix.Thisturnsouttobequite complexbecausethe32pinsonthematrix areinaseeminglycompletelyrandomorder andmustbecorrectlyassignedtopins07 oneachportofthemicrocontroller.Table1 providesthepinmappingswiththematrix pinnumbersinboldandthecorresponding microcontrollerportletterandnumber directlybelow. 1 A0 9 B5 17 E7 25 B1 2 F0 10 B4 18 A7 26 B0 3 E1 11 A4 19 F6 27 F3 4 A2 12 E4 20 E5 28 A3 5 F2 13 F5 21 A5 29 E2 6 E3 14 A6 22 F4 30 F1 7 B7 15 E6 23 B3 31 A1 8 B6 16 F7 24 B2 32 E0

correctlymakingalloftheconnections,we arethenreadytowriteatestprogramand begintestingtheboard. ProgrammingtheMicrocontroller TheAtmelATMEGA128canbeprogrammed usingBASIC,C,orAssemblylanguage.After thecodeiswritten,itiscompiledusingthe WinAVRcompilerwhichoutputsaHexfile thatcanthenbedirectlydownloadedtothe microcontroller.TheHexfileisdownloaded viaanInCircuitProgrammerthatconnects themicrocontrollertotheparallelportofa PC.

Figure4:InCircuitprogramdownloadtool

Table1:MatrixPinNumbersinBold,corresponding microcontrollerPortLetterandnumberdirectlybelow.

TheHexfilemustbedownloadedthrough useofspecialSerialDeviceProgramming softwaresuchasthefreewareprogram PonyProg2000.TheAtmelevaluationboard Ipurchasedfromfuturlec.comcamewith extremelyeasytofollowtutorialsand exampleprogramsthatshowedstepby stephowtocompileanddownloadthefiles

Thesecanbeusedinconjunctionwiththe matrixdatasheetinformation(linkstothis foundintheReferencessection),which showsthepinorientationontheactual matrixandwhichpinscorrespondtowhich LEDsineachrowandcolumn.After

tothemicrocontroller.Anyseriesof microcontrollersnodoubtcomeswith extensivedocumentsonsettingupand programmingoneforthefirsttime,soIwill notintofurtherdetailofthoseprocesses. ThereareavarietyofIDEsavailable

LEDinthearray.Figure5showsanexample programthatdemonstrateshowtoturnon everyLEDinthematrix,changingwhich colorLEDsarelitatevenintervals.Notethe infinitewhileloop,sincewejustwantthe microcontrollertorunthisroutineforas longasitispoweredup.Thissectionof codewouldappearinthemain()ofyourC sourcefile.Theonlyothercodethatwould benecessarywouldbethe#include librariesforyourspecificmicrocontroller andwhateverlinesofinitializationmaybe requireddependingontheapplication.The codeisextrememlysimple,withthemain forloopsimplyiteratingdowntherowsof thematrixwhilesimultaneouslyupdating thecolumndataonthePortsofthe microcontroller.Thedelayinbetweeneach rowmustbecalibrateddependingonthe speedofthemicrocontrollerbeingused. Thetargetvalueistousethelongestdelay possiblewithoutbeingabletoseeany flickeringoftheLEDs.Thedelayisdesired toensurethattheLEDsaregettingenough currenteachtimetoachievefullbrightness. Thecountervariableoutsideoftheforloop allowsstatestochangeaccordingtothe lengthofthedurationvariable.

fordevelopingmicrocontrollerprograms dependingonthelanguagethatisdesired andthechiparchitecturebeingused.For AtmelsAVRfamilyofchips,Atmelprovides afreeAssemblyLanguageIDEcalledAVR Studio4whichcanbedownloadedfrom www.atmel.com.Forprogrammingin BASIC,ademoversionofBASCOMAVRis availablefromMCSElectronicsat www.mcselec.com.Thedemoversions onlylimitationisthatofa4kBmaximum sourcecodefilesize.ForprogramminginC thereisCodeVisionAVR,availableinademo versionwitha2kBfilesizelimitationat www.codevision.be.AgoodfreeC/C++IDE iscalledCode::Blocksandisavailableat www.codeblocks.org.Code::Blocksalready haspreconfiguredsettingsforusingthe WinAVRcompiler,soitisaverygoodchoice forafree,fullyfunctionalIDE. Thefirstprogramusedtotestthe

setupshouldbeverysimpleandtestevery


Figure5:ExampleControlPrograminC

programmingtheLEDmatrixtodisplay interestingpatterns.Agoodexpansionisto captureaninputsignalusinganADCand thenmodifythedisplaybasedontheinput signalinformation.Withadigitizedinput signal,theFFTcouldthenbetakenandDSP algorithmscouldbeusedtomapthedata totheLEDmatrixininterestingways.

Conclusion Asisapparent,therearemanydifferent optionswhenitcomestochoosinga microcontrollerandLEDmatrixtowork with.ItiseasiesttochooseanLEDmatrix firstandthentoselectamicrocontroller thatmeetsthedemandsoftheLEDstobe controlled.Oncethebasicsetupis complete,therealchallengeliesin

OnLineReferences Arduinowww.arduino.cc Opensourcemicrocontrollerprojectbased onAtmelAVRfamilyofchips Atmelwww.atmel.com ManufactureroftheAVRseriesof microcontrollers BestMicrocontrollerProjects www.bestmicrocontrollerprojects.com ManyexampleprojectswithPICmicros Code::Blockswww.codeblocks.org FreeC++IDEwithbuiltinsupportformany differentcompilers Futurlecwww.futurlec.com Sellsmicrocontrollerevaluationboardsand starterkits,aswellasLEDmatrices Microchipwww.microchip.com ManufacturerofPICfamilyof microprocessors Parallaxwww.parallax.com Sellsmicrocontrollerstarterandadvanced kits SparkFunElectronicswww.sparkfun.com SellsmicrocontrollersandLEDmatrices TheLEDLightwww.theledlight.com SellsalltypesofLEDs,hasgoodbeginner tutorialsonsettingupLEDs.

RGBLEDDotMatrixDisplay www.foryard.com
FYM-23881ABxxx ManufacturedbyForyard

Optoelectronics DataSheet http://www.sparkfun.com/datasheets/Com ponents/FYM23881ABxxx.pdf

Vous aimerez peut-être aussi