Joystick + PC + Arduino


People, I want to move a servo in arduino by joystick. Ok, but not simple that. I want to connect my arduino in PC and the Joystick USB connect in my PC. So, when I`ll move the joystick in my PC for exemple, to the left, the servo in arduino will move to the left. I want to do the same, like the example below:

Ok, but I want to do with Visual Basic or C# NOT in Pyton. Anyone can I help me? I searched in google but not sucess.... :'(

Thanks in advance!

I can't help you with finished code to do this. But you have to break it into smaller tasks.

First figure out how to read the joystick from VB / C#. You can probably use Microsofts DirectX API for doing that.

Then figure out how to send the information to Arduino. in .net (both VB and C#) there are serial port classes that can handle that, it's well documented in this forum and other places how to send data from a VB / C# program to Arduino.

Then program Arduino to read the data from the serial port and move the servo, that i s well documented in many places as well.

So your biggest issue is to read the joystick. Dig into the DirectX API documentation. Try here:

The below code is from a different programming language, but it shows a method of using the winmm dll.

Struct JOYINFO, x As long , y As long , z As long , buttons As long

rem This code calls the windows joystick handler and comes back with x/y values for joy(n) and joy(m)

calldll #winmm, "joyGetPos", JOYSTICK2 as long, JOYINFO as struct , result as long
posJoyX2 = JOYINFO.x.struct
posJoyY2 = JOYINFO.y.struct
Button1=JOYINFO.buttons.struct and 1
Button2=JOYINFO.buttons.struct and 2
Button3=JOYINFO.buttons.struct and 4
Button4=JOYINFO.buttons.struct and 8
Button5=JOYINFO.buttons.struct and 16
Button6=JOYINFO.buttons.struct and 32
Button7=JOYINFO.buttons.struct and 64
Button8=JOYINFO.buttons.struct and 128
Button9=JOYINFO.buttons.struct and 256
Button10=JOYINFO.buttons.struct and 512

print posJoyX2
print posJoyY2
print "========="
print Button1
print Button2
print Button3
print Button4
print Button5
print Button6
print Button7
print Button8
print Button9
print Button10

MikMo, thanks, I will study more about directinput, I think this is way too!

zoomkat, this code is in VB6 write? Do you think I can convert to VB?

The code is from liberty basic. A google search for "winmm.dll joystick" produces pages like below.