Controlling the RC car using Visual Basic 6

I am back again with my next post. This post is about controlling the RC car using the Visual Basic 6. There are also several programs that you can control RC car with but I have chosen Visual Basic because I am little bit de javu in Visual Basic.

If you are directly linked to this page then I prefer you to read my rest of the articles as well because this post will be worthless to you if you ignore these two previous post.
1. Parallel port interfacing
2. Hacking the RC car

In my first post on Parallel port interfacing I’ve already mentioned you about the basic coding part here is the short extract from it.

 

If you are using XP you’ll need separate file to communicate with parallel port as later version of windows doesn’t allows you to communicate with the parallel port directly.

You’ll need to download this DLL file, Click here to download.

After you downloaded search for inpout32.dll in the windows explorer in the directory where you’ve downloaded the file and then Copy and Paste it to c:/windows/system32 and also to c:/windows/system32/driver. Ok you are now done.

Now the programming part,

First make a new exe project in Visual Basic 6. Then declare the following function to the form.

 

Private Declare Function Inp Lib “inpout32.dll” _
Alias “Inp32” (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib “inpout32.dll” _
Alias “Out32” (ByVal PortAddress As Integer, ByVal Value As Integer)

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Out 888, 1

End sub

 

Are you newbie on Visual Basic? Don’t worry my friend just copy the above codes. Let me teach you what the above code does.

 

Private Declare Function Inp Lib “inpout32.dll” _
Alias “Inp32” (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib “inpout32.dll” _
Alias “Out32” (ByVal PortAddress As Integer, ByVal Value As Integer)

 

 

 

 

These codes calls inpout32.dll from the system folder which helps Visual basic to communicate with the parallel port.

 

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Out 888, 1

End sub

These codes enables you to send data to parallel port. “Out” is for output, 888 is the parallel port address and 1 is the data pin address.

For better result and easy process you’ll have to connect the wires from the positive of transistor with the parallel port serially i.e. Up= pin 2, Down= pin 3 Left=pin 4 Right=pin 5.
If you properly checked the connection then you’ll have no problem in programming.

Now the hardware part modification is completely finished.

Well lets go again for the programming part. Easy as 123, just copy and paste the following code in to Visual basic form. After creating form put Label1, Label2, Label3, Label4, Label5, Label6, Label7, Label8 and Label9 in separate places without overlapping, this is optional. It only shows you which function was pressed.

Private Declare Function Inp Lib “inpout32.dll” _
Alias “Inp32” (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib “inpout32.dll” _
Alias “Out32” (ByVal PortAddress As Integer, ByVal Value As Integer)

Dim Port1 As Integer

‘End Sub
‘ PORTS are 1,2,4,8,16,32,64,128 all glow is 255
‘ ()
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyNumpad8 Then
Port1 = 888
Out Port1, 8
Label1 = “UP”
End If
If KeyCode = vbKeyNumpad4 Then
Port1 = 888
Out Port1, 2
Label4 = “LEFT”
End If

If KeyCode = vbKeyNumpad7 Then
Port1 = 888
Out Port1, 10
Label2 = “UP-LEFT”
End If
If KeyCode = vbKeyNumpad9 Then
Port1 = 888
Out Port1, 12
Label6 = “UP-RIGHT”
End If

If KeyCode = vbKeyNumpad2 Then
Port1 = 888
Out Port1, 1
Label3 = “DOWN”
End If

If KeyCode = vbKeyNumpad1 Then
Port1 = 888
Out Port1, 3
Label8 = “LEFT-DOWN”
End If
If KeyCode = vbKeyNumpad3 Then
Port1 = 888
Out Port1, 5
Label9 = “RIGHT-DOWN”
End If

If KeyCode = vbKeyNumpad6 Then
Port1 = 888
Out Port1, 4

Label5 = “RIGHT”
End If
If KeyCode = vbKeyUp Then
Port1 = 888
Out Port1, 8
Label1 = “UP”
End If
If KeyCode = vbKeyLeft Then
Port1 = 888
Out Port1, 2
Label4 = “LEFT”
End If

If KeyCode = vbKeyDown Then
Port1 = 888
Out Port1, 1
Label3 = “DOWN”
End If

If KeyCode = vbKeyRight Then
Port1 = 888
Out Port1, 4
Label5 = “RIGHT”
End If

End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Label1 = “”
Label5 = “”
Label3 = “”
Label4 = “”
Label2 = “”
Label6 = “”
Label8 = “”
Label9 = “”
Port1 = 888
Out Port1, 0

End Sub

Connect the parallel port male connector to your computer. Run the program and use your arrow keys to control it and you can even use Numpad. The functionality of Numpad is little more advanced. For example when you press 7 your car will move UP and Left at the same time. I had some problem using combination keys, I mean combined arrow keys, the data to the parallel port can be sent only once. If you get any solution then please inform me about that.
Note: The Pin value may vary as I have soldered the wires of direction and movement controls haphazardly. If you have problem then please ask me I will help you. If you have problem with controls from your keyboard then reconfigure the pin address respective to the remote control circuit.

You can leave a response, or trackback from your own site.

Leave a Reply