Páginas

jueves, 27 de noviembre de 2014

"Control Display LCD with Arduino and Visual Basic .NET" Part II

Hi, here it is this new page ....

What's this?



It's an application to "control a display LCD with Arduino and Visual Basic.NET"

I'll show you the way to "control the display LCD from Visual Basic .NET" through Arduino.

For this, I've developed a graphical interface standalone written in Visual Basic .NET with a own protocol to communicates the Arduino board with the VB .NET application for controlling the display LCD.




For the high level application, I've used an user control .dll, developed by me months ago and that you can find in another page of this blog. Click over the next link,  if you want to see it or download the "display LCD .dll"

http://proyectoselectronicacreativa.blogspot.com.es/2014/01/control-display-lcd-con-visual-basic.html

Also, you can use for other applications you want to develop.

For the low level application, I used the IDE Arduino and I developed a small application to communicate with the Display LCD besides to an own protocol for understanding the commands send from the VB .NET application to Arduino, and from Arduino to the inputs/outputs of the pins of display LCD.

This is the schematic for the conections between Arduino inputs/outputs pins with de Display LCD.



Click to this link for downloading the schematic:



Below, it's shown the true schematic mounted over prototype board.



As you can see, when the code is loaded in Arduino board right away it's ready for receive commands from the VB.NET application. It's indicated with a message in Display LCD saying: Ready to receive.

The protocol to communicate the application VB.NET with Arduino it is very easy. It an own protocol where you can select the number of bits or streaming that you want to send. Exactly I made this command to indicates that a message will be sent to the Display LCD and following the text to show with a number maximum of characters, that it coincide with the number maximum of the display LCD (32 Characters)


 // CONTROL DISPLAY LCD
 // In this case, for do any actions with Display LCD the received command must be:
 // Example: LCD_X (Where X is a number and this number indicates the command to do)
 // Where inDatoVB[0] = L --> Communications with LCD (Uses to be different from other actions)
 //            inDatoVB[1] = C --> Communications with LCD
 //            inDatoVB[2] = D --> Communications with LCD
 //            inDatoVB[3] = Always Character '_'
 //            inDatoVB[4] = Character '_', '0', '1' , '2' ... --> It's the command to do from GUI VB.NET to Arduino Display LCD
 //                            '_' Write the received text from the application GUI VB.NET 
 //                            '0' Clear the Display LCD from the application GUI VB.NET
 //                         ... other values to extend the characteristic in the future.    


In order to program the Arduino Board with the code, you should follow the next steps:

1. Download the file with the code for Arduino. You can do it from this link:


or copy this code and save in a file.

//'*****************************************************************************************
//'                           LICENSE INFORMATION
//'*****************************************************************************************
//'   Example Application for Control a display LCD with Arduino and Visual Basic .NET 1.0.1.0
//'   It shows a program that control the text send to the display LCD from 
//'   a GUI developed in Visual Basic .NET through serial/usb port
//    It's implemented an own small protocol to do the communication very easy.

//'   Copyright © 2014  
//'   Rubén García Coronado 
//'   Email: rubengaco13@gmail.com
//'   Created: Dec 2014
//'
//'   This program is free software: you can redistribute it and/or modify
//'   it under the terms of the GNU General Public License as published by
//'   the Free Software Foundation, either version 3 of the License, or
//'   (at your option) any later version.
//'
//'   This program is distributed in the hope that it will be useful,
//'   but WITHOUT ANY WARRANTY; without even the implied warranty of
//'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//'   GNU General Public License for more details.
//'
//'   You should have received a copy of the GNU General Public License
//'   along with this program.  If not, see <http://www.gnu.org/licenses/>.
//'*****************************************************************************************


#include <LiquidCrystal.h>

//Variable to know the size of the received command
int len;
char inDatoVB[37];

char inDatoVB_Comando[5];
char inDatoVB_Linea_1[16];
char inDatoVB_Linea_2[16];

char scroll = '0';
int Texto_LCD_in;


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//Setup the serial communications and display LCD
void setup()
{
 Serial.begin(115000);   //Speed 
 pinMode(13, OUTPUT);    //Setup the used pin
 Serial.print("Lista la Comunicacion RUBEN");  //Send a message to the port

 lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
 lcd.print("Ready to receive"); // Print a message to the LCD.
}

void loop()
{
  if (Serial.available() > 0)
  { 
   //Data received are read in the variable inDatoVB array  
   //These values are the streaming that would be sent from application GUI VB .NET
   //They are read all bytes and are checked for knowing what is the action to do.
         
    len = Serial.readBytes(inDatoVB,38);
  
     
    // CONTROL DISPLAY LCD
    // In this case, for do any actions with Display LCD the received command must be:
    // Example: LCD_X (Where X is a number and this number indicates the command to do)
    // Where inDatoVB[0] = L --> Communications with LCD (Uses to be different from other actions)
    //       inDatoVB[1] = C --> Communications with LCD
    //       inDatoVB[2] = D --> Communications with LCD
    //       inDatoVB[3] = Always Character '_'
    //       inDatoVB[4] = Character '_', '0', '1' , '2' ... --> It's the command to do from GUI VB.NET to Arduino Display LCD
    //                         '_' Write the received text from the application GUI VB.NET 
    //                         '0' Clear the Display LCD from the application GUI VB.NET    
    //                         ... other values to extend the characteristic in the future.

    if(inDatoVB[0] =='L' && inDatoVB[1]=='C' && inDatoVB[2] =='D' && inDatoVB[3]=='_' && inDatoVB[4]=='_')
     {
    lcd.setCursor(0, 0);  

           //Write the first line in the Display LCD   
  for (int i=5; i<21;i++)
  {
           lcd.print(inDatoVB[i]);
  Serial.print(inDatoVB[i]);
           }
          
            //Write the second line in the Display LCD
           lcd.setCursor(0, 1);
  for (int j=21; j<37;j++)
  {
  lcd.print(inDatoVB[j]);
  Serial.print(inDatoVB[j]);
  }

     }
       else
       {
       }
  
    //Clear all Display LCD and data 
    if(inDatoVB[0] =='L' && inDatoVB[1]=='C' && inDatoVB[2] =='D' && inDatoVB[3]=='_' && inDatoVB[4]=='0')
     {
        lcd.clear();
         for (int k=6; k<37;k++)
  {
            inDatoVB[k]=' ';
            }
     }
    
    else
    {
    }
  }

}

2. Conect the Arduino Board to the USB port. Automatically, would be detected, if it's not like this because it's the first time that you connected the Arduino to your computer, I recommend go to this link to solve any problem:


3. Open the file downloaded before.


4. Click over button verify and then click over button load.

5. Click on reset button of Arduino board and a message was shown in the Display LCD indicating: Ready for receive.


6. Lauch the VB.NET application and open de communication port. With this program you can write the message that you want to show in the LCD display, for example:



7. Click over button Send to LCD or keypress enter. Automatically the message written will be send and shown in the LCD display. See the next figure:



It's enough for show you how control a display LCD with Arduino and Visual Basic .NET, the best way to check it would be download the code and test it for yourself.

I hope that you like it!

.dll Library and .exe for "Control Display LCD"

(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 "Control Display LCD" with "Arduino & VB.NET" .

"Source Code for Control Display LCD"



A greeting. 

-----------------------------------------------------------------------------------------------------------------------------------------------------
Please, if you liked this blog, has helped you or have you seen any interesting project or you've been able to download some documentation please leave a comment. Thank you. 



------------------------------------------------------------------------------------------------------------------------------------------------------


No hay comentarios:

Publicar un comentario

Deja tu comentario