Shop OBEX P1 Docs P2 Docs Learn Events
PS/2 Mouse sample code with serial terminal support? — Parallax Forums

PS/2 Mouse sample code with serial terminal support?

BotdocterBotdocter Posts: 271
edited 2010-04-29 07:11 in Propeller 1
I have a ps/2 mouse ready to hook up but now i need some code to make it run. I have downloaded the "Mouse" driver from the obex, but it doesn't contain any demo code.

All i need is the mouse to count the steps it's away from it's base(starting point) as Y, and the rotation must be calculated with X, so a fixed total value 360 degrees

PNG file is attached to make my idea more clear.



Any help is appreciated since i cannot find any tutorials or topics on this...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor

a few motors and a whole lot of chaos!
«1

Comments

  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 00:32
    Anyone? A link to some sample code maybe?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • b.p.m.b.p.m. Posts: 59
    edited 2010-04-14 00:56
    hey botdoc,
    it seems that great minds think alike; i been working out
    the finer points of building a bot incorporating a PS/2
    mouse as the soul sensory input. it would use a internal
    mapping subroutine to 'know' where it is in a room, etc.
    i was planning on using a cutdown protoboard, but the
    size and expense has me working on a version using a
    PIC and a small toy robot i bought. i was going to use
    the Prop mouse driver also, but now i guess i'll have to
    port it PIC asselmbler (oh boy, what fun). i have a genuine
    Paralllax optical mouse ($5, great deal) that i plan to
    harvest for parts.
    good luck with your mouse-bot.

    blake

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Can't sleep, clown will eat me."
    Bart Simpson
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-04-14 02:00
    This project is already completed at the source below.

    http://forums.parallax.com/showthread.php?p=661158
    http://forums.parallax.com/showthread.php?p=782525
    hackaday.com/2006/01/29/robotic-motion-sensing-using-an-optical-mouse/
    Chad George said...
    The optical mouse sensor is integrated directly into the lower circuit board of the robot (it's covered by a lense in the pictures above) There is no ps2 connector since its only the sensor chip that I am using. The sensor connects to the Prop via a 2 wire SPI at ~1Mhz. The sensor returns a delta X and delta Y since last read when polled for position. By sampling quickly and integrating these small changes a position can be obtained.
    humanoido

    Post Edited (humanoido) : 4/14/2010 2:07:46 AM GMT
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 02:03
    I have the map code done allready ( not tested yet)
    it uses wavefront mapping.

    Search on the forum for 'matrix' and you'd find my topic.
    Might you find anything on ps/2 let me know

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 03:56
    Thank you for the links, but they're still ongoing projects and non of them have posted any code yet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 04:53
    i wrote this myself but can't get it to work... can anyone see what i'm doing wrong? it does compile,run and output (zero's) to the terminal.

    But nothing when the mouse moves..

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      dPin = 8
      cPin = 9
    
    OBJ mouse : "Mouse.spin"
        Ser   : "FullDuplexSerial.spin"
        
    PUB Main | delta_y,delta_x,mousey,mousex 
    
        Ser.start(31, 30, 0, 115200)  '' Initialize serial communication to the PC   
    
        mouse.start(dPin,cPin)
    
        mousex := mouse.delta_x 
        mousey := mouse.delta_y
        
        repeat
          ser.dec(mousex)
          ser.tx(9)
          ser.dec(mousey)
          ser.tx(13)
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • pullmollpullmoll Posts: 817
    edited 2010-04-14 09:21
    Botdocter said...
    But nothing when the mouse moves..

    Not surprising, as you print the local variables, not the function results: Change the code to:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      dPin = 8
      cPin = 9
    
    OBJ mouse : "Mouse.spin"
        Ser   : "FullDuplexSerial.spin"
        
    PUB Main | delta_y,delta_x,mousey,mousex 
    
        Ser.start(31, 30, 0, 115200)  '' Initialize serial communication to the PC   
    
        mouse.start(dPin,cPin)
    
        
        repeat
          mousex := mouse.delta_x 
          mousey := mouse.delta_y
          ser.dec(mousex)
          ser.tx(9)
          ser.dec(mousey)
          ser.tx(13)
    
    
    


    And it should work as you expect. You don't actually need mousex and mousey, if all you want to do is print to the serial output. You can call the functions mouse.delta_x and mouse.delta_y inside the dec().

    HTH,
    Juergen

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 14:46
    Euhm... Nothing... Just bought a new mouse. Will try that.

    Thank you!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 18:11
    This mouse won't even turn on. The led flashes once on power up but them
    nothing...?!?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • hover1hover1 Posts: 1,929
    edited 2010-04-14 18:42
    Could you have DATA and CLOCK lines swapped? Been there. Do you have the correct pull-ups?
    555 x 401 - 57K
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 19:36
    I had the two 100 ohm resistors in place but didn't know about the 10 k-ohm ones.
    Let me try that and ill get back to you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-14 23:11
    Ok added the resistors. Led stays on but very weak. When using scroll, led turns off and doesn't come back on untill re-power.
    Wat is wrong? I saw that in the mouse itself, on the cPin and dPin there are allready 2 resistors could that be a problem?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-15 16:12
    I still ain't got this to work. The mouse turns on, led changes from dimmed to bright on movement, but no output.

    HELP!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-04-15 19:44
    can forum-members look into glasbowels?

    No not at all.

    There are two ways to solve a problem arrowing and narrowing.

    arrowing means shoot around creative guesses in the hope that one hits the problem.
    can be succesfull quickly can be unsuccessful endlessly

    narrowing means narrow down the problem by excluding possible reasons STEP BY STEP.
    ALWAYS successful after a limited amount of time.

    Did you connect the mouse to a PC testing if it works with a PC? If everything is alright the mouse-internal LED lights up
    you can't reverse this conclusion. if the internal LED lights up this is no guarantee that EVERYTHING is working

    Did you check the input pins by simply connecting them through a switch to +3.3V/0V?

    Did you check the clock and dataline of the mouse with an oscilloscope what the signal levels are when connected to the propeller?

    Alternative: did you made a small testprogram that checks if the clockline/dataline is switching

    Did you download the code to RAM or EEPROM?

    What kind of board do oyu have?

    The more information you provide about your setup the better the help can be.

    From providing the word "help" the only help can be asking back questions

    best regards

    Stefan
  • BotdocterBotdocter Posts: 271
    edited 2010-04-15 20:25
    Yes indeed! And that would be the questions that are relevant. I don't know what info is relevant and what not.

    Anyway, a few questions where already answered a few posts back. So here we go:

    i have no pc to test the mouse on since i'm a mac user.

    I've changed the input pins to other pins but did not matter.

    I have a propeller robot control board ( as used in the stingray)

    i bought 2 mice and the inside is quite different. One has resistors for the leds and for the clock and datapin. When i connect this one the power seems to be too low to work. The other one has no internal resistors and power is just fine. Neither of them give me any output what so ever.

    If you need to know more, please let me know...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-04-16 22:22
    As you are not sure which info is relevant or not post just all info (except what you had for dinner)

    you haven't even answered my questions yet

    do you have an oscilloscope?

    I took a look onto the schematic of the propeller robot control board
    (could have been provide by you to make it easier for other forum-members to help you)

    most of the prop-IO-pins are conected to some kind of hardware that will interfere with the mouse.
    As long as you don't tell us on which Prop-IO-pins you have connected the mouse everything is speculation

    so please tell us which IO-pins you use for the mouse - and addtional - your knowledge level about electronics


    best regards

    Stefan
  • pullmollpullmoll Posts: 817
    edited 2010-04-16 23:10
    StefanL38 said...
    so please tell us which IO-pins you use for the mouse

    He used pins 8 and 9, as can be seen in the source he posted. I don't think he changed his code to what I suggested in the first reply, though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • hover1hover1 Posts: 1,929
    edited 2010-04-16 23:41
    You could try and disable the translator an connect the two mouse conections directly to the header before the translator. That might be you problem.

    Give it a try.

    Jim
    405 x 405 - 177K
  • BotdocterBotdocter Posts: 271
    edited 2010-04-19 15:12
    I did try but it makes no difference at all.
    i really have no idea what i did wrong. If i connect it to those ports without the converter in between. Do i still need the pullup resistors?(100 ohm and 10K)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!

    Post Edited (Botdocter) : 4/19/2010 3:17:16 PM GMT
  • hover1hover1 Posts: 1,929
    edited 2010-04-19 15:22
    Yes you need the pullups and the in-line resistors. Are you supplying the mouse with 5 volts as shown in the circuit?

    Jim
    Botdocter said...
    I did try but it makes no difference at all.
    i really have no idea what i did wrong. If i connect it to those ports without the converter in between. Do i still need the pullup resistors?(100 ohm and 10K)

    555 x 401 - 57K
  • BotdocterBotdocter Posts: 271
    edited 2010-04-19 15:57
    Yes indeed. I made a pcb with a ps/2 connectoe and the resistors. No difference....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-04-20 03:53
    How can it be that everyone gets this to work and i can't? Multiple mice further i still ain't got it working!!
    I tried everything. Usb mice, ps2 mice and combi mice ( also wireless ).

    I really need this mouse to work before i can code anything else. Please help me!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • AribaAriba Posts: 2,690
    edited 2010-04-20 15:14
    Botdocter said...
    Yes indeed. I made a pcb with a ps/2 connectoe and the resistors. No difference....

    Have you made the connections right ? The MiniDIN have a weird numbering of the pins.
    Here is a working Layout, viewed from the component side.

    Andy
    190 x 173 - 2K
  • BotdocterBotdocter Posts: 271
    edited 2010-04-20 16:31
    So actually the ps/2 connector is placed on top of this? Top view?
    If so i have the wires the right way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-04-21 02:10
    USB-mice won't work as USB is a complete different protocol than PS/2
    using a wireless mouse at the beginning is not a good idea as then you are dealing with another source of faults: the wireless connection.

    If you start to develop something you should keep the things as simple as possible.

    did you make the basic checks that I recommended?

    You seem to be a hobbyist. But at some points you need to work like a professional. If you are just guessing around "it might be this or that"
    your hobby is guessing around and trying and no longer programming.

    If a professional encounters a problem and can't solve it with two quick guesses he switches to analysing ALL the details.
    Not a single detail is skipped by thinking "I think this is it not" And he checks REALLY EVERYTHING.

    This means:
    Using a SPIN-demoprogram that is well known as working. Checking does the mouse work with this?
    next check is: are the IO-pins still working properly?

    using a small testprogram that check the IO-pins are they still working as input / output by simply connecting then through a current-limiting resistor of 1kOhm with a switch
    which connects the IO-pin to ground or +3.3V

    then testing the io-pin with a small led-blinking program conneting a current-limiting resistor of 220 ohms and an LED to the IO-pin

    only if you HAVE DONE these checks you can be REALLY sure the IO-pins are still working

    Without that checks you are just ASSUMING they are working. If this is NOT the case you can try pull-up-resistors, pinouts mices as long as you want
    you won't find the error.

    next thing using an oscillsocope to analyse the signals on the pins of the mouse.

    1.) when connected to a PC
    2.) when connected to the propeller
    comparing them

    if you don't have an oscilloscope write a small testprogram that makes a variable count up everytime the state of the IO-pin connected to the data-line of the mouse changes
    from this you get a feedback "dataline changes its signal state". Of course then you know much less then if use an oscilloscope.

    connect the mouse to the data and clock-io-pin
    additional connect the clock-io-pin through a resistor to another free IO-pin and use a freq-measuring program started in another cog to see if the clock-line
    toggles at the required frequency

    etc. etc. etc.

    best regards

    Stefan
  • BotdocterBotdocter Posts: 271
    edited 2010-04-21 16:41
    Thank you for your reply.

    I need to say one thing though...

    I'm getting so tired of members who seem to think i just ask and do no research myself.
    because i do!
    The information found on this forum isn't very clear though most of the time.
    For a newbie to spin, a lot of things are not understandablr because of a lot of 'jargon'

    anyway...

    All the code that i have untill now, i wrote myself. Nothing is copied, and so i did my own research.


    As for the mouse: i didn't just try anything. I followed the posts that i could find and it turned out to do nothing. So i tried to find a solution but had no succes. And here we are.

    I have no osciloscope and have code from the obex to make it work. Even have code that has been posted in this topic by one of the members but also no succes...

    I hope i can write those test programms. At least i will try...

    Thanx!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • AribaAriba Posts: 2,690
    edited 2010-04-21 19:03
    Here is a test program which works with my mouse on a ProtoBoard. The Output goes to the PST or to PropTerminal.
    You should make the connections before the voltage translater as hover1 suggested, and don't forget to close the
    jumper to disable the translator (JP3 if you use pins 8/9).
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      ms   :   "Mouse"
      ser  :   "FullDuplexSerial" 
      
    PUB Main | b
      'start the terminal
      ser.start(31,30,0,115200)
      ser.str(string("Mouse Demo...",13))
    
      'start the mouse
      ms.start(24, 25)  '<--- your pins 
    
      repeat
          ser.tx(1)     'Home
          ser.tx("B")   'show Mouse values
          ser.tx(":")
          ser.dec(ms.buttons)
          ser.tx(" ")
          ser.tx("X")
          ser.tx(":")
          ser.dec(ms.abs_x)
          ser.tx(" ")
          ser.tx("Y")
          ser.tx(":")
          ser.dec(ms.abs_y)
          ser.tx(" ")
    
          waitcnt(clkfreq/10 + cnt)
    
    



    Andy
  • BotdocterBotdocter Posts: 271
    edited 2010-04-21 19:16
    Thank you! I will try it tonight. And let you know if it worked. So i understand right i have to jumper the converter AND use the connection before the converter? Or is it a 'or' solution?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!

    Post Edited (Botdocter) : 4/21/2010 7:21:23 PM GMT
  • AribaAriba Posts: 2,690
    edited 2010-04-21 20:36
    Yes before the converter AND set the jumper. If I understand the description of the RobotControlBoard right, the jumper disables the converter. So the converter can not disturb the mouse communication.
  • hover1hover1 Posts: 1,929
    edited 2010-04-21 21:25
    Sorry I did not point out putting the jumper in to disable the converter.

    Let use know how it turns out.

    Jim
    Botdocter said...
    Thank you! I will try it tonight. And let you know if it worked. So i understand right i have to jumper the converter AND use the connection before the converter? Or is it a 'or' solution?

Sign In or Register to comment.