Shop OBEX P1 Docs P2 Docs Learn Events
Optical mouse as posistional dead-reckoning device — Parallax Forums

Optical mouse as posistional dead-reckoning device

mountaineermountaineer Posts: 27
edited 2006-07-20 04:02 in BASIC Stamp
I'm trying to use a optical mouse to perform a encoder type task. My robot is differential drive and is controlled using a speed and turn value, which then goes through a mixer function. I'm planning on aiming the hacked mouse at the floor and orienting it so the y axis corresponds to speed and the x axis corresponds to the turn value. I can then use it in some sort of PID loop.

Anyhow, I found out that most optical mice use the same chip set because the company that invented optical technology has a patent on it. I found a document on the kronos robotics website that tells how to use their microcontroller to communicate with a optical mouse using the Avago ADNS-2610. The example has a GE mouse that I couldn't find, so I found another, similar mouse that had the A1610. I couldn't find any mention of the 1610 on the Avago site even though the chip has their icon/symbol thing on it, so I figured that it had the same pinout and command set.

On the data sheet for the 2610 it outlines the communications with the chip, which I tried to translate into code to the best of my ability. The chip appears to have a default high clockline, so I decided to bitbash it just to see if I could get it working, which it didn't.

I'm stuck right now and don't know what to do. Has anyone else tried this?

Thanks in Advance, mountainieer2000

the kronos article is at http://www.kronosrobotics.com/Anotes/Athena to Optical Mouse.pdf

the data sheet for the ADNS-2610 is at http://www.avagotech.com/pc/downloadDocument.do?id=4328

Comments

  • VbGuruVbGuru Posts: 35
    edited 2006-06-07 03:45
    I hate to burst your bubble but I can’t get a mouse to be dead accurate. I have tired my best and I have tried every method I could find. The best I found and easiest to use would have to be hands down the EzMouse by multilabs. They offer fair tech support and have a top quality product. I bought a Pak from AL Williams but I never got it to work despite my best efforts. I wouldn’t tell you not to try one out though. He has top notch tech support. ·If you would like any of my code or help just drop me an email.· Kronos robotics was an attempt.... you need to check out www.hackaday.com and look back a few weeks... a guy does it and gets it to work, again i had no luck with this though...
    http://home.comcast.net/~maccody/robotics/mouse_hack/mouse_hack.html
    http://home.comcast.net/~maccody/robotics/croms-1/croms-1.html
    http://www.imakeprojects.com/projects/seeing-eye-mouse/
    If you make any break-throughs please let me know!!!!

    ·
    ·Any ways… I have been very successful with getting direction from the mouse. ·I took a little gag box to work, it uses:
    2 two color leds red/green
    1 red led
    1 green led
    1 momentary switch
    ·
    What it does:
    Turn on it on and press the button to start it
    Move the mouse to a different location.
    Press the switch a second time
    it then uses the two color leds to tell you if you are getting closer or farther from your start point. One is X. One is Y. Red you are going the wrong way green you are not. You get the idea.
    Best luck I have had was with the EzMouse set to super high resolution. It gets within a about an inch of the original start location which it pretty dang close.
    ·
    Hope this helps you
    ········· Mat
    ·
    ·
    http://www.fiacopetti.it/pic-ps2interf_en.htm
    ·
    ·
    http://www.multilabs.net/ezMOUSE.html
    Best product I think, VERY EASY to hook up and use I have code for this if you need. Tech support from these guys was iffy…. They told me to get the sample code to use it out of a project they have…. I had a hard time getting just what I needed from it. But again…. I have this and will give it to you if needed
    ·
    http://www.awce.com/pak11.htm
    Pak, this guy has top notch tech support!!!!! Couldn’t get it to work but was happy with all of the help that I was given.
  • FranklinFranklin Posts: 4,747
    edited 2006-06-07 15:23
    You might get some information from this:
    http://sprite.student.utwente.nl/~jeroen/projects/mouseeye/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tristan TTristan T Posts: 31
    edited 2006-06-07 21:18
    I am using an ADNS-3060 chip, and have had a lot of success with it:

    http://www.contrib.andrew.cmu.edu/~ttrutna/16-264/Vision_Project/
    http://www.contrib.andrew.cmu.edu/~ttrutna/16-264/Vision_Project2/

    I can't share my source, but this should help you get started.
    This is all implemented by following the ADNS-3060 data sheet.
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    ''           _BSpx24_
    '     - sout|        |vin  - +9V
    '     -  sin|        |vss  - gnd
    '     - atin|        |res  - sw2
    ' gnd -  vss|        |vdd  - +5V
    '     -   p0|        |p15  -
    'rsvd -   p1|        |p14  - ncs
    'rsvd -   p2|        |p13  - miso
    'rsvd -   p3|        |p12  - sclk
    'rsvd -   p4|        |p11  - mosi
    '     -   p5|        |p10  - reset
    '     -   p6|        |p9   -
    'led  -   p7|________|p8   - sw3
    ''
    ...
    ...
    
    LOW ncs
    SHIFTOUT mosi, sclk, MSBFIRST, [noparse][[/noparse]$50]
    SHIFTIN miso, sclk, MSBPRE, [noparse][[/noparse]mot\8, dx\8, dy\8, squal\8, shut_up\8, shut_low\8, mx_pix\8]
    HIGH ncs
    
    



    If you are planning on using the mouse farther than 2mm from the ground, you will need to replace the lens assembly. I have had luck just using heat shrink wrap to connect a 6mm lens to the body of the sensor. You need to make sure to get the surface in focus, so figuring out how to use burst mode and frame dump to get an image out is a step in the right direction. Also pay attention to squal values, they should stay above 50.

    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-06-26 04:06
    Tristan,

    Would it be possible to get you to write a snip of code for me?

    I am currently using the adns 2060 and havent had any luck.

    I am looking at getting a 3060 (if you have a name of an optical mouse that would be great) I did a quick Google and didnt get any mice.

    Anyway.... assuming that the chip is connected to the stamp the same... what would the program look like (for the 2060) ?

    I have had the best results with the EzMouse. I had a direct connection to the 2060 using the Atom from basic micro, but i havent a clue how to translate the code.

    I have been reading your links you posted and as soon as i get my hands on a 3060.... I cant wait.

    I was also wondering (outa my grasp) how hard would it be to connect to one of the laser ones? I have been looking and they seem to be able to "see" on just about any surface.

    Thank you

    ······· Mat
    ·
  • Tristan TTristan T Posts: 31
    edited 2006-06-26 18:06
    Mat,
    Do you have a datasheet for the 2060? As far as laser mice go, they should interface in the same way.
    -Tristan
  • Tristan TTristan T Posts: 31
    edited 2006-06-26 18:15
    I'm pretty sure this:
    www.logitech.com/index.cfm/products/details/US/EN,CRID=2142,CONTENTID=10121
    is the 3060. Too bad it's so expensive. The chip on digikey is about $5, but only in lots of 80.
    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-06-27 02:03
    Tristan
    I goofed…. It’s the 2160, and I have the document attached as well as two others that I found useful. I have a fair amount of information on doing this. I would be glad to share what I have but most of the pdfs I have are 2.5-5 mbs so I can’t add them as attachments.
    ·
    If you would like my email is
    ·
    Pic_socket@yahoo.com
    ·
    I don’t mind emails.
    ·
    If you need anything else just let me know.
    ·
    ·
    Thank you for your time and help!!!

    ······················· Mat
  • Tristan TTristan T Posts: 31
    edited 2006-06-27 15:14
    Alright, here's my best guess on how to interface with the chip.
    First, you're going to want to open up the mouse and take out(or smash) the 8-bit cypress microcontroller.

    Then connect two pins from your basic stamp to leads 3 and 4 on the 2160 like:
           _____
        --| 2160|-- SCK
        --|     |-- SIO
        --|     |--
        --|     |--
    
    



    From here I will refer to the basic stamp pins connected to the 3rd and 4th pins on the 2160 as SCK and SIO:

    sck CON [noparse][[/noparse]whateverpin]
    sio CON [noparse][[/noparse]whateverotherpin]
    
    dx Var Byte
    dy Var Bytec
    
    


    So then doing read write operations comes next.
    So to read out dx for example you (should i think) write to the dx register and then listen for the response.
    SHIFTOUT sio, sck, MSBFIRST, [noparse][[/noparse]$03]
    SHIFTIN sio, sck, MSBPRE, [noparse][[/noparse]dx/8]
    
    



    Let me know if that works. You need to have the USB connected to get power to the chip, and you need to have removed the other controller so that you don't confuse the 2160.

    I'm in the process of designing a SIP package for the ADNS-3060 and the support circuit and if there's enough interest I could produce enough to sell some.

    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-06-29 03:38
    Tristan.
    ·
    Wow…. Good and bad. I hooked the optical mouse up like you said and plugged in the commands. Some times I get nothing no matter how I move the mouse, other times I get a number that just climbs full throttle or in stages. If I play with it a little (resetting and pulling the power) I can get it to work. I get very consistent and steady results one direction, which is what it’s set for right now. I went out and got a brand new mouse and did the modifications to it. I get the same results. Any ideas about what might be happening? I was guessing that it was in the startup pause but thinking about it, is that still needed because this is going directly to the chip and not through the cypress chip. I have also checked the power (new batteries) and all of my solder joins (even got a new mouse). I am running all of this off the basic stamp homework board.
    ·
    ·
    ··········· I also have a question about the data coming in.·
    ·
    pdf page 13:
    ············ Two bytes coming in. One is the direction (0 or 1 possible I think) the second byte is the data. ·(pdf page 20) eight bit 2’s compliment…. Does that have to do with one byte telling direction while the other is giving the direction value? If that is true then to get both x and y I will need to read from that point in the registry and parse it out?
    ·
    Not sure about any of that, still just learning the shiftin, shiftout and serin serout commands.
    ·

    Thank you for your help thus far. I have learned a bit, but most importantly I have seen that it is doable!!!!
    ·
    ·
    ·I have the program that is from what you gave me and another that i got from a source i cant remember..... the second one·(I think)·gives running totals of x & y·and the squal values.··


    P.S.·· What would one of he SIP package cost? I would be interested in atleast 3 if they are not too costly
  • Tristan TTristan T Posts: 31
    edited 2006-06-29 17:22
    VbGuru,
    I think the "climbing full throttle" you are describing is actually a result of interpreting a signed integer as an unsigned integer. The mouse chip uses the first bit to describe negative or positive and then next 7 to give the number, so if you get 255, that's actually -1.

    Give this a try:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    sck CON 15
    sio CON 14
    
    dx VAR Byte
    dx = 0
    dy VAR Byte
    dy = 0
    squal VAR Byte
    
    TOTALX VAR Word
    TOTALX = 0
    
    TOTALY VAR Word
    TOTALY = 0
    
    PAUSE 500
    
    SHIFTOUT sio, sck, MSBFIRST, [noparse][[/noparse]$00, %00000001]  'force the mouse into awake state
    PAUSE 1
    
    DO
      SHIFTOUT sio, sck, MSBFIRST, [noparse][[/noparse]$03]
      SHIFTIN sio, sck, MSBPRE, [noparse][[/noparse]dx\8]
      PAUSE 1
      SHIFTOUT sio, sck, MSBFIRST, [noparse][[/noparse]$02]
      SHIFTIN sio, sck, MSBPRE, [noparse][[/noparse]dy\8]
      PAUSE 1
      SHIFTOUT sio, sck, MSBFIRST, [noparse][[/noparse]$04]
      SHIFTIN sio, sck, MSBPRE, [noparse][[/noparse]squal\8]
    
      TOTALX = TOTALX + dx
      IF dx < 127 THEN TOTALX = TOTALX - 256   ' deal with negative numbers
      TOTALY = TOTALY + dy
      IF dy < 127 THEN TOTALY = TOTALY - 256    'again
    
      DEBUG SDEC ? dx, SDEC ? dy, DEC ? squal
      DEBUG CLS, SDEC ? TOTALX, SDEC ? TOTALY
    LOOP
    



    The SIP package price depends on how much it actually costs to print the breakout boards (probably cheap, but the 3060 has a staggered metric DIP so they might charge more for that) and the price on the 3060s. Right now Digikey sells them in lots of 80 for around $5, but I think I might be able to get a better deal. Of course I'd have to recoup some of the cost of buying a lot of 80 not knowing how many I can sell, but I would imagine that I could put together a package for around $25 or $30 shipped.

    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-06-30 04:45
    Tristan,
    Thanks for the code. Careful of the two “<” that should be “>” in the negative check. Only took a second to fix and works wonders. I am getting better results than anything else that I have done. I am going to keep working with this and see what happens.

    In the mean time, I am trying to make/buy/whatever it takes (if it is possible) something that can be set on the side of a drum and give me the distance it has moved. What I am looking for is basically a tape measure. I have the rest of my little mad scientist setup working. I need it to be able to measure out distances of about 30 inches to a few feet (maybe more) and be able to reset it and pull that distance again. I was hoping that the mouse would work for me as it has no moving parts to wear out. Anyway… I have everything else working and was looking at quadrature encoders, but found a page about doing this and it would be a lot better suited. All I need is one axis; I can cover/paint the surface to what ever it would need. The drum rotation speed is pretty high but that can be changed. Do you think that it is possible to do with one of these mouse sensors? Even if it’s the 3060 or laser mouse… I only need one to work. Do any of these offer that kind of precision? Am I chasing phantoms? You have shown me stuff that I couldn’t pull of in a few months of reading and piecing together.


    Thanks again for all of your help
    Mat
  • Tristan TTristan T Posts: 31
    edited 2006-06-30 15:25
    Mat,
    I'm not sure about the rated speed for the 2160, however the 3060 has a maximum trackable velocity of 40 inches per second. In my personal experience, the basic stamp is too slow to attain these speeds. The problem is that as the speed increases, the buffer in the mouse chip fills up faster. If the mouse counts up more than 128 'counts' in either direction before it is polled for motion data, then the buffer overflows and you lose your accuracy because the counter resets.

    If you can paint the surface of the drum, you might want to consider a simpler solution such as a photo resistor to count dark patches on the surface alternating with light patches, or a rotary encoder on the axis of the drum. I don't want to discourage your quest to use the mouse sensor, I just am not sure that it is the best solution. If you need real repeatable precision, you can get it from the sensor. I calibrated a 3060 to get repeated 10m measurements within 1%, but a cheap rotary encoder on a wheel on the ground would be cheaper and easier and more accurate. The mouse sensor is really useful for when you have no way of touching your enviornment at all.

    -Tristan

    (oh and sorry about the < > thing, I wrote the program directly in the forum and I guess I wasn't particularly careful)
  • VbGuruVbGuru Posts: 35
    edited 2006-07-05 04:22
    Tristan,

    ··········· I made a trip to HomeDepo and made up a test rig for the mouse. You are right; if the mouse is traveling slowly then it does just fine. I am trying to get another microcontroller setup for it. I can’t get the code to work for it properly, would you happen to know anything about Mbasic? If I go slowly then everything seems to be ok. I am using the Basic Atom. I put a link to the specs at the bottom. It will do 33,000 + instructions per second…. I have a total pause of about 33 milliseconds (I think). Shouldn’t this be fast enough to do track your hand dragging it across a book (squal at 143)?
    ·
    I am interested in the mouse for a few reasons. Firstly I can’t seem to get it to work for me (well it is now, so thank you for your help) secondly, it has many applications for other things that I have been thinking of doing. Third, my father has a mini sumo that he wants to add the tracking ability to. That way if the tires say he is going forward he can look at the floor and get a real answer. I wanted to join the elite, the ones that have it working for them. I have parts coming from mouser for doing the photo resistor encoder. I also have read that the encoder wheel from the actual mouse will work well. If I remember correctly it should be able to handle 3000 + rpms…. ·But that is for after the mouse. I have lots of sites booked marked for sine cosine.
    What do you mean when you say that you have calibrated a 3060… I believe that they have different resolutions that the chip can be set at (maybe it’s the ezmouse doing it though). I have a lot to learn still about this.
    ·
    You say you wrote that strait into the forum…. Man you’re good…you’re building cities and I’m still playing with link-n logs…
    ·
    ·
    http://www.basicmicro.com/downloads/docs/atom3.pdf
    http://www.basicmicro.com/downloads/docs/atom24.pdf
    ·
    ·
    These are the specs of the MCU
    ·
    http://www.basicmicro.com/Product.aspx?productID=18&CategoryID=1
    ·

    ·············· Thanks

    ························ Mat

    P.S. how would you have the interface to the SIP for the·3060?
  • Tristan TTristan T Posts: 31
    edited 2006-07-05 17:56
    Mat,
    I just ordered a BasicAtomPro, so I'll give it a try when that arrives. I'll email you with my results with the BasicAtom because I don't know if it's ok to talk about that kind of stuff on the Parallax website. Try stripping out all of the pauses in your loop. I trimmed my loop down to no pause statements, slowed down only by mathematical operations and updating a serial LCD.

    The SIP will have 2 wires for power, and 4 for the serial IO, but you can drive both the in and out data pins with a single I/O pin on your uController.

    I didn't mean to discourage your interest in the mouse sensor, I just wanted to make sure it was the right sensor for your problem.

    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-07-06 13:44
    attachment.php?attachmentid=73899
    ·
    ·Tristan
    I think that I found my problem with not being able to track the mouse movements. If you look at the table above…. The 2610 has a “g” rating of .25, where at the sensor that you are using is rates at 15. That means yours is… about 60 times better at handling acceleration. I can see how in a mouse the 2160 would work, it missing counts and not maintaining good tracking doesn’t really matter. You would just move the mouse a little more. The 3060 should stay with your movements 99% of the time. Looking at a few reviews, they state that you can tell the difference in having a better tracking mouse.
    ·
    I am going to get a 3060 mouse. Take a look at the Razer copperhead mouse. The refresh rate of it is amazing 1 ms response time (most mice are around 8 I think). It has great, but it has unique interface settings. I thought I would post this bit of information, because of the fact it gives a few names of mice for the given sensors.
    ·
    Here are a few links·
    ·
    http://www.ida.net/users/oe1k/OpticalMouse/· more mice listed here as well as better info about specs of the sensors.
    ·
    http://www.tomshardware.co.uk/2005/11/18/the_ultimate_mouse_hunt_part_twouk/page9.html
    ·
    http://www.chiefvalue.com/product/productdetails.aspx?submit=&item=26-153-105&ATTMice
    ·
    ·
    The BasicAttoms are awesome! I would recommend the Mbasic book on the web site. What makes the basic stamp better to use is the tech support, which the atom has next to none. I stripped out everything from my code and even put an if then statement so that it only ran the serout command every 20th time through the code. I also upped the serout speed to 57.6k. Like I wrote above, your code and your help has been top notch, but I think that I am working with an inferior chip, and that is where the root of my problems are. The SIP sounds good so far, one question though… where would one get lenses for it?
    ·
    ··········· Thanks
    ······················· Mat
    ·
    636 x 368 - 15K
  • Tristan TTristan T Posts: 31
    edited 2006-07-06 15:33
    Mat,
    Your diagnosis of tracking problems seems reasonable, but hold off on getting that Razer Copperhead mouse. The problem being that with laser mouse it relies on having a laser illuminate the entire field of vision, so if you wanted to take out the old lens and focus it more than 3 or 4 mm from the ground you would run into problems lighting a larger area with the laser. The 3060 based mice have different features/specs because the chip actually has a 2kb srom space that the manufacturer loads with a microcontroller on each boot. I'm not sure what the default settings with no srom are, but I can find out for you. Avago provides srom files on the 3060 website, but I am not sure which features each option enables.

    As far as lenses go, right now I am using a 6mm 4.59fl laser diode that I found in the lab that I have connected to the neck of the sensor front plate with heat shrink wrap. Not exactly the most robust option, but it stays in focus so I can't complain. If I end up putting together a package to sell, I'll figure out some kind of threaded lens mounting system. Either way it probably won't happen until the end of the summer.

    If you end up looking for a 3060 in a logitech mouse, it will probably be labeled ADNS-2020 or A2020s or something; they behave the same way.

    -Tristan
  • RinksCustomsRinksCustoms Posts: 531
    edited 2006-07-06 20:06
    I would like to post a dumb question for better of clarifacation...

    Couldn't you just interface these mice with a PS/2 or usb adapter to a BS2?

    Forgive my ignorance...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Definetly a E3 (Electronics Engineer Extrodinare!)
    "I laugh in the face of imposible,... not because i know it all, ... but because I don't know well enough!"
  • Tristan TTristan T Posts: 31
    edited 2006-07-06 20:58
    RinksCustoms,
    While you can get some kind of post processed data out of the PS/2 port, you would need a microcontroller to do the mouse handshaking/interface, so your final solution would be:

    Mouse chip->Cypress chip(included in a mouse)->ps2 to serial bridge->ps2 basic stamp logic layer-> dx dy data
    instead of just: mouse chip -> dx dy data

    Also, with a PS/2 or USB interface you have a fixed data rate which you have to synchronize with the bs2 where as the bs2 can poll for data directly at its own rate if directly interfaced.

    You can get much more data out of an optical mouse chip than just dx and dy if you interface directly to the chip. Most importantly you can get an image dump and surface quality data out of the chip which is not sent to the computer via PS/2 or USB.

    Also, the 3060 uses a shaddow rom file which must be loaded onto the chip directly from a microcontroller, so if you want any different settings than the ones that come factory burned on the cypress chip you are out of luck.

    In the end it is much simpler, cheaper, and more robust to connect directly to the chip, unless of course you are using a propeller or something that comes with a PS/2 interface.

    Are you at all interested in navigation with optical mouse sensors? or just trying to see if you have a simple solution?

    -Tristan
  • VbGuruVbGuru Posts: 35
    edited 2006-07-20 04:02
    Tristan,
    ··········· I got my optical mouse and before I started taking it apart I hooked it up to my ezmouse. I got the same results from it as I did the others mice. Its still just more or less general distances.
    ·
    ·I looked into hacking the new mouse, but I have a few questions.
    ··········· The atom and the stamp are 5v, the sensor wants 3.3v. I see that you used resistors to make the connection. Will that work for me also? I was wondering if I needed something like a 1n4148 signal diode to protect it. I am pretty sure that resistors from 10k – 100k should work. ·
    ·
    I would also like to add that for what I want it for I will be leaving it in the mouse so I don’t need to worry about the optics.
    ·
    I have an encoder hooked up to the atom and I cant get it to keep track of the rotations and still be able to output to an lcd. I am currently working on getting a pic16f876a and having it send the data through the Hserial.
    ·
    Does anyone know of any good rotary encoders?
    ·
    ·RinksCustom,
    ··········· I am interested in doing this because I can’t. I would like to learn to do something new... just to know I can.·
    I am learning to program in a few languages and on two platforms. I find the easiest way for me to further what I know is find something that looks fun or interesting and do it. I have bought the two different pre-made setups for getting data from mice, but they don’t seem to work as well as stated. I would like to get them to work that well.
    ·
    Thanks
    ········ Mat
Sign In or Register to comment.