Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Mouse Movement from PS2 Trackpad

  1. #1

    Mouse Movement from PS2 Trackpad

    Hello there,
    I have been working on converting an Alps Glidepoint Numpad and Trackpad to USB with a Teensy++.
    So far I have managed to hook up +5V, Ground, CLK, and DATA from the trackpad to the Teensy, and using the attached code I can get it to stream data into the Serial Monitor for the X and Y axis when moving my finger across the Trackpad.
    But despite trying to research online I can not seem to figure out how to convert this information to cursor movement.

    Code:
    /*
    
    #include "PS2Mouse.h"
    
    PS2Mouse mouse(22,23);
    
    void setup(){
      Serial.begin(9600);
      while(!Serial);
      Serial.print("Setup...");
    
      mouse.begin();
      Serial.println("complete!");
    }
    
    void loop(){
      uint8_t stat;
      int x,y;
      mouse.getPosition(stat,x,y);
      
      Serial.print(stat, BIN);
      Serial.print("\tx=");
      Serial.print(x, DEC);
      Serial.print("\ty=");
      Serial.println(y, DEC);
      
      delay(2);  
    }
    I tried to use this next sketch but it did not result in any cursor movement.
    If there is something obvious that I am missing here, or if there are any helpful resources to point me to I would be rather appreciative.

    Code:
    /*
    
    #include "Mouse.h"
    #include "PS2Mouse.h"
    #define PS2_DATA 22
    #define PS2_CLK 23
    
    byte mstat1;
    byte mstat2;
    byte mxy;
    byte mx;
    byte my;
    byte mz;
    int msval[2];
    int repeatCnt;
    
    
    PS2Mouse mouse(PS2_CLK, PS2_DATA);
    
    void setup()  {
       Mouse.begin();
      mouse.write(0xff); //reset
      mouse.read(); //ack byte
      mouse.read(); //blank */
      mouse.read(); //blank */
      mouse.write(0xf0); // remote mode
      mouse.read() ; //ack
      delayMicroseconds(100);
      mouse.write(0xe8);
      mouse.read();
      mouse.write(0x03);
      mouse.read();
      mouse.write(0xe8);
      mouse.read();
      mouse.write(0x00);
      mouse.read();
      mouse.write(0xe8);
      mouse.read();
      mouse.write(0x01);
      mouse.read();
      mouse.write(0xe8);
      mouse.read();
      mouse.write(0x00);
      mouse.read();
      mouse.write(0xf3);
      mouse.read();
      mouse.write(0x14);
      mouse.read();
      Serial.begin(9600);
    }
    
    void ms_read()
     {
       mouse.write(0xeb);
       mouse.read();
       mstat1 = mouse.read();
       mxy = mouse.read();
       mz = mouse.read();
       mstat2 = mouse.read();
       mx = mouse.read();
       my = mouse.read();
       msval[0] = (((mstat2 & 0x10) << 8) | ((mxy & 0x0F) << 8) | mx );
       msval[1] = (((mstat2 & 0x20) << 7)  | ((mxy & 0xF0) << 4) | my );
       msval[2] = int(mz);
     }
       
       void loop()  {
        ms_read();
        if (msval[0] > 0 and msval[2] > 10)
        { repeatCnt++; }
        else
        { repeatCnt = 0; }
    
          if (repeatCnt > 2)
          {
            msval[0] = map(msval[0], 580, 5164, -1023, 1023);
            msval[1] = map(msval[1], 1120, 5967, 1023, -1023);
            Mouse.move(msval[0]/200,msval[1]/200);
          }
       
       }

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,882

  3. #3
    Quote Originally Posted by tonton81 View Post
    Thanks for the link, this can position the mouse to a specific point on screen, is there a specific implementation to tie the mouse movement to the data coming in from the trackpad?

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,882
    moveTo uses absolute positioning of the pixel size on your screen. So if you got a coordinate based on screensize, thats exactly where the pointer will go
    if you change screen resolution, obviously you'll need to write the adjustment based on that

    usually if the device has a min/max (like when I hacked the pioneer NEX6000 deck touchscreen, enabled OS touch support thru teensy for HDMI peripherals as a mouse), you can map() them to your moveTo positions based on the screensize

  5. #5
    Quote Originally Posted by tonton81 View Post
    moveTo uses absolute positioning of the pixel size on your screen. So if you got a coordinate based on screensize, thats exactly where the pointer will go
    if you change screen resolution, obviously you'll need to write the adjustment based on that

    usually if the device has a min/max (like when I hacked the pioneer NEX6000 deck touchscreen, enabled OS touch support thru teensy for HDMI peripherals as a mouse), you can map() them to your moveTo positions based on the screensize
    It says that this will only work for Teensy LC, 3.0 and 3.1.
    Possibly that's the reason it spits out these errors?"

    Code:
    Arduino: 1.8.5 (Windows 10), TD: 1.40, Board: "Teensy++ 2.0, Keyboard + Mouse + Joystick, 16 MHz, US English"
    
    thisguy: In function 'void setup()':
    thisguy:7: error: 'class usb_mouse_class' has no member named 'screenSize'
       Mouse.screenSize(1920, 1080);  // configure screen size
    
             ^
    
    thisguy: In function 'void loop()':
    thisguy:16: error: 'class usb_mouse_class' has no member named 'moveTo'
         Mouse.moveTo(25, 100);       // point to pixel at 25, 100
    
               ^
    
    thisguy:19: error: 'class usb_mouse_class' has no member named 'moveTo'
         Mouse.moveTo(1580, 14);      // point to pixel at 1580, 14
    
               ^
    
    'class usb_mouse_class' has no member named 'screenSize'
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,882
    Arduino: 1.8.5 (Windows 10), TD: 1.40, Board: "Teensy++ 2.0, Keyboard + Mouse + Joystick, 16 MHz, US English"
    I think you have Teensy2.0 selected in your boards? You should also update teensyduino

    i do believe they are for the T3.x series
    Last edited by tonton81; 12-10-2018 at 03:19 PM.

  7. #7
    The Teensy ++ only comes in 2.0, it won't let me upload a 3.x sketch.

  8. #8
    I managed to get mouse movement with the following code, but it is quite erratic. It doesn't track finger movement at all.
    I'm not sure what the issue is, any help would be appreciated.

    Code:
    #include "PS2Mouse.h"
    #include <Mouse.h>
    #define PS2_DATA 22
    #define PS2_CLK 23
    
    
    
    void mouse_init();
    void setup();
    void loop();
    PS2Mouse mouse(22, 23);
     
    /*
       initialize the mouse. Reset it, and place it into remote
       mode, so we can get the encoder data on demand.
    */
    void mouse_init()
    {
      mouse.write(0xff);  // reset
      mouse.read();  // ack byte
      mouse.read();  // blank */
      mouse.read();  // blank */
      mouse.write(0xf0);  // remote mode
      mouse.read();  // ack
      
    }
     
    void setup()
    {
      Serial.begin(9600);
      mouse_init();
    }
     
    /*
       get a reading from the mouse and report it back to the
       host via the serial line.
    */
    void loop()
    {
      char mstat;
      char mx;
      char my;
     
      /* get a reading from the mouse */
      mouse.write(0xeb);  // give me data!
      mouse.read();      // ignore ack
      mstat = mouse.read();
      mx = mouse.read();
      my = mouse.read();
     
      /* send the data back up */
      Serial.print(mstat, BIN);
      Serial.print("\tY=");
      Serial.print(mx, DEC);
      Serial.print("\tX=");
      Serial.print(my, DEC);
      Serial.println();
      
     
     
      Mouse.move(mx / 1.3 , my / -1.7);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •