Go Down

Topic: C# communication help (Read 563 times) previous topic - next topic


Hey guys, I'm new here, just bought a couple of Arduino to play around with.

I'm a C# programmer at heart, so I'd like to learn how to use the Arduino with C# so I can write GUI programs and such for it.

My programming would be pretty simple. I saw a video on youtube a C# program controlling a couple LEDs... when you click on the program, it turns on the LEDs on the Arduino. Sounds simple... but how do I control the Arduino with C#????

The website for the project was no help since it was in Chinese...
Anyhelp would be appreciated... or at least point me in the right direction. I've done quite a bit of searching and hasn't found much.


Hunt around for a C# serial library, then talk to Arduino over usb.

Here's a c++ example


You might be able to re write it for c#


Feb 19, 2009, 11:33 pm Last Edit: Feb 19, 2009, 11:37 pm by mikalhart Reason: 1
Serial with C# is pretty easy.  No need to hunt around for libraries -- .NET is already there!

Code: [Select]
using System.IO.Ports;

 // to open a port
 SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);

 // example: forever displaying incoming characters
 while (true)
   if (port.BytesToRead > 0)
     char c = (char)port.ReadByte();

 // example: writing a few bytes to the port
 byte[] arr = new byte[4];
 arr[0] = arr[1] = arr[2] = arr[3] = c;
 port.Write(arr, 0, 4); // write the 4 bytes

 // example: writing a string
 port.Write("Hello, world!");

Just look in the documentation for System.IO.Ports.SerialPort for more goodies.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131