Arduino-PS2X icon indicating copy to clipboard operation
Arduino-PS2X copied to clipboard

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

Open maxbambucha opened this issue 5 years ago • 1 comments

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!

maxbambucha avatar Jan 21 '20 18:01 maxbambucha

Thanks for your sharing. I also encounter this problem recently.It helps me a lot

Oakshen avatar May 13 '21 11:05 Oakshen