Issues with ps4 controler, USB host shield and arduino mega

I am building a robot car controlled by a ps4 controller. For this I've been using an arduino uno board and a usb host shield but since I realized I was going to need more D pins, I changed the board to an arduino Mega 2560. The code seems to upload flawlessly. However the board is not recieving info from the ps4 controller anymore. ¿Anyone knows why is this happening? Please help

An UNO uses Serial but the MEGA also has Serial1, Serial2 and Serial3.
Check what pins You are using.

I don't think that's is the problem, My code doesen't use serial for anything other than monitorized tests. ¿Or does it? ¿Would you be able to help me if I sent the code?

If You want serious suggestions and not wild guesses, what way do You think would work?
Schematics and code of course!

#include <Servo.h>
Servo SERVO_2;
int servo_position = 0 ;
////////////////////////////////////////////////////////////////////////////////MANDO
#include <PS4USB.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

USB Usb;
PS4USB PS4(&Usb);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;
////////////////////////////////////////////////////////////////////////////////Motores
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////SETUP
void setup(){
   SERVO_2.attach(9);
  
/////////////////////////////////////////////////////////////////////////////////Mando
Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); // Halt
  }
  Serial.print(F("\r\nPS4 USB Library Started"));
/////////////////////////////////////////////////////////////////////////////////Motores
  Serial.begin(9600);// Initiates the serial to do the monitoring 
  motor1.setSpeed(100);
  motor2.setSpeed(100);
  motor3.setSpeed(100);
  motor4.setSpeed(100);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////LOOP
void loop() {
  Mando();
  }
/////////////////////////////////////////////////////////////////////////////////Mando
void Mando(){
   Usb.Task();
  if (PS4.connected()) {
    if (PS4.getButtonClick(TRIANGLE)) {
      Serial.print(F("\r\nTriangle"));
        SERVO_2.write(180); 
    }else if (PS4.getButtonClick(CIRCLE)) {
      Serial.print(F("\r\nCircle"));
        SERVO_2.write(0); 
    }else if (PS4.getButtonClick(UP)) {
      Serial.print(F("\r\nUp"));
        motor1.run(FORWARD);
        motor2.run(FORWARD);
        motor3.run(FORWARD);
        motor4.run(FORWARD);
    }else if (PS4.getButtonClick(RIGHT)) {
      Serial.print(F("\r\nRight"));
        motor1.run(FORWARD);
        motor2.run(FORWARD);
        motor3.run(BACKWARD);
        motor4.run(BACKWARD);
    }else if (PS4.getButtonClick(DOWN)) {
      Serial.print(F("\r\nDown"));
        motor1.run(BACKWARD);
        motor2.run(BACKWARD);
        motor3.run(BACKWARD);
        motor4.run(BACKWARD);
    }else if (PS4.getButtonClick(LEFT)) {
      Serial.print(F("\r\nLeft"));
        motor1.run(BACKWARD);
        motor2.run(BACKWARD);
        motor3.run(FORWARD);
        motor4.run(FORWARD);
    }
  }
}

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