Está en la página 1de 15

"Control Arduino with VB.

NET"
Buenas a tod@s,
Espero con esta nueva entrada poder contribuir con mi granito de arena a ayudar a todos
aquellos que os habis animado en el mundo de la electrnica a intentar hacer alguna
aplicacin con "Visual Basic .NET y Arduino". Sin ms preambulos aqu esta todo lo
que necesitis.
Os presento la aplicacin "Control Arduino with Visual Basic .NET by RS232-USB"
realizada en "VB .NET para controlar Arduino" Uno, cuyo microcontrolador es el
ATMega328P-PU. Con ella podris manejar a vuestro gusto cualquiera de los puertos de
I/O de la tarjeta, tanto los pines digitales, como los PWM as como tambin los
analgicos.
Esta es la fachada de como ha quedado la aplicacin:

"VB.NET Arduino"
Aqu os muestro la tarjeta que he usado para el control y las pruebas:

Y un pequeo esquema con el montaje:

En este par de vdeos os muestro como manejar la aplicacin de "VB .NET para
controlar Arduino"

En esta imagen os muestro las alternativas de configuracin software que se puede


hacer de los pines I/O del Arduino (aunque no todos los pines soportan la configuracin

PWM). Lo mejor es usar el datasheet del microcontrolador ATMega328P-PU, para


aclarar cualquier duda sobre las posibles configuracin de cada pin de I/O.

De todos modos en el cdigo tanto del Arduino como en el de la aplicacin de Visual


Basic .NET os he dejado explicado los comandos de las tramas de comunicacin
enviadas y lo que significa cada valor. Como podeis observar es un protocolo que me he
inventado y que no tiene porque ser de esta manera, cada uno puede hacerse el suyo
acorde a sus necesidades o a su gusto.
// SALIDA PWM / PWM OUTPUT
// In this case, for do any actions with PWM the received command must be:
// Example: P03_OUT_125
// Where
//
inDatoVB[0] = P --> PWM PIN
//
inDatoVB[1] = Number of the pin (tens)
//
inDatoVB[2] = Number of the pin (units)
//
inDatoVB[3] = Always Character '_'
//
inDatoVB[4] = Character 'O' -->
//
inDatoVB[5] = Character 'U' --> Type of PIN OUTPUT
//
inDatoVB[6] = Character 'T' -->
//
inDatoVB[7] = Always Character '_'
//
inDatoVB[8] = Units value -->
//
inDatoVB[9] = Tens value -->
value XXX To PWM
//
inDatoVB[10] = Hundreds value -->
//SALIDA DIGITAL / DIGITAL OUTPUT
// In this case, for do any actions with DIGITAL OUT the received command must be:
// Example: D03_OUT_XX0
// Where:
//
inDatoVB[0] = D --> DIGITAL PIN
//
inDatoVB[1] = Number of the pin (tens)
//
inDatoVB[2] = Number of the pin (units)
//
inDatoVB[3] = Always Character '_'
//
inDatoVB[4] = Character 'O' -->

//
//
//
//
//
//

inDatoVB[5] = Character 'U' --> Type of PIN OUTPUT


inDatoVB[6] = Character 'T' -->
inDatoVB[7] = Always Character '_'
inDatoVB[8] = Always Character 'X'
inDatoVB[9] = Always Character 'X'
inDatoVB[10] = State of the out PIN --> Value 0 or 1

//ENTRADA DIGITAL / DIGITAL INPUT


// In this case, for do any actions with DIGITAL IN the received command must be:
// Example: D03_IN__XXX
// Where:
//
inDatoVB[0] = D --> DIGITAL PIN
//
inDatoVB[1] = Number of the pin (tens)
//
inDatoVB[2] = Number of the pin (units)
//
inDatoVB[3] = Always Character '_'
//
inDatoVB[4] = Character 'I' -->
//
inDatoVB[5] = Character 'N' --> Type of PIN INPUT
//
inDatoVB[6] = Always Character '_'
//
inDatoVB[7] = Always Character '_'
//
inDatoVB[8] = Always Character 'X'
//
inDatoVB[9] = Always Character 'X'
//
inDatoVB[10] = Always Character 'X'
// ENTRADA ANALOGICA / ANALOG INPUT
// In this case, for do any actions with ANALOG INPUT the received command must
be:
// Example: A03_IN__XXX
// Where:
//
inDatoVB[0] = A --> ANALOG PIN
//
inDatoVB[1] = Number of the pin (tens)
//
inDatoVB[2] = Number of the pin (units)
//
inDatoVB[3] = Always Character '_'
//
inDatoVB[4] = Character 'I' -->
//
inDatoVB[5] = Character 'N' --> Type of PIN INPUT
//
inDatoVB[6] = Always Character '_'
//
inDatoVB[7] = Always Character '_'
//
inDatoVB[8] = Always Character 'X'
//
inDatoVB[9] = Always Character 'X'
//
inDatoVB[10] = Always Character 'X'
En esta otra imagen, podis observar los comandos que se envan va serie al Arduino
para que el Software en Visual Basic .NET los interprete y en consecuencia acte sobre
los pines I/O. Como podeis comprobar los comandos que se encuentran de color verde
son los comandos que hemos construido desde la aplicacin de VB.NET para enviar al
arduino y que anteriormente os explicado unas lineas ms arriba.

Esta es la estructura de como he dejado las regiones del cdigo de la aplicacin:

Pues bien, aqu os dejo todo el cdigo de la aplicacin realizada con Visual Basic .NET:

Cdigo de la Aplicacin "Control Arduino with VB .NET"


(Incluye el cdigo .ino para Arduino y todo el cdigo Visual Basic .NET ms la libreria
.dll del Led)
Haz click para descargar
Por cierto, la libreria .dll del led a la que me refiero es la que se encuentra en otra pgina
de este mismo blog.
http://proyectoselectronicacreativa.blogspot.com.es/2014/10/user-control-led-withvisual-basic-net.html
(Precisamente, esto fue, lo que me hizo retrasar la publicacin completa de esta entrada,
pues hasta que no finalice el control LED .dll no decid publicarlo, pues quera hacer
uso de la misma como ejemplo de uso de este mismo control)
Y el cdigo fuente que habra que volcar en el Arduino. Lleva algunos comentarios as
como la explicacin del protocolo que me he generado:

Cdigo fuente para la tarjeta de Arduino.

https://drive.google.com/file/d/0By2_W81NKkeAOHMxWEI3VzhaVEk/view?
usp=sharing
Pantallazo de como es programado con xito el fichero de configuracin para el
Arduino.

Finalmente os dejo tambin un par de vdeos donde se ven como se maneja la aplicacin
software junto con la placa board de pruebas. En ellos veris el funcionamiento
completo de control sobre todos los pines I/O.

Espero que os guste y que a partir de este ejemplo podis hacer vosotros vuestras
aplicaciones de control con Arduino personalizadas para vuestras aplicaciones. ....
nimo!...
Ya estoy en marcha con nuevos ejemplos ....!!
Un saludo y hasta pronto.

"User Control LED with Visual Basic .NET"


Hi everybody,

From now I'm going to write the pages of my blog in english. The reason is
very simple, I would like that they can be read for as many people as
possible, so .... I hope with my english writing don't scare anyone, it is not
perfect but I'll try to do the best possible.

Said that! ... here I show you a new page where I've been working to make a
user "control LED for Visual Basic .NET".

It is a very simply control that many times we use in many electronics GUI
(graphical user interface) applications and some times we don't have in
none control toolboxes in the IDE Software (integrated development
environment).

This picture show the aspect of the LED.

These are all colors to choose:

Here I show you a video where the user contol LED have been used in an
example application.

How to use the user control LED from the .dll compiled library
.

Here, attached the .dll library for user "control LED"

.dll Library for "User Control LED"


https://drive.google.com/file/d/0By2_W81NKkeAekZYTUlaSW1sRG8/view?
usp=sharing

In order to use it, you should follow the next steps:


1.Create a new proyect.

2. Choose the tipical project: Windows Forms

3. Go to the toolbox and there, select the general tab and over there click
with the right button mouse to open the emergent menu.

4. Select the option "Select elements". Here, click over tab "Components
.NET Framework" and click over button. A new windows dialog box are
shown. You should look for the user contol LED file .dll that you should have
if
you
have
downloaded
from
the
link
indicated
before.

5. If the user control LED have been loaded succesfully, you can use it as
you can see in the next picture. Exactly in the tab general you can find the
new user control.

6. Select the new user control with the mouse and drag and drop over the
window form and this appear drawn. This control can be setup as whatever
other control with his properties window.

7. Finally, include this code and run the code with F5. A picture like this
would be shown.

That's all! , Just now, we have an application with our new user control LED.

Example application that use the user control LED.

I've developed a small application that shown how can be setup this user
control. Its appearance is shown you in this picture.

It's enough for show you how the control works and its characteristics.
I hope that you like it!

"Library .dll and .exe for User


Control LED"
https://drive.google.com/file/d/0By2_W81NKkeAeEladGx6YjBfSEk/view?
usp=sharing
(Remember, copy the .dll file in the same path where is the executable
file .exe)

Click over this link to download the source code for "User Control LED" .

"Source Code for User Control LED"


https://drive.google.com/file/d/0By2_W81NKkeAVGFsRXJjWmp1a1U/view?
usp=sharing

This is another link where I show you a good example where I've used the
.dll "VB.NET Led". Really is other page of the blog.

También podría gustarte