interface arduino wifi shield v2.2 and visual basic

Greeting everyone
I'm doing a project of controlling robot(left,right,backward and forward).using:
1. visual basic6 command to control robot
2. connection through arduino wifi shield v2.2
3.progarmming using arduino
I have set the AT command for wifi shield correctly and can work.
the robot should be controlled throughout Visual basic 6(GUI for controlling motion) using keyboard.
in Visual basic6 i used winsock over TCP/IP connection in order to connect to wifi shield and execute the motion.
currently, i stuck how to make interfacing between arduino and visual basic 6,
bellow all programming that i hv been done,hope i can get help.
I'm doing a project of controlling robot(left,right,backward and forward).using:
1. visual basic6 command to control robot
2. connection through arduino wifi shield v2.2
3.progarmming using arduino
I have set the AT command for wifi shield correctly and can work.
the robot should be controlled throughout Visual basic 6(GUI for controlling motion) using keyboard.
in Visual basic6 i used winsock over TCP/IP connection in order to connect to wifi shield and execute the motion.
currently, i stuck how to make interfacing between arduino and visual basic 6,
bellow all programming that i hv been done,hope i can get help.
2014-03-31 22:48:25 Hello Salem,
I am not familiar with VB, sorry.
But i guess you could test with Telnet first for the commands and the move them on your VB code.
Jose
I am not familiar with VB, sorry.
But i guess you could test with Telnet first for the commands and the move them on your VB code.

2014-03-29 08:28:38 yes, that has been done
the main problem is with arduino wifi shield v2.2
need to transfer the command wireless,,
i have been set the AT command ,but i couldnt figure out how to translate that command to accept comming data from Visual basic 6,pls read the code and tell me if any correction
salem89
the main problem is with arduino wifi shield v2.2
need to transfer the command wireless,,
i have been set the AT command ,but i couldnt figure out how to translate that command to accept comming data from Visual basic 6,pls read the code and tell me if any correction

2014-03-29 02:20:35 you could try to send some data from VB to your arduino first. and check with software serial, or LED
Jose

2014-03-29 02:18:27 arduino sketch
//Standard PWM DC control
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance(char a,char b) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
Serial.begin(115200); //Set Baud Rate
Serial.println("Run keyboard control");
}
void loop(void)
{
if(Serial.available()){
char val = Serial.read();
if(val != -1)
{
switch(val)
{
case 'W'://Move Forward
advance (255,255); //move forward in max speed
break;
case 'S'://Move Backward
back_off (255,255); //move back in max speed
break;
case 'A'://Turn Left
turn_L (100,100);
break;
case 'D'://Turn Right
turn_R (100,100);
break;
}
}
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
visual basic 6
Option Explicit
Public direction As String
Public ttime As Integer
Public address As String
Public upstatus, downstatus, leftstatus, rightstatus, hornstatus As Integer
Public output As Integer
Private Sub call_timer_Timer()
Call motion("manual", upstatus + downstatus + rightstatus + leftstatus + hornstatus)
'Calls motion module. Lets it know manual driving and what value to output to the
'parallel port
End Sub
Private Sub Command1_Click()
If sock.State = sckClosed Then ' if the socket is closed
sock.RemoteHost = lbladdress.Text ' set server adress
sock.RemotePort = "1500" ' set server port
Label5.Caption = "Connected"
sock.Connect ' start connection attempt
Else ' if the socket is open
sock.Close ' close it
Label5.Caption = "Not Connected"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Detects if control keys are pressed
If KeyCode = vbKeyEscape Then End 'Exits
If KeyCode = vbKeyC Then Call Command1_Click
If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then: cmd_up.BackColor = &HFF0000: cmd_up.Picture = cmd_up.DownPicture: upstatus = 6
'If up arrow is pressed or W then change pictures (make it blue) and change upstatus.
If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFF0000: cmd_down.Picture = cmd_down.DownPicture: downstatus = 9
'If down arrow is pressed or S then change pictures (make it blue) and change downstatus.
If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFF0000: cmd_left.Picture = cmd_left.DownPicture: rightstatus = 5
'If left arrow is pressed or A then change pictures (make it blue) and change rightstatus.
If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFF0000: cmd_right.Picture = cmd_right.DownPicture: leftstatus = 10
'If right arrow is pressed or D then change pictures (make it blue) and change leftstatus.
If KeyCode = vbKeyH Then hornstatus = 32
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'Stops output to that direction when key is lifted.
'Changes pictures back to unactivated (none-blue).
If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then cmd_up.BackColor = &HFFFFFF: cmd_up.Picture = cmd_up.DisabledPicture: upstatus = 0
If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFFFFFF: cmd_down.Picture = cmd_down.DisabledPicture: downstatus = 0
If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFFFFFF: cmd_left.Picture = cmd_left.DisabledPicture: rightstatus = 0
If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFFFFFF: cmd_right.Picture = cmd_right.DisabledPicture: leftstatus = 0
If KeyCode = vbKeyH Then hornstatus = 0
End Sub
Private Sub Form_Load()
Dim line As String
'Stores {Arrow with white} pic in .DisabledPicture for each button
cmd_up.DisabledPicture = cmd_up.Picture
cmd_down.DisabledPicture = cmd_down.Picture
cmd_left.DisabledPicture = cmd_left.Picture
cmd_right.DisabledPicture = cmd_right.Picture
'Following Opens Config.txt and collect Parallel Port Address and Refresh Rate
Open CurDir & "\config.txt" For Input As #1
Line Input #1, line
Line Input #1, line
address = line 'Sets parallel port address
lbladdress.Text = address 'displays address
call_timer.Interval = 5
End Sub
Private Sub sock_Close()
sock.Close ' has to be
End Sub
Private Sub sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Socket Error " & Number & ": " & Description
sock.Close ' close the erraneous connection
End Sub
'Motion Executor
Sub motion(direction As String, ttime As Integer)
address = Form1.address
Select Case direction
Case 1 To 6
Case "manual"
'If manual driving, parallel port output required for direction has already
'been calculated, so output value passed to ttime
output = ttime
Case "FF"
output = 1
Case "BB"
output = 2
Case "RR"
output = 8
Case "LL"
output = 4
Case "SS"
output = 0
End Select
Rem vbOut address, output
'sock.SendData output & Chr(0)
If sock.State = sckConnected Then
If output = &HC Or output = &H1C Then output = output - 8
If output = &H3 Or output = &H13 Then output = output - 2
sock.SendData Chr(output + 1) & Chr(0)
Label5.Caption = Chr(output + 1) & Chr(0)
Else
Label5.Caption = "NOT sending data"
End If
End Sub
salem89
//Standard PWM DC control
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance(char a,char b) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
Serial.begin(115200); //Set Baud Rate
Serial.println("Run keyboard control");
}
void loop(void)
{
if(Serial.available()){
char val = Serial.read();
if(val != -1)
{
switch(val)
{
case 'W'://Move Forward
advance (255,255); //move forward in max speed
break;
case 'S'://Move Backward
back_off (255,255); //move back in max speed
break;
case 'A'://Turn Left
turn_L (100,100);
break;
case 'D'://Turn Right
turn_R (100,100);
break;
}
}
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
visual basic 6
Option Explicit
Public direction As String
Public ttime As Integer
Public address As String
Public upstatus, downstatus, leftstatus, rightstatus, hornstatus As Integer
Public output As Integer
Private Sub call_timer_Timer()
Call motion("manual", upstatus + downstatus + rightstatus + leftstatus + hornstatus)
'Calls motion module. Lets it know manual driving and what value to output to the
'parallel port
End Sub
Private Sub Command1_Click()
If sock.State = sckClosed Then ' if the socket is closed
sock.RemoteHost = lbladdress.Text ' set server adress
sock.RemotePort = "1500" ' set server port
Label5.Caption = "Connected"
sock.Connect ' start connection attempt
Else ' if the socket is open
sock.Close ' close it
Label5.Caption = "Not Connected"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Detects if control keys are pressed
If KeyCode = vbKeyEscape Then End 'Exits
If KeyCode = vbKeyC Then Call Command1_Click
If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then: cmd_up.BackColor = &HFF0000: cmd_up.Picture = cmd_up.DownPicture: upstatus = 6
'If up arrow is pressed or W then change pictures (make it blue) and change upstatus.
If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFF0000: cmd_down.Picture = cmd_down.DownPicture: downstatus = 9
'If down arrow is pressed or S then change pictures (make it blue) and change downstatus.
If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFF0000: cmd_left.Picture = cmd_left.DownPicture: rightstatus = 5
'If left arrow is pressed or A then change pictures (make it blue) and change rightstatus.
If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFF0000: cmd_right.Picture = cmd_right.DownPicture: leftstatus = 10
'If right arrow is pressed or D then change pictures (make it blue) and change leftstatus.
If KeyCode = vbKeyH Then hornstatus = 32
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'Stops output to that direction when key is lifted.
'Changes pictures back to unactivated (none-blue).
If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then cmd_up.BackColor = &HFFFFFF: cmd_up.Picture = cmd_up.DisabledPicture: upstatus = 0
If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFFFFFF: cmd_down.Picture = cmd_down.DisabledPicture: downstatus = 0
If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFFFFFF: cmd_left.Picture = cmd_left.DisabledPicture: rightstatus = 0
If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFFFFFF: cmd_right.Picture = cmd_right.DisabledPicture: leftstatus = 0
If KeyCode = vbKeyH Then hornstatus = 0
End Sub
Private Sub Form_Load()
Dim line As String
'Stores {Arrow with white} pic in .DisabledPicture for each button
cmd_up.DisabledPicture = cmd_up.Picture
cmd_down.DisabledPicture = cmd_down.Picture
cmd_left.DisabledPicture = cmd_left.Picture
cmd_right.DisabledPicture = cmd_right.Picture
'Following Opens Config.txt and collect Parallel Port Address and Refresh Rate
Open CurDir & "\config.txt" For Input As #1
Line Input #1, line
Line Input #1, line
address = line 'Sets parallel port address
lbladdress.Text = address 'displays address
call_timer.Interval = 5
End Sub
Private Sub sock_Close()
sock.Close ' has to be
End Sub
Private Sub sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Socket Error " & Number & ": " & Description
sock.Close ' close the erraneous connection
End Sub
'Motion Executor
Sub motion(direction As String, ttime As Integer)
address = Form1.address
Select Case direction
Case 1 To 6
Case "manual"
'If manual driving, parallel port output required for direction has already
'been calculated, so output value passed to ttime
output = ttime
Case "FF"
output = 1
Case "BB"
output = 2
Case "RR"
output = 8
Case "LL"
output = 4
Case "SS"
output = 0
End Select
Rem vbOut address, output
'sock.SendData output & Chr(0)
If sock.State = sckConnected Then
If output = &HC Or output = &H1C Then output = output - 8
If output = &H3 Or output = &H13 Then output = output - 2
sock.SendData Chr(output + 1) & Chr(0)
Label5.Caption = Chr(output + 1) & Chr(0)
Else
Label5.Caption = "NOT sending data"
End If
End Sub
