element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Interfacing Ps2(playstation) with Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 1 reply
  • Subscribers 401 subscribers
  • Views 451 views
  • Users 0 members are here
Related

Interfacing Ps2(playstation) with Arduino

Former Member
Former Member over 13 years ago

Hey I am interfacing Ps2 with an arduino to control servo motor wirelessly.My code is able to detect ps2 but it's not reading input from ps2.please tell me Is there any problem in my code.Here is my code::image

 

#include <Servo.h>

#include <PS2X_lib.h>

 

 

Servo myservo;

PS2X ps2x;

int ps2x_error = 0;

byte ps2x_type = 0;

byte ps2x_vibrate = 0;

 

 

int pos = 0;// variable to store the servo position

const byte servoPin = 9;

byte incomingByte;

 

 

void setup()

{

  {

  Serial.begin(9600);

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object

  pinMode(servoPin, OUTPUT);   

  }

  

   

  ps2x_error = ps2x.config_gamepad(13,10,11,12, false, false);

 

 

  if(ps2x_error == 0)

    Serial.println("Found Controller, configured successful");

  else if(ps2x_error == 1)

    Serial.println("No controller found, check wiring.");

  else if(ps2x_error == 2)

    Serial.println("Controller found but not accepting commands.");

  else if(ps2x_error == 3)

    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");

   

   

 

 

  // get which type

  ps2x_type = ps2x.readType();

  switch(ps2x_type)

  {

  case 0: Serial.println("Unknown Controller type");  break;

  case 1: Serial.println("DualShock Controller Found");  break;

  }

}

void loop () {

  if((ps2x_error == 1) || (ps2x_error == 2) || (ps2x_error == 3))

    {

    //skip loop if no controller found

    return;

     }

  else if(ps2x_error == 0)

  {

    if(ps2x_type == 1)

    {

     

     

   ps2x.read_gamepad(); //read controller

 

 

    if(ps2x.Button(PSB_PAD_UP))

      {    

        Serial.println("Up ");

        for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees

  {                                  // in steps of 1 degree

        myservo.write(pos);              // tell servo to go to position in variable 'pos'

        delay(15);                       // waits 15ms for the servo to reach the position

  }

       

      }

      else

      {

        Serial.println("DOWN ");

         for(pos = 90; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees

  {                               

         myservo.write(pos);              // tell servo to go to position in variable 'pos'

         delay(15);                       // waits 15ms for the servo to reach the position

  }

      }    

     

    

   

     

   

}

  }

  delay(50);

}

  • Sign in to reply
  • Cancel
Parents
  • t0mpr1c3
    0 t0mpr1c3 over 13 years ago

    I had exactly the same issue connecting a Guitar Hero whammy pedal to a servo. My guess is that the bitbanged serial communication with the PS controller is incompatible with the software PWM used in the Servo library. Try the old hardware PWM library instead: http://arduiniana.org/libraries/pwmservo/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • t0mpr1c3
    0 t0mpr1c3 over 13 years ago

    I had exactly the same issue connecting a Guitar Hero whammy pedal to a servo. My guess is that the bitbanged serial communication with the PS controller is incompatible with the software PWM used in the Servo library. Try the old hardware PWM library instead: http://arduiniana.org/libraries/pwmservo/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube