├── .gitattributes ├── .gitignore ├── ADNS2051.cpp ├── ADNS2051.h ├── ADNS2083.cpp ├── ADNS2083.h ├── ADNS2610.cpp ├── ADNS2610.h ├── ADNS2620.cpp ├── ADNS2620.h ├── OptiMouse.cpp ├── OptiMouse.h ├── PAN3101.cpp ├── PAN3101.h ├── README.md ├── examples ├── Coordinates │ └── Coordinates.ino └── Speed │ └── Speed.ino └── keywords.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /ADNS2051.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2051.cpp -------------------------------------------------------------------------------- /ADNS2051.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2051.h -------------------------------------------------------------------------------- /ADNS2083.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2083.cpp -------------------------------------------------------------------------------- /ADNS2083.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2083.h -------------------------------------------------------------------------------- /ADNS2610.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2610.cpp -------------------------------------------------------------------------------- /ADNS2610.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2610.h -------------------------------------------------------------------------------- /ADNS2620.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2620.cpp -------------------------------------------------------------------------------- /ADNS2620.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/ADNS2620.h -------------------------------------------------------------------------------- /OptiMouse.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/OptiMouse.cpp -------------------------------------------------------------------------------- /OptiMouse.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/OptiMouse.h -------------------------------------------------------------------------------- /PAN3101.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/PAN3101.cpp -------------------------------------------------------------------------------- /PAN3101.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zapmaker/OptiMouse/8eeb46819612ed6dca9143b4eff0cc7db8781020/PAN3101.h -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OptiMouse 2 | 3 | Original code by Martijn The 4 | Modified by zapmaker to (a) run on Arduino 1.x and (b) support 2620 sensor 5 | 6 | Hack an older or cheaper optical mouse to read data from it. 7 | Note: Newer optical mice have complex chips that cannot be read by this library. 8 | Look at the libraries and search on the web to find mice that have these sensors. -------------------------------------------------------------------------------- /examples/Coordinates/Coordinates.ino: -------------------------------------------------------------------------------- 1 | // This example reads out the PixArt PAN3101 Optical Navigation Sensor 2 | // It's used in many cheap optical mouses. 3 | // 4 | // For support for the Agilent ADNS-2051, ADNS-2083 or ADNS-2610, move 5 | // the files for your mouse to the folder with the OptiMouse files. 6 | // Then uncomment the right header files and object instances below. 7 | // 8 | // The Arduino will keep track of a (x, y) coordinate by increasing 9 | // or decreasing the x and y variables by dx and respectively dy. 10 | // Every 128th sample it reports the current (x, y) over the Serial. 11 | // 12 | // Written by Martijn The -> post [at] martijnthe.nl 13 | // Tutorial: http://www.martijnthe.nl/optimouse/ 14 | // Based on the sketches by Beno”t Rousseau 15 | 16 | #include "PAN3101.h" 17 | // #include "ADNS2051.h" 18 | // #include "ADNS2610.h" 19 | // #include "ADNS2620.h" 20 | // #include "ADNS2083.h" 21 | 22 | #define SCLK 2 // Serial clock pin on the Arduino 23 | #define SDIO 3 // Serial data (I/O) pin on the Arduino 24 | 25 | PAN3101 Optical1 = PAN3101(SCLK, SDIO); // Create an instance of the PAN3101 object 26 | // ADNS2051 Optical1 = ADNS2051(SCLK, SDIO); 27 | // ADNS2610 Optical1 = ADNS2610(SCLK, SDIO); 28 | // ADNS2620 Optical1 = ADNS2620(SCLK, SDIO); 29 | // ADNS2083 Optical1 = ADNS2083(SCLK, SDIO); 30 | 31 | signed long x = 0; // Variables for our 'cursor' 32 | signed long y = 0; // 33 | 34 | int c = 0; // Counter variable for coordinate reporting 35 | 36 | void setup() 37 | { 38 | Serial.begin(38400); 39 | Optical1.begin(); // Resync (not really necessary?) 40 | } 41 | 42 | void loop() 43 | { 44 | 45 | // The status commands are available only for the PAN3101 and the ADNS2051: 46 | 47 | // Optical1.updateStatus(); // Get the latest motion status 48 | // if (Optical1.motion()) // If the 'Motion' status bit is set, 49 | // { 50 | 51 | x += Optical1.dx(); // Read the dX register and in/decrease X with that value 52 | y += Optical1.dy(); // Same thing for dY register..... 53 | 54 | // } 55 | 56 | if (c++ & 0x80) 57 | { // Report the coordinates once in a while... 58 | Serial.print("x="); 59 | Serial.print(x, DEC); 60 | Serial.print(" y="); 61 | Serial.print(y, DEC); 62 | Serial.println(); 63 | c = 0; // Reset the report counter 64 | } 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /examples/Speed/Speed.ino: -------------------------------------------------------------------------------- 1 | // This example reads out the PAN3101 Optical Navigation Sensor 2 | // It's used in many cheap optical mouses. 3 | // 4 | // For support for the Agilent ADNS-2051 or ADNS-2610, move the 5 | // files for your mouse to the folder with the OptiMouse files. 6 | // Then uncomment the right header files and object instances below. 7 | // 8 | // The Arduino reads out the dx register and passes it through 9 | // the serial port, at a regular interval. So practically, 10 | // it measures the speed of the surface. 11 | // 12 | // Written by Martijn The -> post [at] martijnthe.nl 13 | // Tutorial: http://www.martijnthe.nl/optimouse/ 14 | // Based on the sketches by Beno”t Rousseau 15 | 16 | #include "PAN3101.h" 17 | // #include "ADNS2051.h" 18 | // #include "ADNS2610.h" 19 | // #include "ADNS2620.h" 20 | 21 | #define SCLK 2 // Serial clock pin on the Arduino 22 | #define SDIO 3 // Serial data (I/O) pin on the Arduino 23 | 24 | PAN3101 Optical1 = PAN3101(SCLK, SDIO); // Create an instance of the PAN3101 object 25 | // ADNS2051 Optical1 = ADNS2051(SCLK, SDIO); 26 | // ADNS2610 Optical1 = ADNS2610(SCLK, SDIO); 27 | // ADNS2610 Optical1 = ADNS2610(SCLK, SDIO); 28 | 29 | void setup() 30 | { 31 | Serial.begin(38400); 32 | Optical1.begin(); // Resync (really necessary?) 33 | } 34 | 35 | void loop() 36 | { 37 | // It's also possible to check whether the internal counter of the sensor 38 | // has rolled over (overflow), on the PAN3101 and the ADNS2051: 39 | 40 | // Optical1.updateStatus(); 41 | // if (Optical1.dxOverflow()) Serial.println("Overflow..."); 42 | 43 | 44 | Serial.println(Optical1.dx(), DEC); 45 | delay(5); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ultrasound 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | PAN3101 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | updateStatus KEYWORD2 16 | dx KEYWORD2 17 | dy KEYWORD2 18 | motion KEYWORD2 19 | dxOverflow KEYWORD2 20 | dyOverflow KEYWORD2 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | 26 | --------------------------------------------------------------------------------