Firmata Messages : Incoming

As you already know I am rewriting the sharpduino library. The new implementation will handle all known firmata features to date (version 2.2 of the protocol). Trying to decipher the available messages you can get lost, as the text representation offered by the firmata.org page is not really indicative of the message structure. There is also the problem of the fragmentation of the information on the wiki pages.

This is why I made the following image. It is a round-up of all the messages, that can be received on the PC host side as of version 2.2

Firmata Messages

We can separate the messages into 2 categories. Those that are 3 bytes -7-bits, but let’s just say it’s bytes- long and those that are longer and are called Sysex Messages.

The sysex messages always start with 0xF0, they have a second byte that is a sysex command and a final byte 0xF7 which tells us that the message is finished. The second byte tells us what the rest of the message will be. Right now there are 6 kinds of sysex messages, but I expect that they will multiply as more functionality is embedded to the Firmata protocol.

Beware that the messages received are almost always a result of a message sent earlier. This image does not show the proper order of the message exchange, but only analyzes the structure of the incoming messages.

This should be helpful to people implementing their own solution for communication using the Firmata protocol, or people wanting to know the ins and outs of the underlying protocol which they are using, if they use a library such as sharpduino.

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.

Reboot

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.

Links

Changing the Default Sound Device

About a year ago I bought for myself a new 24-inch monitor. It is great for games work as you can work with a lot of documents/source code files together without having to scroll around and/or toggle between many windows. What was great about this monitor, was that it had an HDMI port. “So what?” you will say and you will be right, but for me it was a revelation, especially when I upgraded my graphics card and bought one which had an HDMI output.

Although regarding graphics there was no difference transitioning from DVI to HDMI the sound was a whole new experience. As with anything in this life, when you get something you have to give something in return. What happened was that there was a new sound device in my setup, so my headphones could not function in parallel to the monitor speakers.

Changing from one to the other is not very difficult, but you have to access the playback devices tab in the sound configuration and set the device you want to use as the default. Searching the net you can find many guides and solutions to this problem. Some with screenshots showing the windows way:

And some more suited to power users/programmers:

Running a command line or having a shortcut (that I usually don’t remember) is not my thing, so building upon the work of the aforementioned people I decided to create an application that lives on the tray, is easy to access and helps me change easily between my monitor speakers and headphones. Let me present you with the aptly named ChangeSoundDevice program.

Usage

Before you use the application make sure that you have downloaded and installed the Microsoft Visual C++ 2010 Redistributable Package (x86). The first time that you will launch the program, it will automatically pop up a window listing the devices it has found in your system.

image

You can edit the names (to make them shorter and friendlier) and hit the OK Button. By default the first time the program is launched the first device will be chosen, but you can now change it easily with two clicks. One to the tray icon and one to the device of your choice. The following screenshot shows the user interface for this window.

image

You can also use the find devices button to get the first window again. This can be useful if you have a new sound device or are not satisfied with the previous naming.

Warning: Geeky Stuff

After having used code that was freely given by the aforementioned sites, it would be only fair to publish the source code of my application too. Inside the source code bundle you will find a solution with 2 projects. The first is a native dll library that is mostly a copy of Dave Amenta’s code with a few changes to make it play nice with P/Invoke. The second is the main program that uses the native library and runs in the tray.

Note that there is an error with the P/Invoke signatures, that I couldn’t resolve. Even though it works, there is some problem that gets caught in the debugger.

You can get the source code here.

Download

Get the applicationhere