How can I control multiple servos with C#

I'd like to send commands to multiple servos from Visual Studio C# through USB port.

I found a tutorial for controlling one through the serial port however I need to be able to control more than one.

How would I do that? I also need to know their positions, so how would I retrieve such information from Arduino?

Thanks in advance

You'll have to send commands from C# to the Arduino over the serial port and have the Arduino send information back to the PC over the serial port. The thing to do now is decide on a communication protocol, how you want to structure the packets of information to contain the commands. How that should work is entirely up to you and depends entirely on what you intend to do with it, so from the limited information you have given I can't help much.

I would suggest reading carefully the Serial Input Basics thread. That will help you get some ideas how to handle your communication.

kolleamm wrote:

I’d like to send commands to multiple servos from Visual Studio C# through USB port.

That doesn’t sound like Arduino. The usual Arduino programmer uses C and/or C++. The usual Arduino does not have a serial port.

I found a tutorial for controlling one through the serial port however I need to be able to control more than one.

How would I do that?

I don’t know the source for the tutorial or how the tutorial was controlling a servo through a serial port, so how can I guess how to control more?

I also need to know their positions, so how would I retrieve such information from Arduino?

The usual servos do not provide any position information except that they usually end up eventually at the position that you command. Thus, the Arduino cannot provide that information.

Instead of guessing games, how about showing us what the wiring looks like and what code you have so far.

Just remember, to post:

  1. Use CTRL-T in the Arduino IDE to autoformat your code.
  2. Paste the autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.

These details and more are located in the locked items at the top of this forum.

I have not purchased an Arduino yet. I'm trying to see if Arduino is capable of this.

What about reading multiple sensor values? Would Visual C++ work?

Thanks

Explain what part you want VS to play. Are you talking about programming the Arduino itself through VS? Or are you talking about having a program that runs on the PC that communicates with a program on the Arduino? If the latter then there's no reason you can't use C# for the PC program.

Yes, I have a program in C# that needs to send and retrieve values from the Arduino, for servos and sensors.

kolleamm: Yes, I have a program in C# that needs to send and retrieve values from the Arduino, for servos and sensors.

No problem. See the link I gave you before and study up on how to communicate with Arduino over the serial line.

The usual Arduino does not have a serial port.

It most certainly does.

I’m trying to see if Arduino is capable of this.

Of course it is. Suppose that your program sent “<5, 100>”. Could you guess what this means for the Arduino to do? Could you figure out how to make the C# app send that string?