Post on 06-Apr-2018
8/2/2019 Senzor iz mike
1/16
ReportTechnologyMasterclassMartijnJansen
AnOpticalMouseSensoras
anextensionforLEGONXT
MartijnJansen
m.e.p.jansen@student.tue.nl
S030887
8/2/2019 Senzor iz mike
2/16
Index:
1.Introduction
2.SensorChoice
3.Hackingtheopticalmouse
4.HackingLEGONXT
5.Implementation
6.PossibleApplications
7.References
8.Appendix
8/2/2019 Senzor iz mike
3/16
1.Introduction
AssignmentDescription
ThisprojectispartoftheTechnologyMasterclassofIndustrialDesignattheTechnicalUniversity
Eindhoven.Duringthisclass,Masterstudentsgettheopportunitytodiveintosomeverydiverseelementsoftechnologylikeelectronics,mechanics,programmingintelligentrobotsandcreatinga
newinnovativesensorforLEGONXT.Thisreportdescribestheelaborationofthelatterassignment.
Deliverables
workingmodeloftheextensionpack reportinMSWorddescribingtheextensionpack technicaldocumentationoftheextensionpack,suchastechnicaldrawingsandUMLmodels photosoftheextensionpack movieoftheextensionpackinactionuploadedinhighqualitytoSurfMediaandavailablefor
downloadfromthere.
8/2/2019 Senzor iz mike
4/16
2.SensorChoice
Forarobotthatisabletomoveitself,itisessentialtoknowinwhatenvironmentitisandwherein
thatenvironmentitislocated.Location,distanceandspeedarevariablesthatcanhelparobotdetermineitscurrentstate.AGPSsensorisabletogivethesevariables,butarequiteexpensiveand
notasaccurateasyoumightneed.Acomputermouseismoreaccurateandcandetectmovement
smallerthanamillimeter.ForthisreasonIdecidedtolookatcomputermiceasanewsensorfor
LEGONXT.
Anoldcomputermouse(fig.1)detectsmovementmechanicallythroughaballinsidethatcanrotate
inanydirection.Therearethreewheelsinsidethatarepositionedagainsttheball,sothatthewheels
areturningwhentheballrolls.Thesewheelschoplightbeamsinfrontoflightsensorssoa
movement,speedofmovementanddirectioncanbedetected.Thiskindofmouseisalsocalledaball
mouse.
Fig.1:Aballmouse
1
Adifferentkindofcomputermouseistheopticalmouse(fig.2).Theopticalmousehasa
sensorinsidethatisactuallyaverysmallcamera.Itdetectschangesinpicturesofthesurface
underneathit.ThisisthenconvertedtoanamountofmovementintotheXorYdirection.AredLED
illuminatesthesurfacetoincreasethecontrastofthepictures.
fig.2:Myopticalmouse(beforethisproject)
Ichosetogofurtherwiththeopticalmousesensorforthefollowingreasons:
ithasnomechanicalpartsthatcanbreakorwearoff; itcanbeusedonmoresurfacesthantheballmouse; aballmousecollectsdebrisinsidethecasing itsquitesmall(smallerthantheballmouse); itscheap; Iseealotoflearningopportunitieshere.
ThefollowingchapterswilldescribehowtocreateanopticalmousesensorfortheNXTfromacheapopticalmouse.
8/2/2019 Senzor iz mike
5/16
3.Hackingtheopticalmouse
IhaveusedsometutorialsIfoundoninternet2,3.Myapproachwasquitesimilar,buteventuallyIneed
toreadthedatawiththeLEGONXT.Myfirststepistohackthemousereadthedatafromthesensor
withArduino4.
TutorialforhackingtheopticalmouseThistutorialwillexplainwhatstepsyouneedtotaketohacktheopticalmouseandreadthedata
withArduino.Firsttakeanoldopticalmouseorbuyacheapone.Fig.2showshowmymouselooked
like.
1.Openupthemouse
Underneaththemousetheresascrewyouneedtounbolt.Thiswillopenupthemouse.Hereyou
findthecircuitboardwiththesensor(thechipinthemiddle),aLED,buttonsandthescrollwheel(fig.
3).Underneaththecircuitboardisthelensclip(fig.4),thatisusedtoamplifythelightandfunctions
asalensforthesensor.
fig.3:Mouseopenedup
fig.4:lensclip
2.Lookupthedatasheet
Thesensorislocatedinthemiddleofthecircuitboard.Searchforthedatasheetofthesensoronthe
internetandlookupthepinconnections.Youneedthefollowingpins:
+5V(inputvoltage) GND(ground) SCK(serialportclock) SDIO(serialportdata)
InthecaseofmysensorIneedpin3,4,6and7(fig.5)
8/2/2019 Senzor iz mike
6/16
fig.5mechanicaldrawing+pinouttableofthedatasheet
5
MakesurethatyoursensordoesnthavetheUSBcontrollerembeddedinsidethechip.Thefirst
mouseItriedtoopenhadthiskindofchip(seefig.6),whichmeansthatyoucantcapturethedata
withoutaUSBprotocol.Usinga2wireserialportcommunicationismuchmorepreferable.
fig.6:amousewiththeUSBcontrollerembeddedinthechipofthesensor
3.SolderwiresSolderwirestothe4neededpins.Itsusefultochoosedifferentcolors,soyoureabletodistinguish
theclockanddatalineseasily(fig.7).
fig.7Wiressolderedtopins3,4,6and7
4.RemovetheUSBcontroller
Thisstepisnotnecessary,butifyourenotgoingtousethemouseanymoreitmightbebetterto
removetheUSBcontrollertopreventthecontrolleroftakingoverthedataconnection.Removing
thecontrollercanbedonebyremovingthesolderedtinandscrapethecontrollerofthecircuitboard.
5.ConnectittoArduino
ChoosetwodigitalpinsontheArduinofortheclocklineandthedatalineandconnectthe+5Vand
GNDofthemousetothe5VandGndofArduino.Uploadthesketches(programsforArduino)
providedbyMartijnThbasedonsketchesofBenotRousseau.MakesurethattherightregistersIf
youopentheSerialmonitorintheArduinosoftwareyoullseethexandyvalues.Inthenext
paragraphIllexplainhowthisworks.
8/2/2019 Senzor iz mike
7/16
GetthedatafromtheopticalmousetoArduino
Inthedatasheetofthesensorthereisawholesectionaboutthesynchronousserialport.Thisportis
usedtosetandreadparametersfromthesensor.Theportusestwowiresandisahalfduplexport,
whichmeansthatitcantalkbothways,butnotatthesametime.Themicrocontroller,inmycasethe
Arduino,alwaysinitiatescommunicationandiscalledthemaster(thesensoristheslave).Thetwo
wiresaretheserialportclock(SCK)andthedataline(SDIO).Theserialportclockisgeneratedbythe
microcontroller.
ThemicrocontrollercantrytoreadparametersliketheXandYmovement,butcanalsowritetothe
sensortochangeparameterslikeforexampletheconfigurationofthesensor.Forthisweneedaread
andawriteoperation.Theclocklineisgeneratedbythemicrocontrollerandispreferablypulsingata
lengthof250nsperpulse.Thefunctionoftheclockistosynchronizedatatransfers.
Writeoperation
Awriteoperationisinitiatedbythemicrocontrollerandconsistsoftwobytes.Thefirstbytecontains
a7bitaddressandhasa1asitsmostsignificantbit(MSB).This1meansthatthemicrocontroller
wantstowritedataandtheaddressisaregisterwhereyouwanttowriteto.Thesecondbytecontainsthedatayouwanttowrite.Theclocksynchronizesthedatatransfer,becausethe
microcontrollerchangesSDIOonfallingedgesoftheclockandthesensorreadsSDIOonrisingedges
oftheclock.
fig.8:Writeoperation
ReadOperation
Awriteoperationworkskindofthesame;italsoconsistsoftwobytes.Thefirstbytehasa0asMSB
(toindicateareadoperation)andasevenbitaddresstorequestthedatafromacertainregister.The
secondbyteisthedatasendfromthesensortothemicrocontroller.Afterthelastbitoftheaddress
thereisadelayof100usforthesensortopreparethedata.
fig.9:ReadOperation
Registers
Inthedatasheetthereisalistofaddresses(fig.10).Fromaddress0x42and0x43youcangetthe
Delta_YandDelta_X(XandYmovement).Letmegiveanexample:IfIwanttoreadtheYmovement
Ihavetoperformareadoperation.Thefirstbytethemicrocontrollersendsis0x42,butwitha0as
MSBbit.Inbitformthislookslikethis:01000010.Thenthereisadelayof100microsecondsand
afterthatthesensorwillgiveabytecontainingthemovementofthesensorintheYdirection.
8/2/2019 Senzor iz mike
8/16
fig.10:AddressesoftheregistersoftheADNS2083
InthenextchapterIllexplainhowtogetthisdatatotheLEGONXT.
8/2/2019 Senzor iz mike
9/16
4.HackingLEGONXT
TheNXTisactuallyamicrocontrollerlikeArduino.ForthisassignmentweneedtoprogramtheNXT
withleJOS,aJAVAbasedlanguagefortheNXT.Icouldntfigureouthowtoreadthesensordirectly
withtheNXTusingleJOS.ThereforeIchosetotoreaddatafromthesensorwithArduinoandletthe
NXTcommunicatewiththeArduino.
LEGONXTcables:ThecablesoftheNXTareactuallyslightlymodifiedJR12cables(telephonecables).Themodification
liesintheconnector.Insidethecableare6wiresthatconnecttoaninputportoftheNXT(fig.12).
fig.12:InputportoftheNXT
6
CommunicationbetweenLegoNXTandArduinothroughI2C:
I2CisaprotocoldevelopedbyPhilips.Theprotocolofreadingtheopticalmousesensorisquitesimilar
tothis,butnotentirely.Inthecaseoftheopticalmousesensor,thereisnodeviceaddress.Youneed
thistostartupthewholecommunication.ForthisreasonIcouldntreadthesensordirectlyfromthe
NXT.
Inmyproject,theArduinoistheslaveandtheNXTisthemaster.InArduinotheresalibrarycalled
Wire.hthatcanbeusedforI2C.Withthislibraryyoucansetthedeviceaddress,Iusedthenumber
127.WhenevertheNXTrequestsdata,Iusethislibrarytosendanarrayoftwobytes;thexandy
value.
InleJOSIrequestdatabyusingtheI2CSensorclass.Icreatedaclassfortheopticalmousesensorthat
extendstheI2CSensorclass.NowIcanmakeseveralobjectsofthisclass,whichcanbeusefulwhenI
wanttousemorethanoneofthesesensorsatthesametime.AftertheNXThasinitializedcommunicationwithdeviceaddress127,itcanrequestdata.Afterthis
requestIgetaresponseoftwobytes,whichIstoreinanarraywithtwoindexes.Thefirstindexof
thearrayisthexvalueandthesecondistheyvalue.
8/2/2019 Senzor iz mike
10/16
5.Implementation
Thischapterdescribestheimplementationintoaworkingprototype.
CircuitblockdiagramThecircuitblockdiagram(fig.13)islargelybasedonthecircuitblockdiagramoftheADNS2083.By
removingtheunnecessarypartsliketheUSBcontrollerandthebuttonsyoullhaveablockdiagramof
thesensorwiththeLED.Connectthefourpins(+5V,GND,SCKandSDIO)ofthesensortotheright
pinsontheArduinoboard.ConnecttheI2CpinsoftheArduinoboard(SCK=ANALOG5,SDIO=
ANALOG4)totheNXTcable.Theotherendofthecablecanbeinsertedintoanysensorportofthe
NXT,exceptsensorport4(isnotcapableofI2C).Iusedsensorport1.
Fig.13:CircuitblockdiagramforreadingthesensorinNXT(rotateyourpage)
8/2/2019 Senzor iz mike
11/16
MechanicalDrawingIwantedtomakeasensorhasalmostthesameformastheexistingNXTsensors.Thefirstdrawings
(fig.14)giveagoodimpressionofthedimensionsoftheouterbody.
fig.14:Firstimpressionofthedimensions
AfterImadethisIstartedtocreatea3Dmodelfor3Dprinting.Thethicknessofthematerialis2mm.
Insidethecasingadifferentconstructionwasneeded.Thecircuitboardhadtobeexactly7.45mm
abovethesurface(fig.15).ThemouseIhackedusedadifferentlensclipthanthedatasheet
recommended.InmydesignIneededtofixthelensclipbymakingaraisedrectangleandcutouta
passageforthelighttogothroughandapassageforthelenstomakepictures(justlikeinsidethe
casingofthemouse,fig.16).Theimplementationisshowninfig.17andtheeventualmodelinfig.18.
fig.15:Assemblydrawingofcircuitboardinsideview
8/2/2019 Senzor iz mike
12/16
fig.16:Lensclipholderinthemousecasing
fig.17:Twoscreenshotsofthe3DCADmodelmadeinSolidWorks
fig.18:Theprototype3Dprintedwiththetechnologyinside
8/2/2019 Senzor iz mike
13/16
NextstepsIvetriedoutthesensorondifferentsurfacesanditworksverywellonwhiteorbrightsurfaces.On
darkorblacksurfacesithasmoretroubletoswitchon.Thereisasettingofthemousesensorthat
switchestheLEDtolessbrightwhenitisntmovedformorethanasecond.Whenthesensordetects
movement,theLEDwillgetbrighteragain.Thisisasettingtosaveenergy.Theproblemondark
surfacesisthatthesensordoesntdetectthefirstmovementverywell,sotheLEDwillnotemitatfull
power.Incaseofemittingwithfullpowerthesensorworksfineagain.Iwouldrecommendwhenthe
sensorisusedondarksurfacestochangetheconfigurationofthesensorandlettheLEDalwayson
withfullpower.
Therearealsosomeminorimprovementsthatcanbemadetothedesignofthecasing.Thelensclip
onlyfitswhenitisputinwithalotofforce.Tryingalitbiggermarginwouldbebetter.
Asmallercircuitboardcanbedesignedwiththetechnicaldrawingprovidedinthisreport.Thismeans
thatthesensorwoulddecreaseinsizeandmightevendecreaseitsbroadthtwice.
8/2/2019 Senzor iz mike
14/16
6.PossibleApplications
SomeexamplesofapplicationsusingtheNXTopticalmousesensorare:
Measuremovement
Arobotcanmeasurehowfarithasdrivenyet.
Measurevelocity
Forrobotsthathavetogowithacertainspeedyoucandividethemovementwiththetimeandyou
getvelocity
Feedbackloopfordrivingstraight
BecausethesensormeasuresXandYvaluesitcanalsogivefeedbackaboutmovementsideways.This
isunwantedforexamplebecauseonmotorisstrongerthantheother.Becauseyoudetectthe
movementsidewaysyoucanfeedthisinformationbacktothemotors(justlikethepotentiometerin
aservomotor).
DrivingtocoordinatesArobotcandrivetoanexactpointintheenvironment,whenitkeepstrackofthemovementsofar
andthebendsithasmade.
8/2/2019 Senzor iz mike
15/16
7.References
1. Picturefrom:http://upload.wikimedia.org/wikipedia/commons/2/2c/Ball_Mouse_semiinside_view.jpg
2. http://www.gurulib.com/_project/optical_mouse_hack_files/optical_mouse_hack.htm3. http://www.martijnthe.nl/optimouse/4. http://www.arduino.cc/5. DatasheetADNS2083(SDNS2083)fromAvagotechnologies6. LegoMindstormsNXTHardwareDelopmentKit
8/2/2019 Senzor iz mike
16/16
8.Appendix
A.DatasheetADNS2083
B.LegoMindstormsNXTHardwareDelopmentKit
C.ArduinoSketch
D.leJOSclasses
E.Videooftheworkingprototype
BecauseAppendixC&Dcontaintoomanypagestoprintandaremoreusefulto
havedigital,Ihavemadethemavailableonline.AppendixEisavideoandcanbe
downloaded.
C.http://www.kansloosdesign.nl/portfolio/wp
content/uploads/2008/12/coordinates_in_mm_i2c.zip
D.http://www.kansloosdesign.nl/portfolio/wp
content/uploads/2008/12/lejosopticalmousesensor.zip
E.http://www.kansloosdesign.nl/portfolio/wp
content/uploads/2008/12/filmpje.m4v