Arduino Mega2560 with Lynxmotion PS2 controller, running basic code to query the controller for buttons pushed and joystick movement. No motors or other shields attached, just doing query off the controller for now, delay of 200 at the of my main loop for reading the controller.
Problem: Getting sporadic readings off the output for the controller. ie: While the controller sits idle on my table:
Left: 127 Right : 127
Left: 127 Right : 127
Left: 127 Right : 127
Left: 255 Right : 255
Left: 127 Right : 127
Left: 127 Right : 127
Left: 127 Right : 127
This would result in any attached motors going bonkers. What’s up with my controller readings? Has my controller begun to fail?
Hi,
Could you please attach to your reply a copy of the code you are currently using and also one or more pictures of your current setup with the Arduino mega 2560?
Sincerely,
Apologies for the late reply. Wiring for the PS2 receiver and the Arduino Mega is pretty straightforward - power and ground plus all the other pins in that are listed in the PS2X definition below. And I should reiterate that these sporadic PS2 receiver readings have been a new development and I’ve had the same PS2 controller and receiver for over a year now (batteries also replaced in the controller). Code is:
[code]// PS2 controller definition
#include <PS2X_lib.h>
// 2017-05-12 - these pins are for use on Arduino Mega2560
#define PS2_DAT 53
#define PS2_CMD 52
#define PS2_SEL 51
#define PS2_CLK 49
PS2X ps2x; // create PS2 Controller Class
int LeftSpeed, RightSpeed, LeftController, RightController;
void setup() {
// debugging serial declaration
Serial.begin(9600);
// PS2 Controller setup
// Setup gamepad (clock, command, attention, data) pins
int error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT);
}
void loop() {
//read controller and set large motor to spin at ‘vibrate’ speed
ps2x.read_gamepad();
//read left controller joystick
LeftController = ps2x.Analog(PSS_LY);
//read right controller joystick
RightController = ps2x.Analog(PSS_RY);
//print the left and right controller values
Serial.print(“Left: “);
Serial.print(LeftController);
Serial.print(”\t Right : “);
Serial.print(RightController);
Serial.println(”\r”);
delay(125);
}[/code]