Page 2 of 2

Re: PSP 1000 Analog Stick to Teensy LC

Posted: Fri Sep 16, 2016 10:41 am
by fdeluxe
For everyone running into the same problem, here's how I solved my calibration:

Code: Select all

// Analog Stick Calibration

  //Remap the data range
    mapX=map(analogRead(23),185, 839, 0, 1023); //I used dxtweak2 on Windows to read at the minimum and maximum values of my stick (X: min=185, max=839, Y: min=125, max=830)
    mapY=map(analogRead(22),125, 830, 0, 1023); //and remapped them to the absolute maximum and minimum values for analog output.
  
  //Deadzones
    if(mapX<512+deadzone&&mapX>512-deadzone)mapX=512;
    if(mapY<512+deadzone&&mapY>512-deadzone)mapY=512;
    if(mapX<24)mapX=0;
    if(mapY<24)mapY=0;
    
  //Non-linear correction.

  // This changes the sticks behaviour from linear acceleration to "exponential". Small stick movements result in slower movement,
  // while great movement results in faster movement. This way the stick is more accurate for fine movements, but loses some of its range.
   
      mapX=(int)(0.00000302*mapX*mapX*mapX-0.004631*mapX*mapX+2.577*mapX+1.23);
      if(mapX>1023) mapX=1023;
      if(mapX<0) mapX=0;
      
      mapY=(int)(0.00000302*mapY*mapY*mapY-0.004631*mapY*mapY+2.577*mapY+1.23);
      if(mapY>1023) mapY=1023;
      if(mapY<0) mapY=0;

    //Send final values
    Joystick.X(mapX);
    Joystick.Y(mapY);
Edit: I changed the non linear correction part of the calibration. Switching from 5V to 3V solved my problem with the stick not being centered!

Visualization of the non-linear calibration. The function I used in the code is a more accurate fit using MATHLAB. Dont use this formula! The stick would be at 561 (off-center) in rest position.
pspstickmath.PNG
pspstickmath.PNG (14.65 KiB) Viewed 1479 times

Re: PSP 1000 Analog Stick to Teensy LC

Posted: Mon Oct 03, 2016 10:10 am
by fdeluxe
Heres a tip for everyone who is struggeling with a non-centered analog stick output: Check if you have connected the stick to a 3V outlet. Most of the calibrstion above became uneccessary once I switched from 5V to 3V.