A wireless rover using Yun & Processing?

Hi guys, a noobie here.

I've built a tethered rover with 2 wheels and controlled it with the Uno. I got the Yun and set up and running on the network. Now when I try to use the Arduino sketch and processing code i used on the Uno on the Yun, it isn't working.

Arduino sketch and processing code.

int motorPin1 = 12;
int motorPin2 = 13;
int motorPin3 = 3;
int motorPin4 = 11;
void setup(){
  Serial.begin(9600);
//setup channel A, left wheel
pinMode(motorPin1, OUTPUT); //forward
  pinMode(motorPin3, OUTPUT);  //backwards
 //setup channel B, right wheel
  pinMode (motorPin2, OUTPUT); //forward
  pinMode (motorPin4, OUTPUT); //backwards
}
//Analog write left motor = 3 = A
//Analog write right motor = 11 = B
void loop(){

}

void serialEvent(){
    int input = Serial.read();
    if(input == 1){ //forward
      digitalWrite(motorPin1,HIGH);
      digitalWrite(motorPin2,HIGH);
      analogWrite(3, 255);
      analogWrite(11,255);
    }
    else if(input == 2){ //backwards
      digitalWrite(motorPin1,LOW);
      digitalWrite(motorPin2,LOW);
      analogWrite(3,255);
      analogWrite(11,255);
    }
    else if(input == 4){ //turn left
      digitalWrite(motorPin1,HIGH);
      analogWrite(11, 255);
    }
    else if(input == 3){ //turn right
      digitalWrite(motorPin2,HIGH);
      analogWrite(3, 255);
    }
    else if(input == 5){ //turn backwards right
      digitalWrite(motorPin3,LOW);
      analogWrite(3, 255);
    }
    else if(input == 6){ //turn backwards left 
      digitalWrite(motorPin4,LOW);
      analogWrite(11, 255);
    }
    else if(input == 7){ //forward stop
      digitalWrite(motorPin1,LOW);
      digitalWrite(motorPin2,LOW);
      analogWrite(11,0);
      analogWrite(3,0);
    }
    else if(input == 8){ //backwards stop
      digitalWrite(motorPin3,LOW);
      digitalWrite(motorPin4,LOW);
      analogWrite(11,0);
      analogWrite(3,0);
    }
    else if(input == 9){ //forward left stop
      digitalWrite(motorPin3,LOW);
      analogWrite(11,0);
    }
    else if(input == 10){ //forward right stop
      digitalWrite(motorPin4,LOW);
      analogWrite(3,0);
    }
    else if(input == 11){ //backwards left stop
      digitalWrite(motorPin3,HIGH);
      analogWrite(3,0);
      analogWrite(11,0);
    }
    else if(input == 12){ //backwards right stop
      digitalWrite(motorPin4,HIGH);
      analogWrite(11,0);
      analogWrite(3,0);
    }
}
import processing.serial.*;
Serial myPort;

void setup(){
  println("The available ports are: ");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[2],9600);
  myPort.buffer(64);
  size(500, 500);
}

void draw(){
  if(keyPressed){
    if(key == 'w' || key == 'W'){
      myPort.write(1);
      println("forward");
    }
    else if(key == 'S' || key == 's'){
      myPort.write(2);
      println("backward");
    }
    else if(key == 'a' || key == 'A'){
      myPort.write(3);
      println("left");
    }
    else if(key == 'd' || key == 'D'){
      myPort.write(4);
      println("right");
    }
    else if(key == 'e' || key == 'E'){
      myPort.write(5);
      println("backwards right");
    }
    else if(key == 'q' || key == 'Q'){
      myPort.write(6);
      println("backwards left");
    }
  }

}

void keyReleased(){
 if(key == 'w' || key == 'W'){
      myPort.write(7);
      println("forward stop");
    }
    else if(key == 's' || key == 'S'){
      myPort.write(8);
      println("backward stop");
    }
    else if(key == 'a' || key == 'A'){
      myPort.write(9);
      println("Turn left stop");
    }
    else if(key == 'd' || key == 'D'){
      myPort.write(10);
      println("Turn right stop");
    }
    else if(key == 'q' || key == 'Q'){
      myPort.write(11);
      println("Turn left stop");
    }
    else if(key == 'e' || key == 'E'){
      myPort.write(12);
      println("Turn right stop");
    }

  println("released");
}

I've got the rover working using the Uno using them. It's tethered, but I want it wireless. I thoguht that if I use the codes on the Uno and switched it to the Yun, it would work. Am I wrong? Some help would be nice.

Cookizai:
Hi guys, a noobie here.

I've built a tethered rover with 2 wheels and controlled it with the Uno. I got the Yun and set up and running on the network. Now when I try to use the Arduino sketch and processing code i used on the Uno on the Yun, it isn't working.

::::SNIP::::

I've got the rover working using the Uno using them. It's tethered, but I want it wireless. I thoguht that if I use the codes on the Uno and switched it to the Yun, it would work. Am I wrong? Some help would be nice.

Cookizai,
I'm puzzled by your code. I see strange things.

  1. two separate code files
  2. a loop() that does nothing.
  3. a library call i have not seen before size()

if you can explain more about your code, may be someone could help.

Jesse

Cookizai:
I've got the rover working using the Uno using them. It's tethered, but I want it wireless. I thoguht that if I use the codes on the Uno and switched it to the Yun, it would work. Am I wrong? Some help would be nice.

If I understand it right, this sketch receives serial commands from this processing code over the Uno's USB connection, right? If you move the code as-is, it should work the same way, using the Yun's USB connection. Does it?

But want you want to do is control it wirelessly. Just using the Yun doesn't magically make it wireless, you will have to make some significant changes to the code to replace the serial communications with network communications. There are several ways to do it on the Yun side, but you will have to find out what can be done in Processing on the PC side. You will have to find a capability that is shared by both environments. I've never used Processing, so I have no idea about its networking abilities (if it even has any.)