Sharpduino Library: Reboot

A little background (Yes you can skip this)

A few years ago I bought an arduino to ease myself into electronic project prototyping. I tried a couple of times with pic microcontrollers, but the promise of using USB to program and debug an electronics board was too good to pass. The arduino, as everyone knows by now, is very easy to use and I had no problem creating from the simplest programs, to more complicated ones.

My goal was to create a program that would communicate with the pc and offer functionality equivalent to USB data acquisition modules from NI that we were using in our laboratory. Although the capabilities of the Arduino weren’t an exact match, the price (about 1/10th) was right. One of the requirements that I had, was that I could use this from the Labview environment. Back then there was no library for arduino for labview so I had to make one. There were actually two ways to accomplish such a task. A full native Labview library or a .net library that could be imported to Labview and used.

Given my background on .net technologies I went for the second solution. This was the birth of the Sharpduino Library. It was based on the Firmata protocol and implemented some basic functionality (Analog Input/Output, Digital Input, Digital Output). It had the functionality that I wanted, so I put it on google code and never really updated it since. I had even forgot that I had written it…

Fast forward to December 2011. I received two emails from people who had seen my library and were interested in the Firmata protocol. One was Noriaki Mitsunaga who not only used the library, but also had made a more complete implementation of the Firmata protocol. You can find his useful applications using this library here. The other was my friend Anton Smirnov who was making an equivalent library in pure Java (find his library here). It rekindled my interest in the library and I decided to do some coding.

The first step was to integrate Noriaki’s work (with his permission) and make it available. This begun with the switch of the repository from svn to mercurial. I have become a huge fan of DVCS and have found that it suits my any style of development if you spend a little time to make the switch from server-based systems. You can find the current code from the source tab of the sharpduino page.

Then I started refactoring a lot of the code, so it would make more sense. At some point I decided that the library needed a more thorough refresh,hence the reboot of the project.


For this new implementation I have decided to make a library that will be useful to two kinds of consumers. There will be a higher level API that will be useful to people in need of the previously available functionality. For example, using the ArduinoUno will be as easy as:

Of course the actual names might change, but the general direction will be this.

What is more interesting (for me) is the lower level API. It will be mostly Message Handlers, Message Senders, Messages and a few base classes to coordinate all these. The previously mentioned implementation will be based on this and will serve as an example on how to put things together to make other Firmata Implementations.

Keep an eye on this blog and/or the sharpduino page for more updates as the new implementation matures and I will have a few things to share.

PS. I would also like to mention that my goal is to create a nuget-distributable library.


15 thoughts on “Sharpduino Library: Reboot

    • Supporting Arduino Mega is one of my goals. What would you like to see in such a library? I am early in the development phase so I would like to hear any suggestions.

    • I am aiming for a workable release in about 2-3 weeks. The base API will be there to be extended for any board. The first implementation/example will be for ArduinoUno, but changing it to fit an Arduino Mega will be easy and should not take me more than 1-2 days.

      So keep an eye on the project and I believe by mid-February I will have you covered.

  1. i was wondering how far along the reboot build has made it. can it reliably be used at this point to talk to an uno and mega board.

    • hi. thx for your interest. I have finished with the base implementation and I am now implementing the arduinouno class. I expect that by the end of the week I will have a working prototype. If you are ok with using code which is in progress keep an eye on the reboot branch on the project’s source code page.

  2. i have have started a project which implements your reboot library and i am at the early stages and most of it is working. the only issue is i cannot get the digital pins on my uno to read or write a value. i have tried:

    (arduinio is a Easyfirmata type)
    for pwm i have
    arduino.SendMessage(new AnalogMessage() { Pin = (byte)ct, Value = 100 });

    how does DigitalMessage work? it wants a bool[] not a bool

    also why can i not just set it directly from
    arduino.Pins[3].CurrentValue = 100
    arduino.Pins[2].CurrentValue = 1 //which is true

    here is a screen shot of what i have so far. if your interested in any of it let me know

    • The digital message is a representation of the corresponding firmata digital message. In order to save some bandwidth it contains data for the hole port and not just a pin. This means that every digital message contains data for 8 pins: (port * 8) – (port * 8 + 7). As such you must provide the other 7 values as they already are (you can read them from the Pins.CurrentValue).

      This thing will happen without you knowing, but it is an unimplemented feature yet. I will probably have some method like SetDigitalValue(int pin,bool value)

      As for your suggestion of using the Pins List to make changes it is quite good and will probably make it easier for end users. Right now I am focusing of making everything extendable but this is definitely one of my end goals for this library.

      I really liked your screenshot. This is something that is on my backlog for implementation, and I am sure that I could not make it so good looking. If you are willing to share the source code we could include it in the library, or when you finish with the implementation, I could link to your site from the google code page.

      Please keep me posted if you have any progress, or any other questions-suggestions that I can help you with.

      • ok so you sending to port B and D . like D00000010

        do you plan on implement a DigitalRead and DigitalWrite function anytime soon. i hope so because i need to finish this interface soon(its part of a bigger project) . i will share the source of this project with you for use . ithe analog values seam to be working well by reading the pin CurrentVal. so i would just need a simple digitalRead(), DigitalWrite(), and ServoWrite() i have the AnalogMessage() working great for the PWM pins.

        • Actually Digital Read functionality is already there. You can just read the Pins[pinNo].CurrentValue. For a digital input pin it will be 0 for false and 1 for true. There is also a NewDigitalValue event that you could subscribe to.

          As far as Servo is concerned, for now you can just send a ServoConfigMessage and then any AnalogWriteMessage to set the values that you want. See the Console test for a quick implementation i did yesterday.

          For the Digital Write I intend to implement it one of these days. Maybe 2-3

  3. would it be possible to email you a few questions. i have my interface working well now using your library (including a digitalWrite function). there are a ton of new features in it (like being able to use you iphone/android to control the input and pwm values. but i have some simple questions like is there a message to reset the board and is there an event that occurs if the board freezes or is disconnected without properly closing the connection.

    here is the android app that works with the controller

    once i get a few of these issues out i will post the code

    • There is a reset message that resets the state of the pins to the default values. Currently there is no such thing such as events for freeze or disconnect. I guess the disconnect event will be easier to implement, but the freeze event will also need code on the board side, or some kind of tracking (ie. I didn’t receive a new analog message for 200ms, there must be some error…)

      Using the library through network was one of my goals. I was thinking of creating a ethernet-serial bridge service and then using something like the app that you mention to control the arduino.

      If you provided your email address correctly on your comments then you already have an email.

  4. Great code you got here really enjoy it!Though there is 1 litlte problem I run across when I want to read a analog port.I tried very different possibilities and I assume this has to work: Dim analog As Integer analog = arduino1.analogRead(5) Label2.Text = analogBecause this way it is working with a digital read returning a 1 or a 0But with a analog read it always stays at 0. Did I do something wrong?If so could you please explain this to me?

    • There are a couple of things that you could try. I am assuming that you are using the ArduinoUno class. First of all the analogRead method returns a float value, so you are probably missing quite a lot of values by declaring your analog variable as integer. Also make sure that you have set the pin as analog by using the setPinMode method.

    • The firmata drreivs are included in the example sketches that come with the chipkit version of the Arduino IDE. The shows that the library is not working. But I have loaded the standardFirmata_2_2_forUNO_o_3 sketch and then worked out the board using the test program available at and was able to read analog values, use pins and digital in or digital out and pwm so I am not really sure what is not working yet.

Leave a Reply

Your email address will not be published. Required fields are marked *