Script works on Mega but not Uno

Hey guys, I’m struggling to get a script to work on an Uno that I’ve had working on a Mega.

I just bought the Uno and something doesnt seem right about how Arduino’s IDE responds to it as opposed to the Mega (see the pics I’ve attached). They are both copies but Arduino seems to retreive more info on the Mega.

I’ve installed the driver from wch.hn and it appears in the device manager as being installed okay. The ‘Blink’ example seems to work fine on the Uno though.

The script uploads to the Uno fine and recognises the controller as per the error message section but the wheels of the model don’t turn. The script I’ve used was made for an Uno and as I said the script worked fine on the Mega this morning and I’ve changed it back since not being able to get it to work and it’s still okay on the Mega.

Any help is much appreciated.

P/S I should add that the RX LED is blinking every half second when I’m using external power.

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

#define PS2_DAT        12      
#define PS2_CMD        11  
#define PS2_SEL        10  
#define PS2_CLK        9  

#define leftm1     3
#define leftm2     4
#define rightm1    5
#define rightm2    6
#define left_EN    2
#define right_EN   7

  //analog values read from PS2 joysticks
int LX = 0;                   
int LY = 0;
int RX = 0;
int RY = 0;

//#define pressures   true
#define pressures   false
#define rumble      true
//#define rumble      false

PS2X ps2x; // create PS2 Controller Class

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


void setup() {

  Serial.begin(9600);

  pinMode(leftm1,  OUTPUT);
  pinMode(leftm2,  OUTPUT);
  pinMode(rightm1, OUTPUT);
  pinMode(rightm2, OUTPUT);
  pinMode(left_EN, OUTPUT);
  pinMode(right_EN, OUTPUT);

  digitalWrite(left_EN, LOW);
  digitalWrite(right_EN, LOW);

  delay(300);  //added delay to give wireless ps2 module some time to startup, before configuring it

  //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 ");
  }
  else if (error == 1)
    Serial.print("No controller found, check wiring. ");

  else if (error == 2)
    Serial.print("Controller found but not accepting commands. ");

  else if (error == 3)
    Serial.print("Controller refusing to enter Pressures mode, may not support it. ");
}

void loop() {
  ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed
  
  if (ps2x.Button(PSB_L1))
  {
    LY = ps2x.Analog(PSS_LY);                     //receive values from p22 joystick
    LX = ps2x.Analog(PSS_LX);
  }
  if (ps2x.Button(PSB_R1))
  {
    RY = ps2x.Analog(PSS_RY);
    RX = ps2x.Analog(PSS_RX);
  }

  if (LY > 200 || RY > 200)                       //check if the joystick pushed up side
  {
    REV();
  }
  if (LY < 100 || RY < 100)
  {
    forward();
  }
  if (LX < 100 || RX < 100)
  {
    left();
  }
  if (LX > 200 || RX > 200)
  {
    right();
  }
  if(LX == 128 && LY == 128 && RX == 128 && RY == 128)
  {
    waithere();
  }

LY = LX = 128;         //return to default vlaues
RY = RX = 128;         //return to default values
}

void forward()
{
  //Serial.print("forward");
  digitalWrite(left_EN, HIGH);
  digitalWrite(right_EN, HIGH);

  digitalWrite(leftm1, HIGH);
  digitalWrite(leftm2, LOW);
  digitalWrite(rightm1, HIGH);
  digitalWrite(rightm2, LOW);

}
void REV()
{
  //Serial.print("rev");
  digitalWrite(left_EN, HIGH);
  digitalWrite(right_EN, HIGH);

  digitalWrite(leftm1, LOW);
  digitalWrite(leftm2, HIGH);
  digitalWrite(rightm1, LOW);
  digitalWrite(rightm2, HIGH);
}
void left()
{
  //Serial.print("left");
  digitalWrite(left_EN, LOW);
  digitalWrite(right_EN, HIGH);

  digitalWrite(leftm1, LOW);
  digitalWrite(leftm2, LOW);
  digitalWrite(rightm1, HIGH);
  digitalWrite(rightm2, LOW);

}
void right()
{
  //Serial.print("right");
  digitalWrite(left_EN, HIGH);
  digitalWrite(right_EN, LOW);

  digitalWrite(rightm1, LOW);
  digitalWrite(rightm2, LOW);
  digitalWrite(leftm1, HIGH);
  digitalWrite(leftm2, LOW);
}
void waithere()
{
  //Serial.print("stop");
  digitalWrite(left_EN, LOW);
  digitalWrite(right_EN, LOW);
  digitalWrite(rightm1, LOW);
  digitalWrite(rightm2, LOW);
  digitalWrite(leftm1, LOW);
  digitalWrite(leftm2, LOW);
}

Pin definition on Mega & Uno are different. Especially the Serial Ports and CLK etc.

dr-o:
Pin definition on Mega & Uno are different. Especially the Serial Ports and CLK etc.

The script has come from a project that uses an Uno, I've not changed anything, so it should work?

model controller

Oh oh I see... You should write, that you are very new to programming. Since people dont know your background, they assume you have some knowledge. If you let people know, they tend to help differently, being more productive.

The whole #define Part of your Software is Pin definition. The pins on Uno and Mega are different. Therefore you have to check the documentation of Mega (google) to find the pins and change them to the numbers you require for Mega.

Have a great one.

fwazz89:
The script has come from a project that uses an Uno, I've not changed anything, so it should work?

If it works on your Mega but not on your Uno then the piece I have highlighted must be an error - or else you have connected something incorrectly.

...R