Go Down

Topic: Control Arduino with VB.Net/C# (Read 21204 times) previous topic - next topic


I didn't use the serial class before in .net.
Usage is easy but it has some 'strange' behaviour that I had to understand.

btw a good resource is this link:

I think a good discussion about the 'efficiency' of code is always desirable, so all input is welcome.

When my webspace is ready I will post a compiled dll to use with some documentation.


OK, I finally got some webspace and copied the compiled dll and arduino sketch.
No further info on the website yet.
I want to add some documentation and perhaps some examples....
(In due time...)

link to the dll:

link to the arduino code:

The rest will follow.


Would you also be so kind to put the Visual Studio solution/project there in a zip file?



Jan 30, 2010, 09:11 am Last Edit: Jan 30, 2010, 09:21 am by vulture Reason: 1
Although it's just work in progress I uploaded the complete VB.Net 2005 project here:


This project is not a finished and polished one.
There is one test application in there that I used to test the inputs and outputs. The application works and I included a small text file with the Arduino connections I used.
All the functions in the class are documented, so using the class shouldn't be difficult.

Some explanation here:

To use the digital ports, you have to set the direction of the port (input, output or pwm), enable the port and optionally set a trigger.
When the trigger is set on a digital port, the class fires an event every time the value of that port is changed.
To read a button, attach that button to a digital port, set the direction to input, enable the port and enable the trigger.
When you push the button, an event is fired from the class, saying that the value is changed to 1 and when you release the button, an event is fired saying that the value has changed to 0.
It's also possible to read the current value of a digital port. This function will not give the current value in return, instead it fires the same event as if the trigger was used. This value-read function can be used with or without the use of the trigger.
For an analog port there's only input, so no direction to set here. Just enable the analog port and read the value.
There is also a 'trigger' on the analog port called threshold. This will fire an event when the value of the analog input is changed by more than the set threshold. This will eliminate the slight changes that occur on the analog input.
Reading the value of the analog input works the same as on the digital input. Just use the GetAnalogValue command and wait for the event.

I know it would be more easy if the value reading functions would return a value but this conflict with the working of the Arduino code.
I'm working on that.

Keep in mind that this is no finished product.
There are no real checks on the input values and portnumbers.
These are all to be implemented in the .Net class.

current commands:

StartCommunication() As Boolean
SetDigitalDirection(ByVal Port As Integer, ByVal Direction As DigitalDirection)
SetDigitalValue(ByVal Port As Integer, ByVal Value As Integer)
EnableDigitalPort(ByVal Port As Integer, ByVal Enable As Boolean)
EnableAnalogPort(ByVal Port As Integer, ByVal Enable As Boolean)
EnableDigitalTrigger(ByVal Port As Integer, ByVal Enable As Boolean)
EnableAnalogTrigger(ByVal Port As Integer, ByVal Threshold As Integer)
GetDigitalValue(ByVal Port As Integer)
GetAnalogValue(ByVal Port As Integer)

current events:

DigitalDataReceived(ByVal DPortNr As Integer, ByVal Value As Integer)
AnalogDataReceived(ByVal APortNr As Integer, ByVal Value As Integer)
LogMessageReceived(ByVal Message As String, ByVal DebugLevel As Integer)

comments are welcome as always.


For anyone that's interested, I made a simple page for my code:


In due time I will update this page to something decent, but for now it's just a simple page to keep track of the revisions and changes to the code.


I found out that there was a problem with the links on my website.
I fixed them for the interested people.

I'm also working on a way to add servo support into it.
I am using the Adafruit motorshield, so I'm planning to add all functionality of that to the Arduino_Net project.

Go Up