Go Down

Topic: More c# & VB.net source code, together with scetch (Read 9 times) previous topic - next topic

Riaan Deyzel

No problem, do you know c# connectivity to Arduino at all becase I have tried almost everything, and currently posting on about 5 Forums for anyone to send me the modified source code & sketch for this apphttp://blog.renatopeterman.com.br/?p=164#comment-8, to be able to control another servo, the up & down (tilt) servo, but no luck for 2 months now.

Please anyone out there With some programming knowlege please help.

Thank you.

a.d

Perhaps you could work it this way - between 0 and 360 controls pan, and 400-760 controls tilt. If you send the arduino, for example, 300, it will move the pan servo to position 300, and if you send the arduino 696 it would move the tilt servo to position 296.

That shouldn't be too hard to modify on the existing source, although it would be a bit obtuse to someone not aware of what was going on when looking back, if it wasn't documented well.

Alternatively send a character before each integer string and parse that before you decide what you want to do with the number you receive after it. So P132 would move the pan to 132, and T132 would change the tilt the same amount. A bit more complicated to implement in the C# source code, but by no means difficult.

Paul Stoffregen

It's not Vb or C#, but I did write a similar GUI-based program in C++ using wxWidgets (works on Mac, Linux and Windows).  It's called "firmata_test", and you can download it here:

http://www.firmata.org/wiki/Proposals

Scroll down and look for the screenshot on that page.  Unfortunately, wxWidgets has a steep learning curve, but it's the only toolkit that produces native apps for all 3 platforms from the same source.

CaptainObvious

http://www.acraigie.com/programming/firmatavb/default.html

After downloading and installing (following their instructions)  Include it with your Visual Basic project, and you just need to make sure before you use it, you set the output to SERVO.
Code: [Select]

Imports Firmata
Public Class Form1
   Dim arduino As FirmataVB
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       arduino.PinMode(8, FirmataVB.SERVO)
   End Sub

   Public Sub setServo(ByVal SERVO_PIN As Byte, ByVal SERVO_VALUE As Byte)
       If SERVO_VALUE > 179 Then
           SERVO_VALUE = 179
       End If
       arduino.AnalogWrite(SERVO_PIN, SERVO_VALUE)
   End Sub
End Class

Keep in mind this is for the Visual Basic edition, you should be able to get the C# code from it.  

With the Firmata DLL downloaded, OUTPUT is misspelled, so just a heads up. So to set an OUTPUT for LED's etc, you'll need to either spell it OUTUPT or use the integer value 1. (I just declare a new variable at the beginning.. dim OUTPUT as byte = 1)

Other than that, after the pin is set to SERVO, you need to use analogWrite instead of servo.write used normally.

Go Up