Interfacing with the Arduino with your PC using the .NET framework and Firmata.



Firmata.NET (PC)  | Firmata v2 (Arduino)


A few months ago, I decided that I wanted to interface my Arduino with the .NET framework and Firmata. Since there were no Firmata libraries for the .NET framework at that time, I decided to write my own in C#. Using the Processing code by David Mellis I was able to crank out a fairly functional library in about an hour.

Why then, am I mentioning this now? Because shortly thereafter, Andrew Craigie released his FirmataVB library while mine remained largely untested.

I was cleaning the proverbial house this week and I decided to go ahead and run my C# implementation of Firmata.NET through it’s paces so I could make publicly available.

Like the Processing library it’s based on, Firmata.NET allows you to access the Arduino from within a C# application in a nearly identical manner to writing an arduino sketch.

The constructor has a number of overloads:

Arduino arduino = new Arduino();

Arduino arduino = new Arduino(string portName);

Arduino arduino = new Arduino(string portName, int speed);

Arduino arduino = new Arduino(string portName, int speed, bool autoStart, int delay);


Default constructor parameters

  • portName: the highest numbered COM port available on the system.
  • speed: speed (in bps) of the serial connection. – Default 115200.
  • autoStart: If true, the port will be opened automatically upon creation.
  • delay: delay (in ms) that the application will wait before attempting to communicate with the Arduino. Recent Arduino models automatically reset when the serial port is connected.  – Default 8000.


Sample usage

arduino.pinMode(9, Arduino.OUTPUT);

arduino.pinMode(10, Arduino.OUTPUT);

arduino.pinMode(11, Arduino.INPUT);

int analog = arduino.analogRead(5);

arduino.analogWrite(9, 128); // half duty-cycle

arduino.digitalWrite(10, Arduino.HIGH);

int status = arduino.digitalRead(12);


That should give you a pretty firm understanding of how the Firmata.NET library works.

I have included a short demonstration video showing a fun application of this using Microsoft XNA Game Studio 3.0 to communicate with an XBox 360 controller. This type of application could be used to add new level of enhancements to gameplay, or the Arduino serial connection could be replaced by a Bluetooth or XBee radio -allowing you to control a wireless robot via your standard XBox 360 controller.