Giter Club home page Giter Club logo

arduino-ps2x's People

Contributors

knielsen avatar kurte avatar madsci1016 avatar srwiez avatar stefqm avatar thesourcerer8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-ps2x's Issues

Arduino PS2X module not working with PS1 controller

I have been trying to use the PS2X module to try to use my PS1 remote with my arduino (I am guessing that PS1 controllers will work because they are virtually the same ). The problem is that I don't want to download the module from the original website because it is not secure (it had HTTP instead of HTTPS) and the download file could contain viruses. Instead I got it off the arduino website. I have wired my controller correctly and have triple checked that all the wires are in the right positions and they seem to be. I then used the arduino example program given by the safely downloaded file. I complied it onto my arduino and I got the following message in the serial No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips Unknown Controller type. I then looked into the text file to debug it and it told me to uncomment 2 of the lines which is what I did. I then ran the example program file again like how the readme file told me to, and I still get the same errors.

How its supposed to be wired:

How I have wired it:

read if PS2 Controller was shut off intermediately (not) possible?

hello,
how can one read in loop() if PS2 Controller was shut off intermediately?
That might have happened manually, perhaps unintentionally, but after a while not having been touched the controler even apperars to shut off automatically, and that will cause severe damage of equipment, e.g. a robot arm ow a mobile robot.
I can see just the cmd lines in setup():
error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);
if(error == 0) { }

but how to verify the operating status in loop() repeatedly, safely? Is there sort of heartbeat?

Invalid Library

Having trouble including the library on arduino 1.8.5 so I cannot run the debug. Tried putting it in my program files x86 because I don't have an arduino file under any of my users, hardware/libraries had the same problem of not showing either. How are you guys including the library?

Specified folder/zip file does not contain a valid library
Invalid library found in C:\Program Files (x86)\Arduino\libraries\Arduino-PS2X-master: C:\Program Files (x86)\Arduino\libraries\Arduino-PS2X-master
Invalid library found in C:\Program Files (x86)\Arduino\libraries\Arduino-PS2X-master: C:\Program Files (x86)\Arduino\libraries\Arduino-PS2X-master

Controller refusing to enter Pressures mode, may not support it.

i have PS2 controller.
i'm not sure for the wiring, i've got
data : pin 12 + pull up 10K
cmd : pin 11
motor power : none
gnd : gnd
3.3 : 3.3v
att : pin 10
clk : pin 13
acknolege : pull up 10K

debug infos

OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:FF 43:73 0:5A 1:FF 0:FF
OUT:IN Configure
1:FF 44:F3 0:5A 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:FF 4D:F3 0:5A 0:FF 1:FF
OUT:IN Configure
1:FF 4F:F3 0:5A FF:0 FF:0 3:0 0:0 0:0 0:0
OUT:IN Configure
1:FF 43:F3 0:5A 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
Controller refusing to enter Pressures mode, may not support it.
GuitarHero Controller Found
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:87 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:73 0:5A 0:FF 0:FF 0:98 0:98 0:78 0:87 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0

can you help me please ?

Joysticks ohne Funktion ?

Hallo. Ich habe einen PS2 Wireless Controller genauso angeschlossen wie es für das Beispiel erforderlich ist. Alles mehrfach kontrolliert. Im seriellen Monitor kommt bei allen Tasten eine Ausgabebestätigung. Beim drücken der Joysticks kommt die Meldung da R3, bzw. L3 gedrückt wurde. Beim betätigen der Joysticks in X oder Y (egal ob rechts oder links) kommt im seriellen Monitor keine Ausgabe. Woran könnte das liegen ?

L2 always pressed

Using the example from here, the L2 button is always pressed and when I press it, it says up and right are pressed too...

Any help? maybe its because of my controller, dont know.

Not detecting ButtonReleased

Has anyone had issues capturing ButtonReleased event?

if (ps2x.ButtonReleased(PSB_PINK))
{ 
  Serial.println("Pink Released");
}

All the other buttons work, but no releases. Followed example - nothing tricky. Using latest build.

Need help

im trying to use this code, and im struggeling alot, i wanna use this code for a PS2 controller and Arduino Uno, i can upload the code etc, but where do i put servors/trusters pins? isent there are complete code out there, whit pin numbers, is this code even complete?
i only need a code for 3 truster and 2 joystick, and a button for light, i gonna build a ROV, but the code aint that easy to get..need help whit this please...

Car wheel controller support

I have a "Blaze Michael Schumacher GTR - Lenkrad (PS1,PS2)" steering wheel controller:

Booting ...
OUT:IN Configure
1:FC 43:1 0:10 1:FC 0:FF
OUT:IN Configure
1:0 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:0 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:10 43:43 0:0 1:0 0:0
OUT:IN Configure
1:85 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:0 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:0 43:43 0:0 1:4 0:0
OUT:IN Configure
1:D 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:0 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:0 43:43 0:0 1:4 0:0
OUT:IN Configure
1:D 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:20 43:63 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:0 43:43 0:0 1:0 0:0
OUT:IN Configure
1:1D 44:42 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:0 43:63 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN
1:1 42:43 0:0 0:0 0:4 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:0 43:43 0:0 1:18 0:0
OUT:IN Configure
1:5 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:41 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:4 43:43 0:0 1:0 0:2
OUT:IN Configure
1:85 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:89 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:0 43:43 0:0 1:0 0:0
OUT:IN Configure
1:5 44:40 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:31 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:0 43:43 0:0 1:0 0:0
OUT:IN Configure
1:41 44:42 0:0 1:0 3:0 0:0 0:0 0:0 0:0
OUT:IN Configure
1:51 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN Configure
1:40 43:43 0:0 1:0 0:6
OUT:IN Configure
1:9D 44:54 0:0 1:1 3:2 0:0 0:0 0:0 0:0
OUT:IN Configure
1:9 43:43 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
OUT:IN
1:80 42:42 0:0 0:0 0:10 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
Controller mode not matched or no controller found

Expected 0x41, 0x73 or 0x79, but got 42
No controller found, check wiring, see readme.txt to enable debug.
Visit www.billporter.info for troubleshooting tips
Unknown Controller type found

I'll try to provide a pull-request soon.

ps2 button problem

while upload this code,
when i press one button then it will print two button

Wrong Arduino pin assignment in example code: PS2X_Example.ino

https://github.com/madsci1016/Arduino-PS2X/blob/master/PS2X_lib/examples/PS2X_Example/PS2X_Example.ino

In the example code, the following mapping is shown (line 9 - 12):

#define PS2_DAT 13 //14
#define PS2_CMD 11 //15
#define PS2_SEL 10 //16
#define PS2_CLK 12 //17

This is to my understanding wrong for Arduino Uno R3. What is shown on the official pinout page:
https://content.arduino.cc/assets/Pinout-UNOrev3_latest.pdf

Should map to:

#define PS2_DAT 12 // D12 -> Controller In, Peripheral Out (CIPO) - The Peripheral line for sending data to the Controller (Arduino)
#define PS2_CMD 11 // D11 -> Controller Out Peripheral In (COPI) -> Commands from Controller to Peripheral (PS2 controller)
#define PS2_SEL 10 // D10 -> SS Slave Select
#define PS2_CLK 13 // D13 -> SCK Serial Clock

If I am correct, this might confuse users of the example code, even so it is commented with: replace pin numbers by the ones you use

Undefined setup() and loop()

I can't make PS2X_lib.cpp a library because Arduino says:

PS2X_lib.cpp:6: error: unterminated #else
#if ARDUINO > 22
^
exit status 1
unterminated #else

and for PS2X_lib.h, it says:

Archiving built core (caching) in: /var/folders/ps/0p5g4lb54152xx5zmb1h5k180000gn/T/arduino_cache_827109/core/core_arduino_avr_uno_cd6542aa3ca11c3dde011c642ad7cbf2.a
/var/folders/ps/0p5g4lb54152xx5zmb1h5k180000gn/T//cciOf0PX.ltrans0.ltrans.o: In function 'main':
/private/var/folders/ps/0p5g4lb54152xx5zmb1h5k180000gn/T/AppTranslocation/7956EF4A-5F6B-4626-B17F-4FD18720B300/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:43: undefined reference to 'setup'
/private/var/folders/ps/0p5g4lb54152xx5zmb1h5k180000gn/T/AppTranslocation/7956EF4A-5F6B-4626-B17F-4FD18720B300/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to 'loop'
collect2: error: ld returned 1 exit status
exit status 1

what am I suppose to do?

Dualshock vibration feature works only on motor1 while motor2 stands still (possible bug)

Hello community!
First of all, thank you all for this super library, I love it! Using this lib I've built an RC monster truck controlled by a wireless Dualshock 2 (not original copy). Now I want to add a feedback from RC model to controller, so I equipped my truck's receiver with a vibration sensor in order to make PS2 controller vibrate as strong as shaky the road surface is!

And it actually works however I noticed that controller vibrates only with motor1 while motor2 stands still. After a short research I found a suggestion to replace ps2x.read_gamepad(false, vibrate); with ps2x.read_gamepad(true, vibrate); to enable motor2. When I do so, motor2 keeps spinning at a constant speed indefinitely and I'm unable to control it by vibrate variable.

Digging deeper in PS2X_lib.cpp, it felt a bit strange that motor1 is controlled by a number 0..255 and motor2 is controlled by boolean true/false value.

Playing around with PS2X::read_gamepad(boolean motor1, byte motor2) function in PS2X_lib.cpp, I've replaced the string byte dword[9] = {0x01,0x42,0,motor1,motor2,0,0,0,0}; with byte dword[9] = {0x01,0x42,0,motor2,motor2,0,0,0,0};. So that boolean motor1 is ignored and byte motor2 value is sent to the controller as a "vibration strength" value for both motors. To my surprise, it worked and now my controller rumbles with both motors as strong as byte motor2 value is.

This is my first Arduino and GitHub experience, so I decided just to share my thoughts and result and may be contribute a bit to this cool library! Thanks for reading!

Joystick without Command line

Hi, I have a problem, my joystick is not original and has no command line. I want to know how I can do to modify the library or use it and to be able to communicate my arduino with the joystick

What does Serial.println(ps2x.Analog(PSS_LY), DEC); mean and how to use it?

I don't know much about arduino's c language so I am pretty confused on how to use the value printed in the serial monitor by the joystick of the ps2 controller ranging from 127 (for the Y and 128 for the X) in a neutral position to 255 and 0 in forward and reverse positions of the joystick.

I am building a soccer robot with hobby servos with 180 degrees of rotation and I want to vary the distance of each step by the degree of the joystick's position for example a 50 value would be divided by 127 and multiplied by a neutral position of 90 degrees to tell each motor to rotate in a pattern of ~35.5 degrees for a casual walking motion and if the value 255 were returned the robot would do a split or go into a full sprint or something along those lines.

I cannot figure out what Serial.println(ps2x.Analog(PSS_LY), DEC); means because when I made:
Serial.println(ps2x.Analog(90 * ((PSS_LY), DEC) /127)); the serial monitor would print a lot of 0's and 1's. I then tried several different versions of divisible and multiples with the most interesting results coming from dividing the subject only by .5 and being returned with values ranging from 0 to 2000 and dividing by the value 2 returning values of 0-67 with a high range of letters like CF and some other stuff. I thought this was just a serial print issue but I cannot get my servos to cooperate with this code at best getting the servos to only turn to low and neutral positions.

I also tried;
float x = (ps2x.Analog(PSS_LY), DEC);
Serial.println(x);
and got the strict result of 10 without any changes.

Do any of you have any thoughts on how to use this part of the ps2x library?

If it helps, this is what I use to control my servos at the moment:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define MIN_PULSE_WIDTH 500
#define MAX_PULSE_WIDTH 2500
#define DEFAULT_PULSE_WIDTH 1500
#define FREQUENCY 50

pwm.setPWM(0, 0, pulseWidth(0)); //Servo 0 set to angle 0 degrees
pwm.setPWM(1, 0, pulseWidth(180)); //Servo 1 set to angle 180 degrees

int pulseWidth(int angle) {
int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH,MAX_PULSE_WIDTH);
analog_value = int (float(pulse_wide) / 1000000 * FREQUENCY * 4096);
return analog_value;

/* I wasn't sure if there was a problem reading decimals so I changed all the ints to floats but that hasn't helped nor did any harm.

float pulseWidth(float angle) {
float pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH,MAX_PULSE_WIDTH);
analog_value = float (float(pulse_wide) / 1000000 * FREQUENCY * 4096);
return analog_value;
*/

License change

Hi,

the GPL license is pretty restrictive and does not work well with MIT / BSD etc.

Maybe you can consider at least LGPL?

Kind regards,
Sol

No Valid Library

Specified folder/zip file does not contain a valid library

The above error message is what I receive after downloading the zip and trying to place it in Arduino IDE. I've tried "include library" Add .zip library. I've tried to change the .h file to uncomment the suggested lines, but I can't "resave" the .h file on windows unless I save it as a .txt. I've tried dragging and dropping the library to the Arduino library folder. I still seem to get that above error message "Specified folder/zip file does not contain a valid library".

Library does not work with ESP32 -> Solved

Replace all Lines in PS2X_lib.h and PS2X_lib.cpp with definition for ESP8266
#ifdef ESP8266

by this line:
#if defined (ESP8266) || defined(ESP32)

Works now great with ESP32.
Thank you for this library!

Problem with Official Sony Controller, dreamGear Controller

Hey folks, a fantastic piece of work here. I've tried this out with three off-brand controllers and the example program works like clockwork. However, when I use an official Sony Playstation DualShock2 controller, I get no luck. I get the same problem when I use a dreamGear wired controller.

When Analog button on the controller is off i get this output.

1:FF 42:71 0:10 0:FE 0:FF 0:3 0:73 0:0 0:61 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
OUT:IN
1:FF 42:71 0:70 0:70 0:70 0:70 0:70 0:70 0:70 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
Controller mode not matched or no controller found
Expected 0x41 or 0x73, got 71
No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips
Unknown Controller type

When the Analog button is turned on, I get a lot of back and forth (happy to share) and then
"
Controller not accepting commands
mode stil set at71
"

Any idea what's going on? Maybe I'm doing something wrong in configuring it.

Controller works only with slow speed

Hello! I tried this library several times. The wiring was perfect. I'm using an Arduino Mega, tested the pins with a simple sketch to check if the Arduino was fault and everything worked fine. Tried 2 different PS2 controllers (a Sony's original and a clone) and both failed. I enabled the debug and the serial port throw "Expected 0x41 or 0x73, got 1". I disabled the internal pull-up and attached an external one (10k to 3.3v) without luck. But when I changed the speed (CTRL_CLK in PS2X_lib.h) from 4 to 20 it worked perfectly. I tried higher speeds (lower numbers) but doesn't work.

Probably this is not a bug from the library but wanted to share with you and other people with the same problem. Will be nice if you change the default value to a higher number and then the users lower it so the library will work for all without modification.

Regards,
Lucas

Random "All Buttons Pressed/Released" Tick

Hi!
I just got the whole PS2Controller+Reciever stuff for the Arduino and tried this along with its test code.
However, I noticed a weird bug? Where every new and then, the serial monitor will be spammed with every single button press/release message there is. And I'm not really sure why?
I tried it with several Arduinos I have (I have too many...) in fear that some may be broken, but that was not the case...
I followed the tutorial and guide to a Tee, and otherwise it works perfectly fine. Just that at least once or twice every thirty seconds everything seems to get pressed at once.

Cant' use SPI device

Hi,
The library worked great when I was sending fata over wifi through ESP8266 and serial. Now, I tried using NRF24L01 and SX1278 LoRa, which are SPI devices. As soon as I try to send anything, the ps2 controller is disabled. I am using an Arduino Micro. How could I fix this?

Example works with Uno but not with Arduino ZERO=M0 or DUE=M3

the lib seems to be bugged or outdated for ARM CORTEX Boards (M0=Zero, M3=Due and/or different ones like Adafruit M4):
your example code:


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

/******************************************************************
 * set pins connected to PS2 controller:
 *   - 1e column: original 
 *   - 2e colmun: Stef?
 * replace pin numbers by the ones you use
 ******************************************************************/
#define PS2_DAT        13  //14    
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17

/******************************************************************
 * select modes of PS2 controller:
 *   - pressures = analog reading of push-butttons 
 *   - rumble    = motor rumbling
 * uncomment 1 of the lines for each mode selection
 ******************************************************************/
//#define pressures   true
#define pressures   false
//#define rumble      true
#define rumble      false

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 connect the controller, 
//or call config_gamepad(pins) again after connecting the controller.

int error = 0;
byte type = 0;
byte vibrate = 0;

void setup(){
 
  Serial.begin(57600);
  
  delay(300);  //added delay to give wireless ps2 module some time to startup, before configuring it
   
  //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
  
  //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);
  
  if(error == 0){
    Serial.print("Found Controller, configured successful ");
    Serial.print("pressures = ");
	if (pressures)
	  Serial.println("true ");
	else
	  Serial.println("false");
	Serial.print("rumble = ");
	if (rumble)
	  Serial.println("true)");
	else
	  Serial.println("false");
    Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
    Serial.println("holding L1 or R1 will print out the analog stick values.");
    Serial.println("Note: Go to www.billporter.info for updates and to report bugs.");
  }  
  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
   
  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
  
//  Serial.print(ps2x.Analog(1), HEX);
  
  type = ps2x.readType(); 
  switch(type) {
    case 0:
      Serial.print("Unknown Controller type found ");
      break;
    case 1:
      Serial.print("DualShock Controller found ");
      break;
    case 2:
      Serial.print("GuitarHero Controller found ");
      break;
	case 3:
      Serial.print("Wireless Sony DualShock Controller found ");
      break;
   }
}

void loop() {
  /* You must Read Gamepad to get new values and set vibration values
     ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
     if you don't enable the rumble, use ps2x.read_gamepad(); with no values
     You should call this at least once a second
   */  
  if(error == 1) //skip loop if no controller found
    return; 
  
  if(type == 2){ //Guitar Hero Controller
    ps2x.read_gamepad();          //read controller 
   
    if(ps2x.ButtonPressed(GREEN_FRET))
      Serial.println("Green Fret Pressed");
    if(ps2x.ButtonPressed(RED_FRET))
      Serial.println("Red Fret Pressed");
    if(ps2x.ButtonPressed(YELLOW_FRET))
      Serial.println("Yellow Fret Pressed");
    if(ps2x.ButtonPressed(BLUE_FRET))
      Serial.println("Blue Fret Pressed");
    if(ps2x.ButtonPressed(ORANGE_FRET))
      Serial.println("Orange Fret Pressed"); 

    if(ps2x.ButtonPressed(STAR_POWER))
      Serial.println("Star Power Command");
    
    if(ps2x.Button(UP_STRUM))          //will be TRUE as long as button is pressed
      Serial.println("Up Strum");
    if(ps2x.Button(DOWN_STRUM))
      Serial.println("DOWN Strum");
 
    if(ps2x.Button(PSB_START))         //will be TRUE as long as button is pressed
      Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
      Serial.println("Select is being held");
    
    if(ps2x.Button(ORANGE_FRET)) {     // print stick value IF TRUE
      Serial.print("Wammy Bar Position:");
      Serial.println(ps2x.Analog(WHAMMY_BAR), DEC); 
    } 
  }
  else { //DualShock Controller
    ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed
    
    if(ps2x.Button(PSB_START))         //will be TRUE as long as button is pressed
      Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
      Serial.println("Select is being held");      

    if(ps2x.Button(PSB_PAD_UP)) {      //will be TRUE as long as button is pressed
      Serial.print("Up held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
    }
    if(ps2x.Button(PSB_PAD_RIGHT)){
      Serial.print("Right held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
    }
    if(ps2x.Button(PSB_PAD_LEFT)){
      Serial.print("LEFT held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
    }
    if(ps2x.Button(PSB_PAD_DOWN)){
      Serial.print("DOWN held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
    }   

    vibrate = ps2x.Analog(PSAB_CROSS);  //this will set the large motor vibrate speed based on how hard you press the blue (X) button
    if (ps2x.NewButtonState()) {        //will be TRUE if any button changes state (on to off, or off to on)
      if(ps2x.Button(PSB_L3))
        Serial.println("L3 pressed");
      if(ps2x.Button(PSB_R3))
        Serial.println("R3 pressed");
      if(ps2x.Button(PSB_L2))
        Serial.println("L2 pressed");
      if(ps2x.Button(PSB_R2))
        Serial.println("R2 pressed");
      if(ps2x.Button(PSB_TRIANGLE))
        Serial.println("Triangle pressed");        
    }

    if(ps2x.ButtonPressed(PSB_CIRCLE))               //will be TRUE if button was JUST pressed
      Serial.println("Circle just pressed");
    if(ps2x.NewButtonState(PSB_CROSS))               //will be TRUE if button was JUST pressed OR released
      Serial.println("X just changed");
    if(ps2x.ButtonReleased(PSB_SQUARE))              //will be TRUE if button was JUST released
      Serial.println("Square just released");     

    if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE
      Serial.print("Stick Values:");
      Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX  
      Serial.print(",");
      Serial.print(ps2x.Analog(PSS_LX), DEC); 
      Serial.print(",");
      Serial.print(ps2x.Analog(PSS_RY), DEC); 
      Serial.print(",");
      Serial.println(ps2x.Analog(PSS_RX), DEC); 
    }     
  }
  delay(50);  
}

Compilation for target Board Arduino DUE (Programming Port):

compile errors:

Arduino: 1.8.8 (Windows 7), Board: "Arduino Due (Programming Port)"

D:\arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\arduino\hardware -hardware D:\arduino\portable\packages -tools D:\arduino\tools-builder -tools D:\arduino\hardware\tools\avr -tools D:\arduino\portable\packages -built-in-libraries D:\arduino\libraries -libraries D:\arduino\portable\sketchbook\libraries -fqbn=arduino:sam:arduino_due_x_dbg -vid-pid=0X239A_0X8022 -ide-version=10808 -build-path C:\Users\hw\AppData\Local\Temp\arduino_build_721665 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.bossac.path=D:\arduino\portable\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.bossac-1.6.1-arduino.path=D:\arduino\portable\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.arm-none-eabi-gcc.path=D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -verbose D:\arduino\portable\sketchbook\libraries\PS2X_lib\examples\PS2X_Example\PS2X_Example.ino
D:\arduino\arduino-builder -compile -logger=machine -hardware D:\arduino\hardware -hardware D:\arduino\portable\packages -tools D:\arduino\tools-builder -tools D:\arduino\hardware\tools\avr -tools D:\arduino\portable\packages -built-in-libraries D:\arduino\libraries -libraries D:\arduino\portable\sketchbook\libraries -fqbn=arduino:sam:arduino_due_x_dbg -vid-pid=0X239A_0X8022 -ide-version=10808 -build-path C:\Users\hw\AppData\Local\Temp\arduino_build_721665 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.bossac.path=D:\arduino\portable\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.bossac-1.6.1-arduino.path=D:\arduino\portable\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.arm-none-eabi-gcc.path=D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -verbose D:\arduino\portable\sketchbook\libraries\PS2X_lib\examples\PS2X_Example\PS2X_Example.ino
Using board 'arduino_due_x_dbg' from platform in folder: D:\arduino\portable\packages\arduino\hardware\sam\1.6.11
Using core 'arduino' from platform in folder: D:\arduino\portable\packages\arduino\hardware\sam\1.6.11

Detecting libraries used...
"D:\\arduino\\portable\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10808 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/libsam" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/CMSIS/Include/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/Device/ATMEL/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\cores\\arduino" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\variants\\arduino_due_x" "C:\\Users\\hw\\AppData\\Local\\Temp\\arduino_build_721665\\sketch\\PS2X_Example.ino.cpp" -o nul
"D:\\arduino\\portable\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10808 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/libsam" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/CMSIS/Include/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/Device/ATMEL/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\cores\\arduino" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\variants\\arduino_due_x" "-ID:\\arduino\\portable\\sketchbook\\libraries\\PS2X_lib" "C:\\Users\\hw\\AppData\\Local\\Temp\\arduino_build_721665\\sketch\\PS2X_Example.ino.cpp" -o nul
"D:\\arduino\\portable\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10808 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/libsam" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/CMSIS/Include/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\system/CMSIS/Device/ATMEL/" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\cores\\arduino" "-ID:\\arduino\\portable\\packages\\arduino\\hardware\\sam\\1.6.11\\variants\\arduino_due_x" "-ID:\\arduino\\portable\\sketchbook\\libraries\\PS2X_lib" "D:\\arduino\\portable\\sketchbook\\libraries\\PS2X_lib\\PS2X_lib.cpp" -o nul
D:\arduino\portable\sketchbook\libraries\PS2X_lib\PS2X_lib.cpp:5:20: fatal error: avr/io.h: No such file or directory

 #include <avr/io.h>

                    ^

compilation terminated.

Bibliothek PS2X_lib im Ordner: D:\arduino\portable\sketchbook\libraries\PS2X_lib (legacy) wird verwendet
exit status 1
Fehler beim Kompilieren für das Board Arduino Due (Programming Port).

would you please kindly fix that?

the lib no longer works with any of my radios

Good morning,

Thanks for your library! I used it on one of my robots a few years ago. I left with the same hardware on a new project. The lib no longer works on my project no longer works, neither do the examples in the lib...

The remote control is properly connected to the receiver, the lights are on. But I still have the same error message on the serial monitor:

"No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips
controller_type: 0
Unknown Controller type found"

I tried with 4 identical remote control in my possession. I checked the wiring and I tested on two 2560s and an Uno. I still have the same message on the serial port.

I hope we can quickly find the problem and that I can reuse your lib :)

ESP32 support

Hi Bill,
I'm not sure if you still keep an eye on comments here but thought this the best way to reach you now that I can't leave a comment on your webpage.
I was running into issues using your code, partially due to issues I was having with my wiring but also I think because I'm using an ESP32 rather than an Arduino Uno.
I found a fork of your code here:
https://github.com/MyArduinoLib/Arduino-PS2X-ESP32/tree/master
where the only difference is everywhere you make a condition for the ESP8266 in the PS2X_lib.cpp and PS2X_lib.h it's been changed to also reference the ESP32. So lines
#ifdef ESP8266
become
#if defined(ESP8266) || defined(ESP32)
It's only a minor change and now I've fixed my wiring I've not gone back to see if that's the sole cause of the error but I thought you might want to know. That or it may be useful to someone else to see what I've discovered.
Thanks for the great library, I love it.
Many thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.