Error while using the psx

so this is my wiring
image

when I tried to compile the code using this particular library,

i am getting this error
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::NewButtonState()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::NewButtonState(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonPressed(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonReleased(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::Button(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonDataByte()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::Analog(unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::readType()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::_gamepad_shiftinout(char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::sendCommandString(unsigned char*, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::enableRumble()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::reconfig_gamepad()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::read_gamepad(bool, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::read_gamepad()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::enablePressures()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::config_gamepad(unsigned char, unsigned char, unsigned char, unsigned char, bool, bool)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::config_gamepad(unsigned char, unsigned char, unsigned char, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::NewButtonState()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::NewButtonState(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonPressed(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonReleased(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::Button(unsigned int)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::ButtonDataByte()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::Analog(unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::readType()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::_gamepad_shiftinout(char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::sendCommandString(unsigned char*, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::enableRumble()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::reconfig_gamepad()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::read_gamepad(bool, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::read_gamepad()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::enablePressures()'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::config_gamepad(unsigned char, unsigned char, unsigned char, unsigned char, bool, bool)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\PS2X_lib\PS2X_lib.cpp.o (symbol from plugin): In function `PS2X::NewButtonState()':

(.text+0x0): multiple definition of `PS2X::config_gamepad(unsigned char, unsigned char, unsigned char, unsigned char)'

sketch\PS2X_lib.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Uno.

Please post your sketch, using code tags when you do

Hi @gratus. It appears that, in addition to installing it as usual, you may have also put a copy of the library in the same folder as your sketch.

If so, the error will be fixed by deleting the library files from the sketch folder.

Please give it a try and then let us know what the results were.

// include libraries
#include <PS2X_lib.h>  //for v1.6

// These are used to set the direction of the bridge driver.
#define ENA 3      //ENA
#define MOTORA_1 4 //IN3
#define MOTORA_2 5 //IN4
#define MOTORB_1 8 //IN1
#define MOTORB_2 7 //IN2
#define ENB 6      //ENB

int motor_right_speed = 0;
int motor_left_speed = 0;

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you conect the controller, 
//or call config_gamepad(pins) again after connecting the controller.
int error = 0; 
byte type = 0;
byte vibrate = 0;

void setup(){

 // Configure output pins
 pinMode(ENA, OUTPUT);
 pinMode(MOTORA_1, OUTPUT);
 pinMode(MOTORA_2, OUTPUT);
 pinMode(ENB, OUTPUT);
 pinMode(MOTORB_1, OUTPUT);
 pinMode(MOTORB_2, OUTPUT);

 // Disable both motors
 digitalWrite(ENA,0);
 digitalWrite(ENB,0);
 
 // Start serial communication
 Serial.begin(57600);
  
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 
 // Check for error
 if(error == 0){
  Serial.println("Found Controller, configured successful");
 }
   
 else if(error == 1)
  Serial.println("No controller found, check wiring or reset the Arduino");
   
 else if(error == 2)
  Serial.println("Controller found but not accepting commands");
  
 else if(error == 3)
  Serial.println("Controller refusing to enter Pressures mode, may not support it.");
   
 // Check for the type of controller
 type = ps2x.readType();
 switch(type) {
  case 0:
    Serial.println("Unknown Controller type");
    break;
  case 1:
    Serial.println("DualShock Controller Found");
    break;
  case 2:
    Serial.println("GuitarHero Controller Found");
    break;
  }
}

// Main loop
void loop(){
   
 if(error == 1) //skip loop if no controller found
  return; 
  
 else { //DualShock Controller
  
    ps2x.read_gamepad(false, vibrate); // disable vibration of the controller   
    
    int nJoyX = ps2x.Analog(PSS_LX); // read x-joystick
    int nJoyY = ps2x.Analog(PSS_LY); // read y-joystick
    
  
    nJoyX = map(nJoyX, 0, 255, -1023, 1023);
    nJoyY = map(nJoyY, 0, 255, 1023, -1023);
  
    // OUTPUTS
    int nMotMixL; // Motor (left) mixed output
    int nMotMixR; // Motor (right) mixed output
  
    // CONFIG
    // - fPivYLimt  : The threshold at which the pivot action starts
    //                This threshold is measured in units on the Y-axis
    //                away from the X-axis (Y=0). A greater value will assign
    //                more of the joystick's range to pivot actions.
    //                Allowable range: (0..+127)
    float fPivYLimit = 1023.0;
        
    // TEMP VARIABLES
    float   nMotPremixL;    // Motor (left) premixed output
    float   nMotPremixR;    // Motor (right) premixed output
    int     nPivSpeed;      // Pivot Speed
    float   fPivScale;      // Balance scale between drive and pivot
  
    // Calculate Drive Turn output due to Joystick X input
    if (nJoyY >= 0) {
      // Forward
      nMotPremixL = (nJoyX>=0)? 1023.0 : (1023.0 + nJoyX);
      nMotPremixR = (nJoyX>=0)? (1023.0 - nJoyX) : 1023.0;
    } else {
      // Reverse
      nMotPremixL = (nJoyX>=0)? (1023.0 - nJoyX) : 1023.0;
      nMotPremixR = (nJoyX>=0)? 1023.0 : (1023.0 + nJoyX);
    }
  
    // Scale Drive output due to Joystick Y input (throttle)
    nMotPremixL = nMotPremixL * nJoyY/1023.0;
    nMotPremixR = nMotPremixR * nJoyY/1023.0;
  
    // Now calculate pivot amount
    // - Strength of pivot (nPivSpeed) based on Joystick X input
    // - Blending of pivot vs drive (fPivScale) based on Joystick Y input
    nPivSpeed = nJoyX;
    fPivScale = (abs(nJoyY)>fPivYLimit)? 0.0 : (1.0 - abs(nJoyY)/fPivYLimit);
  
    // Calculate final mix of Drive and Pivot
    nMotMixL = (1.0-fPivScale)*nMotPremixL + fPivScale*( nPivSpeed);
    nMotMixR = (1.0-fPivScale)*nMotPremixR + fPivScale*(-nPivSpeed);
    
    motor_left_speed = nMotMixL;
    motor_right_speed = nMotMixR;
  
    if (motor_right_speed > 50) {
      digitalWrite(MOTORB_1,HIGH);
      digitalWrite(MOTORB_2,LOW);
    }
    else if (motor_right_speed < -50) {
      digitalWrite(MOTORB_1,LOW);
      digitalWrite(MOTORB_2, HIGH);
      
    }
    else {
      digitalWrite(MOTORB_1, LOW);
      digitalWrite(MOTORB_2, LOW);
    }
  
    if (motor_left_speed > 50) {
      digitalWrite(MOTORA_1, LOW);
      digitalWrite(MOTORA_2, HIGH);
    }
    else if (motor_left_speed < -50) {
      digitalWrite(MOTORA_1,HIGH);
      digitalWrite(MOTORA_2,LOW);
    }
    else {
      digitalWrite(MOTORA_1, LOW);
      digitalWrite(MOTORA_2, LOW);
    }
    analogWrite(ENA, abs(motor_left_speed));
    analogWrite(ENB, abs(motor_right_speed));
    if (abs(motor_left_speed > 50) || abs(motor_left_speed > 50)) {
      Serial.println("Moving!");
    }
   
   delay(50);
 }    
}

Well it worked out thank you somuch, you are a life saver :slight_smile:

You are welcome. I'm glad it is working now. Enjoy!

Hi,
Is it the same project?

If so, please don't duplicate our efforts....

so I want to make a car controlled using arduino and ps2 controlller.
This is my wiring, and I have double checked it, it is correct as shown

and I have used this ps2x library

and this is the sketch

// include libraries
#include <PS2X_lib.h>

// These are used to set the direction of the bridge driver.
#define ENA 3      //ENA
#define MOTORA_1 4 //IN3
#define MOTORA_2 5 //IN4
#define MOTORB_1 8 //IN1
#define MOTORB_2 7 //IN2
#define ENB 6      //ENB

int motor_right_speed = 0;
int motor_left_speed = 0;

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you conect the controller, 
//or call config_gamepad(pins) again after connecting the controller.
int error = 0; 
byte type = 0;
byte vibrate = 0;

void setup(){

 // Configure output pins
 pinMode(ENA, OUTPUT);
 pinMode(MOTORA_1, OUTPUT);
 pinMode(MOTORA_2, OUTPUT);
 pinMode(ENB, OUTPUT);
 pinMode(MOTORB_1, OUTPUT);
 pinMode(MOTORB_2, OUTPUT);

 // Disable both motors
 digitalWrite(ENA,0);
 digitalWrite(ENB,0);

 // Start serial communication
 Serial.begin(57600);
  
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

 // Check for error
 if(error == 0){
  Serial.println("Found Controller, configured successful");
 }
   
 else if(error == 1)
  Serial.println("No controller found, check wiring or reset the Arduino");
   
 else if(error == 2)
  Serial.println("Controller found but not accepting commands");
  
 else if(error == 3)
  Serial.println("Controller refusing to enter Pressures mode, may not support it.");
   
 // Check for the type of controller
 type = ps2x.readType();
 switch(type) {
  case 0:
    Serial.println("Unknown Controller type");
    break;
  case 1:
    Serial.println("DualShock Controller Found");
    break;
  case 2:
    Serial.println("GuitarHero Controller Found");
    break;
  }
}

// Main loop
void loop(){
   
 if(error == 1) //skip loop if no controller found
  return; 
  
 else { //DualShock Controller
  
     ps2x.read_gamepad(false, vibrate); // disable vibration of the controller

    int nJoyL = ps2x.Analog(PSS_LX); // read left stick
    nJoyL = map(nJoyL, 0, 255, 1023, -1023);

    int motor_right_speed = 1023;
    int motor_left_speed = 1023;
    
    if (nJoyL < 0) {
      motor_right_speed = motor_right_speed + nJoyL;
    }
    if (nJoyL > 0) {
      motor_left_speed = motor_left_speed - nJoyL;
    }


    if(ps2x.Button(PSB_R2)) {
      digitalWrite(MOTORA_1,LOW);
      digitalWrite(MOTORA_2,HIGH);
      digitalWrite(MOTORB_1,HIGH);
      digitalWrite(MOTORB_2,LOW);      
      analogWrite(ENA, motor_right_speed);
      analogWrite(ENB, motor_left_speed);
    }
    if(ps2x.Button(PSB_L2)) {
      digitalWrite(MOTORA_1,HIGH);
      digitalWrite(MOTORA_2,LOW);
      digitalWrite(MOTORB_1,LOW);
      digitalWrite(MOTORB_2,HIGH);      
      analogWrite(ENA, motor_right_speed);
      analogWrite(ENB, motor_left_speed);
    }
    if(!ps2x.Button(PSB_L2) && !ps2x.Button(PSB_R2)) {
      analogWrite(ENA, 0);
      analogWrite(ENB, 0);    
    }
     
 delay(50);
 }    
}

when I turn on the controller and the battery , I can see both the leds on the receiver and the controller stop blinking, indicating that they are connected.
when I try to use the joystick or any button, nothing, literally nothing happens. I don't know what is wrong and would appreciate any help
thanks

start simple

remove the motors, connect only the PS2 receiver and modify the code to print the commands you receive. Ensure this works.

Once you have that fully working then add the motors

Hi,
Is it the same project?

If so, please don't duplicate our efforts....

Hey, It is the same project. I am new to the community, and still learning things. sorry for wasting your time.

Hello, do yourself a favour and please read How to get the best out of this forum

I merged both threads.

thanks. appreciate it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.