Site Navigation

Page Navigation

Links

Arduino <> Firmata <> Visual Basic .NET

Introduction

Since the release of the .NET Framework version 2.0 the handy SerialPort component has made communicating over the serial port fairly straightforward. Sending and receiving a simple packet of bytes is almost a trivial matter. But what if you want to read and write to and from every pin on your Arduino board. Not a problem. Just spend many, many weeks creating, coding and testing your own serial protocol!

But why bother? A perfectly good general purpose serial protocol already exist in the form of Firmata.

Firmata is a generic protocol for communicating with microcontrollers from software on a host computer. It is intended to work with any host computer software package. Right now there is a matching object in a number of languages. It is easy to add objects for other software to use this protocol. Basically, this firmware establishes a protocol for talking to the Arduino from the host software. The aim is to allow people to completely control the Arduino from software on the host computer. Firmata.org

The minor problem I had was that I wanted to use Visual Basic .NET as my programming environment. I could find examples where libraries of code existed in Processing and Python but noting for VB.NET. As the code I could find was all licensed under the GNU GPL license I decided to try to learn from it, copy bits of it and create the beginnings of a component class library for .NET. What i've done seems to work so I'd thought i'd share it here with anyone who's interested. There are three libraries you can download, use and modify. FirmataVB.dll, DigitalPinControl.dll and AnalogPinControl.dll. Two sample applications are also available to download that demonstrate the use of the component/controls.

A brief introduction to each library is given below. More information about each can be found on the following pages.

FirmataVB

FirmataVB_dll image

FirmataVB is a .NET component class library that contains methods to send and receive messages using the Firmata V 2.0 protocol. The component takes care of connecting to the serial port and has properties and methods to set the port name and baud rate.

FirmataVB can be used in your projects in two main ways.

  1. It can be added as a component to the Toolbox. This component can then be simply dragged onto any form to make it available to code within your project.
    FirmataVB component in component tray
  2. You can include a reference to the FirmataVB.dll class library in your project and then create a instance of FirmataVB programmatically.FirmataVB instance in Visual Basic form code

Digital Pin Control

Digital Pin Control class library image

The DigitalPinControl.dll contains a User Control that can be added to the Toolbox. Once in the Toolbox you can then create as many instances of it as you need on your form.

When you push a button or close a switch wired to an Arduino digital pin a message can be sent via Firmata to the Digital Pin Control. It will show the On or Off state using a simple LED graphic.

As well as being able to receive digital messages the control can be set to send them. Either a simple On or Off can be sent using a button or a Pulse Width Modulation value (PWM) can be sent using a slider bar. The PWM send will only work if the pin you are sending to on your Arduino supports PWM.

Using the DigitalPinControl.dll makes creating an application to test Firmata quick and easy.

Analog Pin Control

Analog Pin Control dll image

The AnalogPinControl.dll contains a User Control that can be added to the Toolbox. Once in the Toolbox you can then create as many instances of it as you need for your form.

Analog Pin Control image

The Analog Pin Control receives analog messages from your Arduino's analog pins. The value, from 0 - 1023 is displayed visually in a progress bar and also as a number. The On/Off button allows you to turn on or off analog pin reporting for that particular pin.

A simple potentiometer wired to an analog pin on your Arduino is all you need to test this control.

Have you made use of FirmataVB or the code?

If so, please consider showing your appreciation (all donations used to continue to pay for web hosting of this resource)

 

Top