Páginas

viernes, 2 de enero de 2015

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

Hi, here it is another second part ....

What's this?



It's an application to "control a display 7 Segments with Arduino and Visual Basic.NET" very similar with the page of the Display LCD. If you want to see it, click over this link.


I'll show you the way to "control display 7 segments" 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 7 segments.




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 7 segments .dll"


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 7 segments 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 7 segments.

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




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 7 segments 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 7 segments and following the text to show with a number maximum of characters, that it coincide with the number maximum of the display 7 segments (32 Characters)


// CONTROL DISPLAY 7 SEGMENTS
// In this case, for do any actions with Display 7 Segments the received command must be:
// Example: D7S_X (Where X is a number and this number indicates the command to do)
// Where inDatoVB[0] = D --> Communications with Display (Uses to be different from other actions)
//       inDatoVB[1] = 7 --> Communications with Display
//       inDatoVB[2] = S --> Communications with Display
//       inDatoVB[3] = Always Character '_'
//       inDatoVB[4] = Character '_', '0', '1' , ... --> It's the command from GUI VB.NET to Arduino Display 7 Segments
//                         '_' Clear the Display 7 Segments from the application GUI VB.NET    
//                         '0' Write 0 in the Display 7 Segments from the application GUI VB.NET
//                         '1' Write 1 in the Display 7 Segments from the application GUI VB.NET
//                         '2' Write 2 in the Display 7 Segments from the application GUI VB.NET
//                         '3' Write 3 in the Display 7 Segments from the application GUI VB.NET
//                         '4' Write 4 in the Display 7 Segments from the application GUI VB.NET
//                         '5' Write 5 in the Display 7 Segments from the application GUI VB.NET
//                         '6' Write 6 in the Display 7 Segments from the application GUI VB.NET
//                         '7' Write 7 in the Display 7 Segments from the application GUI VB.NET
//                         '8' Write 8 in the Display 7 Segments from the application GUI VB.NET
//                         '9' Write 9 in the Display 7 Segments from the application GUI VB.NET


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 7 Segments with Arduino and Visual Basic .NET 1.0.1.0
//'   It shows a program that control the text send to the display 7 Segments 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 © 2015 
//'   Rubén García Coronado 
//'   Email: rubengaco13@gmail.com
//'   Created: Jan 2015
//'
//'   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/>.
//'*****************************************************************************************



//Variable to know the size of the received command
int len;
char inDatoVB[5];  //Array to save the text received form the RS232
const int PinCount = 4;    // the number of LEDs in the bar graph
int ledPins[] = { 2, 3, 4, 5 };   // an array of pin numbers to which LEDs are attached


//Setup the serial communications and four pines as outputs for the display 7 Segments
void setup()
{

  // loop over the pin array and set them all to output:
  for (int thisPin = 0; thisPin < PinCount; thisPin++) 
  {
    pinMode(ledPins[thisPin], OUTPUT); 
  }
  
 Serial.begin(115000);   //Speed 
 pinMode(13, OUTPUT);    //Setup the used pin
 Serial.print("Lista la Comunicacion RUBEN");  //Send a message to the port

 // Write the data to the Pin array to inicializate to a value 0 the display 7 segments
 digitalWrite(ledPins[0],LOW);
 digitalWrite(ledPins[1],LOW);
 digitalWrite(ledPins[2],LOW);
 digitalWrite(ledPins[3],LOW);


}

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,6);
  
     
// CONTROL DISPLAY 7 SEGMENTS
// In this case, for do any actions with Display 7 Segments the received command must be:
// Example: D7S_X (Where X is a number and this number indicates the command to do)
// Where inDatoVB[0] = D --> Communications with Display (Uses to be different from other actions)
//       inDatoVB[1] = 7 --> Communications with Display
//       inDatoVB[2] = S --> Communications with Display
//       inDatoVB[3] = Always Character '_'
//       inDatoVB[4] = Character '_', '0', '1' , '2' ... --> It's the command to do from GUI VB.NET to Arduino Display 7 Segments
//                         '_' Clear the Display 7 Segments from the application GUI VB.NET    
//                         '0' Write 0 in the Display 7 Segments from the application GUI VB.NET
//                         '1' Write 1 in the Display 7 Segments from the application GUI VB.NET
//                         '2' Write 2 in the Display 7 Segments from the application GUI VB.NET
//                         '3' Write 3 in the Display 7 Segments from the application GUI VB.NET
//                         '4' Write 4 in the Display 7 Segments from the application GUI VB.NET
//                         '5' Write 5 in the Display 7 Segments from the application GUI VB.NET
//                         '6' Write 6 in the Display 7 Segments from the application GUI VB.NET
//                         '7' Write 7 in the Display 7 Segments from the application GUI VB.NET
//                         '8' Write 8 in the Display 7 Segments from the application GUI VB.NET
//                         '9' Write 9 in the Display 7 Segments from the application GUI VB.NET

//Clear the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='_')
     {
    // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],HIGH);
  digitalWrite(ledPins[2],HIGH);
  digitalWrite(ledPins[3],HIGH);

     }
        
    //Show number 0 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='0')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],LOW);
}
     
      
    //Show number 1 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='1')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],LOW);
}
     
    //Show number 2 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='2')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],HIGH);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],LOW);
 }
     
     //Show number 3 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='3')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],HIGH);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],LOW);
 }

//Show number 4 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='4')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],HIGH);
  digitalWrite(ledPins[3],LOW);
 }
 
  //Show number 5 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='5')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],HIGH);
  digitalWrite(ledPins[3],LOW);
 }
 
  //Show number 6 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='6')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],HIGH);
  digitalWrite(ledPins[2],HIGH);
  digitalWrite(ledPins[3],LOW);
 }
 
  //Show number 7 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='7')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],HIGH);
  digitalWrite(ledPins[2],HIGH);
  digitalWrite(ledPins[3],LOW);
 }
 
  //Show number 8 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='8')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],LOW);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],HIGH);
 }
 
  //Show number 9 in the Display 7 Segments 
    if(inDatoVB[0] =='D' && inDatoVB[1]=='7' && inDatoVB[2] =='S' && inDatoVB[3]=='_' && inDatoVB[4]=='9')
     {
  // Write the data to the Pin array:
  digitalWrite(ledPins[0],HIGH);
  digitalWrite(ledPins[1],LOW);
  digitalWrite(ledPins[2],LOW);
  digitalWrite(ledPins[3],HIGH);
 }

    
  }

}


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 compueter, 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 the number 0 is shown in the display 7 segments:



6. Lauch the VB.NET application and open de communication port. With this program you can write the number (from 0 up to 9) that you want to show in the display 7 segments, for example:



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



It's enough for show you how control a display 7 segments 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 7 Segments"

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

"Source Code for Control Display 7 Segments"



Bit by bit we are making the way ....

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