duminică, 6 ianuarie 2013

C# communicate with Arduino Part.3




I made a C # application to control two servos via USB with Arduino.




When you pull the slider bar, the value is sent to the Arduino, which represent the positions of the servo.
Each servo has his own bar.






 
C# code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace SERIAL_ANALOG_WRITE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void bara1_ValueChanged(object sender, EventArgs e)
        {
            val_bara1.Text = Convert.ToString(bara1.Value);
            transmite1();
        }





        

[... do you want the rest of the code???? ...]



        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) serialPort1.Close();
        }
    }
}


Arduino code :


#include <Servo.h> 
int v, v1, v2, v3, v4;
Servo servo1;
Servo servo2;

void setup()
{
   servo1.attach(9);
   servo2.attach(10);
   Serial.begin(9600);
}

void loop()
{
  if (Serial.available()>0)
  {

[... bla-bla-bla...]

  }
  
  delay(10);
}


15 comentarii:

  1. Hi. May I please have the code for my new project?

    RăspundețiȘtergere
    Răspunsuri
    1. give me your email address!

      Ștergere
    2. Hi. My email adress is:
      xyz.boy.28@googlemail.com

      Thanks a lot!!! =)

      Ștergere
  2. Hi. May I please have the code for my new project?
    I'm very interested in C#, arduino and USB communication.

    RăspundețiȘtergere
  3. Hi, can i get the rest of code?
    My email is:
    mamretsptc@gmail.com

    RăspundețiȘtergere
  4. Hi,
    I am searching 2 servos motor at the same time?
    Could you send to me codes arduino and c#?
    best regards.
    my email:
    cengav4r@gmail.com

    RăspundețiȘtergere
  5. Hi again,
    I tried your codes but i did not work on my platform.
    If it is possible, Could you send to me C# Project file.
    I send to you my files .Maybe you can see my fault.
    best regards
    Cenk

    download link;
    http://www.multiupload.nl/FYDZCRROXU
    (I tried send this mail to your gmail but gmail gives error )

    RăspundețiȘtergere
  6. Acest comentariu a fost eliminat de autor.

    RăspundețiȘtergere
  7. Acest comentariu a fost eliminat de autor.

    RăspundețiȘtergere
  8. Hi,
    you have posted a beautiful example to Arduino c# communication.
    Can i have a code. I'd like to try it.
    zanzinot@yahoo.it
    Brodo

    RăspundețiȘtergere
  9. Hello, can you send me code for this awesome project?
    qlukasq@o2.pl

    RăspundețiȘtergere
  10. I don't have my computer around. I'll send when I get home!

    RăspundețiȘtergere
  11. Hello, I'm working on a school project and I'm having trouble controlling servos via C# because they tend to move at the same time or in certain values they turn on other motors that should be off... could you share the codes? mastermike_520@hotmail.com

    RăspundețiȘtergere
    Răspunsuri
    1. Hy!
      I lost the codes, but if I can help it ....
      C # application must first send '1 'to control the engine 1, followed by the desired angle or '2' command to drive 2, followed by the desired angle.
      The Arduino code, according to the first digit received, it sends the command to the servo 1 or 2.

      Ștergere