Hello everyone,
I'm currently working on a project that involves controlling the direction of two motors mounted on a chasis over wifi. It's like a wireless "tank" but I'm having problems when I try to send data to the wifly shield. The Wifly shield (RN-131C) is connected to a Arduino UNO R3 that has a Motor shield R3 to control the two motors mentioned before. The sketch I designed works perfectly with the Arduino conected to the computer with an USB cable, and it uses the letters "W, A, S, D" of the keyboard to move in a specific direction. I use the hyperterminal and it works fine.
Now, my goal is, to make everything wirless and to be able to send the command (one of the letters) over the wifi and the vehicle should go to that direction, but I don't have a clue where to start. For now I managed to autoconnect the Wifly to my wifi network, but I can't connect to it because I don't know the IP adress, I think there's a command to set the IP to whatever I want, but I don't know it. Also I have searched for something similar to read the serial available for the Spi but I haven't found anything.
Here's the code That works without wifi connection, only through USB cable:
void setup()
{
int a;
for (a=5; a<=8; a++)
pinMode (a, OUTPUT);
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
while (Serial.available() < 1) {} // Wait until a character is received
char val = Serial.read();
int leftspeed = 150; //255 is maximum speed
int rightspeed = 150;
switch(val) // Perform an action depending on the command
{
case 'w'://Move Forward
forward (leftspeed,rightspeed);
break;
case 's'://Move Backwards
reverse (leftspeed,rightspeed);
break;
case 'a'://Turn Left
left (leftspeed,rightspeed);
break;
case 'd'://Turn Right
right (leftspeed,rightspeed);
break;
default:
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
break;
}
}
void forward(char a,char b)
{
digitalWrite(12, LOW);
analogWrite(3, 100);
digitalWrite(13, HIGH);
analogWrite(11, 100);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
}
void reverse (char a,char b)
{
digitalWrite(12, HIGH);
analogWrite(3, 100);
digitalWrite(13, LOW);
analogWrite(11, 100);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
}
void left (char a,char b)
{
digitalWrite(12, LOW);
analogWrite(3, 100);
digitalWrite(13, LOW);
analogWrite(11, 100);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
}
void right (char a,char b)
{
digitalWrite(12, HIGH);
analogWrite(3, 100);
digitalWrite(13, HIGH);
analogWrite(11, 100);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
}