More c# & VB.net source code, together with scetch

Good day.

I have an Aduino Deumilanouve, and I am strugling to interface simple tasks like to control 3 servo's with 5 butons (servo1 pan left /right) (Servo2 tilt up/down) and the 5th seperate button to make this third servo go 0*- 180* and then back to 0*.

It will be awesome if this new revision has more support & examples of # & VB.net source code & apps.
I would love it also if the new revision will come out with an app like Firmata, only beter, more push buttons for servo & motor control & less sliders.

If anyone out there can help me with this source code for my Deumlanouve (5 Button servo - control/PWM Pin 9, 10, and 11 )I will realy apprecite it.
see below for example:

Thank you very much,
Riaan Deyzel

Hello,

I don't see exactly what is your problem. It's very simple to interface vb.net (or other language) with an arduino. You just have to send by serial connection keywords or a character to the arduino and it reacts in function of them.

I am an beginner with programming, more an electronics guy.
If anyone got time,and have an idea how to do this, please do this for me.
I have been strugling with this for 2 month.
I have wired everything up, Arduino to sensors, arduino to servo's, arduino to 15 A Pololu MotorDriver and then to 2X 12V drill motors, basically a fully completed robotic tank with CO2 Air rifle for an turret////but I can not control anything////.
I managed to control my motors via Firmata, then tried it with my servos, but they were very shakky,and I would like to push a button to move my servo's, and not move an sider to send PWM to arduino. A simple sketch just for these 5 buttons functioning will be appreciated.

Thanks for the repy. :slight_smile:

I don't think the devs want to waste their time on something that will only benefit windows users.

A simple sketch just for these 5 buttons functioning will be appreciated.

Not possible without a lot more information.

A slider can take on any value in it's range. So, it's range is typically set to match the necessary output. In the case of a slider controlling a servo, the range of the slider is typically 0 to 180. Whenever the slider is moved, the new value is sent, and the receiver moves the servo to that new position.

Buttons on the other hand offer discrete events. YOU have to decide what the servo should do when a button is pressed. Should the value to be sent be increased by 1? By 5? By 14? By 22? Decreased by 7?

Once YOU decide that, then buttons can replace sliders. You also need to decide if you are going to keep track of the servo position in the PC application of in the Arduino. If the PC keeps track of the value, then it should send that value every time a button is pressed.

If the Arduino is keeping track of the value, then you send either a delta (+5, +12, -7) or an event (UP, DOWN, LEFT, RIGHT, WAVE), and program the Arduino to do something with either the delta or the event.

Good day

Exactly like this http://blog.renatopeterman.com.br/?p=164#comment-8, but in english, and with tilt support, current version only pans left to right, and i need up & down as well.
and pins 9 for pan & 10 for tilt and not the current pin 8.

Please see what you guys can do for me.

Thanks
Riaan

Here is the current scetch which I modified to change the pan servo to pin 9

// Importa a biblioteca Servo.h do arduino
#include <Servo.h>

// Cria uma variavel do tipo Servo que será
// o nosso servo.
Servo servo1;

// Array de char que receberá o comando
// via serial
char buffer[4];

// Variavel que identifica quantos
// caracteres foram recebidos, pois só é
// possível receber um caracter por vez
int received;

void setup(){

  // Define o baud rate (taxa de trasmissão) como 9600
  Serial.begin(9600);

  // Atribui o servo ao pino 9 do Arduino
  servo1.attach(9);

  // Atribui o valor 0 para a variavel received
  received = 0;

  // Na posição 0 do array, atribui o valor '\0'
  // que identifica onde começa o array
  buffer[received] = '\0';
}

void loop(){

  // Verifica se existe alguma entrada de dados
  // disponivel na entrada serial
  if(Serial.available()){

    // Salva os caracteres no array a cada iteração
    buffer[received++] = Serial.read();

    if(received >= (sizeof(buffer)-1)){

      // Imprime na saída serial o valor
      // Apenas para mostrar o valor
      Serial.println(buffer);

      // Converte o valor de "char" para "int"
      int numero = atoi(buffer);

      // Envia o comando para o Servo Motor
      servo1.write(numero);

      // Zera novamente a variavel
      received = 0;
    }

    // Limpa o buffer da entrada serial
    Serial.flush();

  }

}

That was the easy part, now I need to add support for an second servo "tilt servo" on pin 10, I can copy the code & buttons from the pan buttons and use them for the tilt buttons, but not sure how to link it to the scetch from the C# app, as the same servo on Pin 9 would probabbly move when I press the Tilt (up/Down Buttons). (http://www.renatopeterman.com.br/downloads/ProjetoArduinoServoControl.rar for source code & http://blog.renatopeterman.com.br/?p=164 for original Scetch)
Can anyone please help with this?
Thanks :-[

You may want to look into the Firmata project. It's more about remote controlling stuff attached to an Arduino from a PC.

Korman

I am an beginner with programming, more an electronics guy.
If anyone got time,and have an idea how to do this, please do this for me.
I have been strugling with this for 2 month.
I have wired everything up, Arduino to sensors, arduino to servo's, arduino to 15 A Pololu MotorDriver and then to 2X 12V drill motors, basically a fully completed robotic tank with CO2 Air rifle for an turret////but I can not control anything////.
I managed to control my motors via Firmata, then tried it with my servos, but they were very shakky,and I would like to push a button to move my servo's, and not move an sider to send PWM to arduino. A simple sketch just for these 5 buttons functioning will be appreciated.
Thanks for the repy.

Previous quote of mine above.

Firmata only gives digital on/off buttons, nd no PWM buttons, instead they use sliders, which is not going to work well to contol an robotic tank.

Sorry about that, I missed it. I though there are also servo controls available for Fimata. I must have missed that.

Korman

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.

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.

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.

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.

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.