
In this article, I want to review the library in the .NET language to interact with the Arduino hardware platform.
Since in the open spaces of Habr, I did not see any mention of this library, I decided to take this initiative into my own hands.
In this article, I will give examples exclusively in the VB.NET language, but you can use this library in any other .NET language
Being engaged in the development of a specialized complex, to perform the tasks I need, I was faced with the problem that, with my needs, all the code may not fit into the memory of the microcontroller as well as taking into account that the device must interact with the PC or, in the absence of a PC, provide the same functionality .
Arduino <> Firmata <> Visual Basic .NET
As a result of the search, I stumbled upon the Firmata protocol for the Arduino hardware platform, and since I was gathering dust on the Arduino Mega 2560, I decided to use it. In the process of familiarization, for some reason, I began to like this protocol less and less until I came across the
page of Andrew Craigie, who wrote the Firmata protocol interaction library with .NET languages.
The author’s website provides free examples and source codes, which you can download yourself in principle, there are also ready-made modules that you can use for yourself.
')
Ready module for using digital outputs of Arduino board

Ready module of work with analog inputs of Arduino board

But I recommend using only the Firmata.Vb component.

Examples and how to use
In order to work with this library, we only need to load our examples from our Arduino: Standart Firmata.
At this programming with the board for us is finished.
Now, by loading the studio and adding a component, we can get to work.
Hello World >> Led ON!
In order to simply light the LED connected to the port of the board, it is enough to register the following code:
Add FirmataVB component to the form
<code>Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load FirmataVB1.COMPortName = "COM5" '' COM FirmataVB1.Baud = "57600" '' FirmataVB1.Connect() '' End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click FirmataVB1.PinMode(6, 1) '' , 6- FirmataVB1.DigitalWrite(6, 1) '' 6- End Sub Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed FirmataVB1.Disconnect() '' End Sub End Class</code>
Pwm
In order to use PWM (PWM), then in the code you need to make small changes.
FirmataVB1.PinMode(6,3) '' 3 - PWM FirmataVB1.DigitalWrite(6,x) '' x - 0 255
Analog
To work with analog input, we specify
FirmataVB1.PinMode(6,0) '' 0 - x = FirmataVB1.AnalogRead(6) '' x - , 6 -
Conclusion
As for me, the library was not written in vain, and I personally saved a lot of time.
I hope this article will be interesting and useful to someone.
Library site
Firmata.VB.NETFirmata protocol
sitePS: If it turned out a little informative or there are questions, I am ready to answer any of them.