View Full Version : C# code for controlling servo with keyboard

04-18-2008, 11:45 PM
I'm brand new to every thing about this, I've built robots before but never programmed (I've been working on all the mechanical components) but I came up with an idea to create a robot that i can control over WiFi. I don't have any of the parts yet but i'm about to order the 4 server controller and a bunch of other things. I have the means of controlling computer wirelessly, but I do not know how to program the phidget

What I need help on is writing a program that will allow me to control the robot with a joystick or keyboard, the program will be running on the robots computer so it doesn't look too hard. But i've never programed before so I don't know were to begin, so could some one help guide me through this. I have microsoft visual C# express, but I can get something else. Thanks.

04-19-2008, 12:23 AM
Welcome to the Community, Brian!

You're going to hate me for suggesting this, but...

Sams Teach Yourself Visual C# 2005 in 24 Hours

Someone will surely share some code with you, but you're not going to be able to modify it to make it do exactly what you want it to do. If you're new to programming, you're biting off a large chunk of project. It's probably time to learn some programming! C# isn't a bad place to start, imho.

04-19-2008, 12:45 AM
C# isn't a bad place to start, imho.

Most def! C# is a very "middle of the road" language. It's very powerful, yet not as powerful as C/C++, and also fairly easy to learn, yet not as easy as vb.net.

04-19-2008, 01:23 AM
That's very much my take on it too, Alex, I think that's a very apt description.

It's also valuable as a web-enabled language.

04-21-2008, 03:56 PM
Hey bluegear,

I can't teach you how to program, because there is far too much to learn about programming. But I can whip together a quick application sometime later this week for ya that will show you how to control servos using a keyboard and a Phidget Servo Controller (I'll put together one for the 4-motor controller). This will at least get you started in understanding how to interact with a Phidget servo controller. Once I build the app, I'll upload it to the Downloads section and post a reply here.

04-23-2008, 05:52 PM
Thank you so very much, i didn't know about the sam thing but i need to check that out. I'm taking a C++ programing course over the summer now.

04-23-2008, 07:31 PM
crap! I meant to write this app for you earlier today but I forgot:( I'm not sure if I can get to it tomorrow or Friday, but absolutely I will have it for you before this coming Monday:D

04-29-2008, 02:30 PM
grrr.... My bad bluegear. I got to stop making promises I can't keep. It gets so hectic here sometimes.

Anyways, after another day late, I finally was able to whip up an app for you showing you how to control Phidget Servos with a keyboard in C# 2005. You can download it here:


Hopefully that'll help get ya started. If you have questions about the app, please reply in the comments section of that download.

05-15-2008, 03:38 PM
Hi Alex,

Thanks for that code sample. I am trying to put together a robot that uses 2 stepper motors, 1 servo motors, and a couple of touch sensors. Can u pls suggest what phidget product I can use to accomplish all of this. I am good with C#.

I plan to test the device from my PC. However in the future, I would like to run the device as standalone with the microcontroller.

Will greatly appreciate suggestions.


05-15-2008, 07:25 PM
If you're eventually looking for a standalone solution that can be used with a microcontroller, phidgets are not for you. Phidgets require a constant connection to a USB host device. You can use a Hammer, an ITX or something like that though.

I'm sure someone here would be able to help you out better than myself. I'm not that experienced with microcontrollers.

05-15-2008, 09:48 PM
Take a look at the "Arduino" controller. It has a USB connection but it is really USB to RS232 glue logic. That makes it incredibly easy to interface with other gear or have it act a a standalone controller. There is also a ready made Servo library that you can download from www.arduino.cc (http://www.arduino.cc)

I'm using this controller in a couple of my home projects and have even used it for work stuff. I highly recommend them.

05-15-2008, 11:25 PM
Not gonna run C# on an arduino...

05-16-2008, 08:24 AM
As far as I know, you can't run any .NET language on any microcontroller, because microcontrollers cannot run the .NET framework, which is what is required to run .NET apps.

However... I don't know any of the latest status updates, but I know a year or so ago there was a lot of buzz about the .NET Micro Framework (http://msdn.microsoft.com/en-us/embedded/bb267253.aspx) that can run on embedded applications. My guess (and it IS only a guess) is that the micro framework is what Msoft is using to run SYNC on those car stereos. I've been wanting to look into it for quite some time now, just haven't found the time yet.

05-16-2008, 09:00 AM
No it won't do C# but there is a ton of pre-written code in C making it really easy to step into that world.

05-16-2008, 09:35 AM
I think it needed clarification, since this is a C# thread...

The Arduino is a decent little microcontroller, running right in the middle of a pack of decent little microcontrollers. But it won't run C#. And porting anything you do in C# to the microcontrollers infinitely limited RAM/ROM/instruction set is a restart-from-scratch project.

A PicoITX, on the other hand, will run C# and phidgets just fine.

09-10-2010, 05:25 PM
You might look into a Serializer (http://www.roboticsconnection.com/p-16-serializer-robot-controller.aspx) board + xBee (http://www.trossenrobotics.com/store/p/5828-XBee-Explorer-USB.aspx) for wireless control.