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.