thefatmoop Posted January 2, 2009 Posted January 2, 2009 Alright so i'm reading the i2c networking from a wii nunchuck using a arduino microcontroller. Idea is that the microcontroller will read the data from wii nunchuck, and convert it to a serial command. A program on the computer will then read the serial input, then it will move the mouse accordingly. an example serial output is: jx223jy225ax793ay647az677zb1cb1 interpreted: joystick x =223 joystick y =225 accelerometer x =793 accelerometer y =647 ...etc here's a program i was working on in vb6 (since i've done mouse programs in vb6 i decided to start off there) problem is that if i'm taking 100 readings a second it just spams the mouse clicking.... text boxes are reading properly, but does anyone know what's wrong? Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Const MOUSEEVENTF_LEFTDOWN = &H2 Const MOUSEEVENTF_LEFTUP = &H4 Const MOUSEEVENTF_MIDDLEDOWN = &H20 Const MOUSEEVENTF_MIDDLEUP = &H40 Const MOUSEEVENTF_MOVE = &H1 Const MOUSEEVENTF_ABSOLUTE = &H8000 Const MOUSEEVENTF_RIGHTDOWN = &H8 Const MOUSEEVENTF_RIGHTUP = &H10 Dim i As Integer Dim InBuffer Dim c As String Dim z As String Private Sub Form_Load() MSComm1.Settings = ("115200, n, 8, 1") MSComm1.RThreshold = 1 For i = 1 To 10 List1.AddItem (i) Next App.TaskVisible = False End Sub Private Sub List1_Click() On Error GoTo ErrHandler If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If MSComm1.CommPort = List1.ListIndex + 1 ' Select port MSComm1.PortOpen = True Exit Sub ErrHandler: MsgBox "An unknown error occurred. Make certain the port is valid and not in use" End Sub Private Sub MSComm1_OnComm() InBuffer = MSComm1.Input If MSComm1.CommEvent = comEvReceive Then If Len(InBuffer) <> 33 Then Exit Sub End If Label1.Caption = "joy X: " & Mid$(InBuffer, 3, 3) ' Input data Label2.Caption = "joy Y: " & Mid$(InBuffer, 8, 3) Label3.Caption = "accel X: " & Mid$(InBuffer, 13, 3) Label4.Caption = "accel Y: " & Mid$(InBuffer, 18, 3) Label5.Caption = "accel Z: " & Mid$(InBuffer, 23, 3) Label6.Caption = "button C: " & Mid$(InBuffer, 31, 1) Label7.Caption = "button Z: " & Mid$(InBuffer, 28, 1) If Mid$(InBuffer, 28, 1) = "0" Then mouse_event MOUSEEVENTF_LEFTDOWN, 0&, 0&, cButt, dwEI DoEvents End If ElseIf Mid$(InBuffer, 28, 1) = "1" Then mouse_event MOUSEEVENTF_LEFTUP, 0&, 0&, cButt, dwEI DoEvents End If If Mid$(InBuffer, 31, 1) = "0" Then mouse_event MOUSEEVENTF_RIGHTDOWN, 0&, 0&, cButt, dwEI DoEvents ElseIf Mid$(InBuffer, 31, 1) = "1" Then mouse_event MOUSEEVENTF_RIGHTUP, 0&, 0&, cButt, dwEI DoEvents End If End If End Sub Private Sub Form_Unload(Cancel As Integer) If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If End Sub Quote
thefatmoop Posted January 3, 2009 Author Posted January 3, 2009 >.> anyone have any experience on connecting ucs to pcs over serial....? Quote
dallaskorben Posted January 3, 2009 Posted January 3, 2009 >.> anyone have any experience on connecting ucs to pcs over serial....? I have experience using serial connection between microcontrollers and PCs, but I have very little VB6 experience so I don't think I can offer much help. It sounds like your problem is within your VB6 software? Maybe you can have the software record all the received serial output to a .txt file to look for anomalies? But I did want to say thanks for the tip that the Wii accessories communicate using I2C! I didn't realize that before, now I've got a new project to play with. :) Is there a connector available to plug in the Wii accessories? I really don't want to have to cut the cable of my Wii nunchuck. Quote
thefatmoop Posted January 5, 2009 Author Posted January 5, 2009 I have experience using serial connection between microcontrollers and PCs, but I have very little VB6 experience so I don't think I can offer much help. It sounds like your problem is within your VB6 software? Maybe you can have the software record all the received serial output to a .txt file to look for anomalies? But I did want to say thanks for the tip that the Wii accessories communicate using I2C! I didn't realize that before, now I've got a new project to play with. :) Is there a connector available to plug in the Wii accessories? I really don't want to have to cut the cable of my Wii nunchuck. yes yes there is! take a double copper sided pcb and use a dremel to cut a board like this. http://todbot.com/blog/2008/02/18/wiichuck...pter-available/ or i guess u can buy one. I was able to get the program working PERFECT! acceleration works, accelerometer works. I was playin some TF2 and it felt like halo3 lol. umm it's setup so i can press the c+z at same time when using accelerometer to recalibrate it. Ideally i would like to re-write the program in java or something open source/ cross platform (python?) Most of my machines cept my gaming rig run linux... so lol it's limited. Another problem is i'm using vb6 and the APIs i'm using aren't standard on windows anymore.... so the program would need to install the apis. I need a programming environment that i can control the mouse and serial... anyway yeah i'll post the source code on my site hopefully tonight (it would help if i had a site to start with) setting up drupal.... my program is a bit messy too. Quote
dallaskorben Posted January 5, 2009 Posted January 5, 2009 yes yes there is! take a double copper sided pcb and use a dremel to cut a board like this. http://todbot.com/blog/2008/02/18/wiichuck...pter-available/ Awesome, thanks! I was able to get the program working PERFECT! acceleration works, accelerometer works. I was playin some TF2 and it felt like halo3 lol. umm it's setup so i can press the c+z at same time when using accelerometer to recalibrate it. Sounds pretty slick, nice work. Eventually I'll come up with a wii nunchuck project and post about it too. :) Thanks again! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.