arduino+vb6

Use this Arduino sketch to upload to your board
DO NOT CHANGE ANYTHING!!!

void setup()
{                
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(7, OUTPUT);
  Serial.begin (9600);
}
void loop()
{

  int a = digitalRead (2);
  int b = digitalRead (3);
  int c = digitalRead (4);
  int d = digitalRead (5); 
  //digitalWrite (7,LOW);
  {
    if (a == HIGH)
    {
      Serial.println("<a>");
      digitalWrite (9, HIGH);
      Serial.println ("Red is the color of Led/ The pressures value is 20psi");
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);

    }
    else if (a == LOW)
    {
      digitalWrite (9, LOW);

    }

    if (b == HIGH)
    {
        Serial.println("<b>");
      digitalWrite (10, HIGH);
      Serial.println ("Green is the color of Led/The pressures value is 40psi");
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);
      
    }
    else if(b==LOW)
    {
      digitalWrite (10, LOW);
     
    }

    if (c == HIGH)
    {
      Serial.println("<c>");
      digitalWrite (11, HIGH);
      Serial.println ("Blue is the color of Led/The pressures value is 60psi");
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);
      delay (200);
      digitalWrite (7, HIGH);
      delay (400);
      digitalWrite (7, LOW);
      
    }
    else if (c==LOW)
    {
      digitalWrite (11, LOW);
     
    }

    if (d == HIGH)
    {
        Serial.println("<d>");
      digitalWrite (12, HIGH);
      Serial.println ("Yellow is the color of Led/The pressures value is 80psi");
      delay (200);
      digitalWrite (7, HIGH);

    }
    else if (d==LOW)
    {
      digitalWrite (12, LOW);
 
    }

  }
}

Create a new project and use the code below you need a put a label called (label1)and caption it "Com Port Number. add a communication object named (MSComm1). Put in a text box called
(ComPort). Add another longer text box called (text1). add a command button called (Command1)change the caption to "find com port". now add another text box called (text1).
Next add a shape object called (Shape1)
compile and run the code. Put the number of the com port into the text box called ComPort... just type in "1". click the command button and the other text box should show the pressure and the shape object should change colors.
If it is the wrong com port you will see the error 8002 comport not found ( or whatever it says)
Then re start and try another port till it doesn't give error messages.
DO NOT CHANGE THE CODE!!!

' Option Explicit
' this is added to allow the sleep call
Private Declare Sub Sleep Lib "kernel32" ( _
    ByVal dwMilliseconds As Long)


Private Sub LEDOn(col As Long)

 Shape1.BackColor = col
End Sub

Private Sub LEDOff()

 Shape1.BackColor = &HFFFFFF
End Sub


Private Sub Command1_Click()
If Val(ComPort) < "1" Then Exit Sub
With MSComm1
        If .PortOpen Then .PortOpen = False
        .CommPort = Val(ComPort)
        .Settings = "9600,N,8,1"
        .DTREnable = True
        .RTSEnable = True
        .RThreshold = 4
        .SThreshold = 3
        .PortOpen = True
  End With
End Sub

Private Sub MSComm1_OnComm()
Dim strData As String
Static strBuffer As String
Dim strWords() As String
Dim intPos As Integer
Dim boComplete As Boolean
Dim mystr As String


 
        Sleep 1000 'this waits one second between readings from the Arduino
        mystr = "" ' set the string to nothing
        mystr = MSComm1.Input
      
   
            intPos = InStr(mystr, "<")
            If intPos > 0 Then
           
                Select Case Mid(mystr, 1, 3) ' strip off the CR/LF
                    Case "<a>"
                        Text1.Text = ("The pressures value is 20 psi")
                        Call LEDOn(vbRed) ' this is in hex
                    Case "<b>"
                        Text1.Text = ("The pressures value is 40 psi")
                        Call LEDOn(vbGreen) ' this is in hex
                    Case "<c>"
                        Text1.Text = ("The pressures value is 60 psi")
                        Call LEDOn(vbBlue) ' this is in hex
                    Case "<d>"
                        Text1.Text = ("The pressures value is 80 psi")
                        Call LEDOn(vbYellow) ' this is in hex
                    Case Else
                       Call LEDOff
                End Select
         End If

End Sub

thanks for replying RPCoyle i'll be online in this consecutive days it's a big opportunity for me to keep in touch with this forum.

now, regarding on what you've posted..i just need to clarify this

Create a new project and use the code below you need a put a label called (label1)and caption it "Com Port Number.

base on what i understood...i change the caption on the label as 1

add a communication object named (MSComm1). Put in a text box called (ComPort).

do i have to put a textbox on my form then if it is..i change the text into ComPort

Add another longer text box called (text1). add a command button called (Command1)change the caption to "find com port". now add another text box called (text1).

i add a longer textbox and change the text as text1, then i add a command button and change the caption into find com port, then i add another textbox and change the text text1

kindly check RPCoyle if all of this are right or did we understand each other..thanks!

Glenn... you are on your own. You need to learn enough about VB to correctly label and initialize the form objects.

If you do as I instructed, the form will work.

I have actually done your project for you. The code on both sides of the com port work. If there is anything left to do, or if for some reason the communications still do not happen then you must work it out yourself.

I wish you Good luck, but this will be my last post to you except perhaps say congratulations, if you send a post that says you completed the project and made it work.

thanks RPCOyle.. ;)i know i'm so makulit..but please am asking you to stay on touch on resolving this just for today and tomorrow.. :disappointed_relieved:

..regarding on what you've posted i made it already and yet it works but what i wanted to happen is, the input should be done from the arduino going to the vb application..it seems, when i press the switch button from my hardware which is connected to the arduino i can see on the serial monitor the "" then the "" should be sent to the vb application..inshort, there is no more pressing the button that may happen to the vb and no more command button should be added, all the vb should do is receiving the input from arduino..

anybody please help me..

First build visual basic 6 project :

Added to the form1 :

  1. Label1
  2. Shape1 then copy it to 8 Piece. *It will be array sequence so the name will be = shape1(0) to shape1(7)
  3. MSComm1

Open on source code interface copy and paste this source code :

Dim angka(8) As Integer //--> this smile will be your enemy 8 )

Private Sub Form_Load()
For i = 0 To 7
Shape1(i).FillStyle = 0
Shape1(i).FillColor = vbRed
angka(i) = "0"
Next
MSComm1.RThreshold = 8
MSComm1.InputLen = 8
MSComm1.Settings = "9600,n,8,1"
MSComm1.CommPort = 2
MSComm1.PortOpen = True
MSComm1.DTREnable = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub

Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
sData = MSComm1.Input
Label1.Caption = ""
For i = 0 To 7
angka(i) = Asc(Mid$(sData, i + 1, 1))
Label1.Caption = angka(i) & Label1.Caption
If angka(i) = "1" Then
Shape1(i).FillColor = vbYellow
Else
Shape1(i).FillColor = vbRed
End If
Next
End If
End Sub

After done make sure you setup the comport number on the visual basic same with your arduino used.

For the arduino program load this to your hardware :

Try used ide2.2 version i dont know either it work with ino1.0 version

//----------------------------------------------------------------------------

int kaki[9]= {-1,2,3,4,5,6,7,8,9};
int baca[9]={0,0,0,0,0,0,0,0,0};

void setup() {
Serial.begin(9600);
for (int i = 1; i <= 8; i++) {
pinMode(kaki*, INPUT);*

  • }*
    }
    void loop() {
  • for (int i = 1; i <= 8; i++) {*
    baca_=digitalRead(kaki*);
    Serial.print(baca,BYTE);
    }
    delay(100);
    }
    //-------------------------------------------------------------------------------
    And the hardware setup is like this :_

    *

To check what comport number your arduino is :

I assume you install all the driver needed and can used arduino.

Right click my computer select > properties > devices manager

now plugin usb cable to your arduino

look at Device Manage > Port (COM&LPT) it will show your arduino comport number.
*Take note the comport number and replace on vb 6 source code.

thank you so much for your reply majdi_mohammad.. :open_mouth:
i'll try this when the time i come home...
but before anything else, this code you posted the inputs are 8 supposedly it's only 4 because the other 4 are just an indicator of the first 4 if it works ( base on the arduino only)..well, again i'll try this.. :%

The code that i post will be:

8 pushbutton on arduino

when push the push button on arduino:

In vb6 will be change to red colour.

  • I dont get how you want it be? maybe you can explain in detail how it will be? :wink:

hello,
it's been a long time..by the way, i try your code for the arduino but when i use to compile this, there is an error occur in this code:

 pinMode(kaki, INPUT)

which means invalid conversion from int* to 'unit8_t'..what does it mean?..

i used the arduino version 0021

..thanks for keeping in touch.. :wink:

Glennmars:
hello,
it's been a long time..by the way, i try your code for the arduino but when i use to compile this, there is an error occur in this code:

 pinMode(kaki, INPUT)

which means invalid conversion from int* to 'unit8_t'..what does it mean?..

i used the arduino version 0021

..thanks for keeping in touch.. :wink:

change pinMode(kaki, INPUT) to pinMode(kaki[i], INPUT)

hello majdi_mohammad, i just want your help on doing that below..i find hard to do this in vb because i there are many textboxes..

Create a new project and use the code below you need a put a label called (label1)and caption it "Com Port Number. add a communication object named (MSComm1). Put in a text box called
(ComPort). Add another longer text box called (text1). add a command button called (Command1)change the caption to "find com port". now add another text box called (text1).
Next add a shape object called (Shape1)
compile and run the code. Put the number of the com port into the text box called ComPort... just type in "1". click the command button and the other text box should show the pressure and the shape object should change colors.

Thanks!

hello retrolefty!

i change the code just like what you've suggested and yet it's okay but another thing appears as an error in this code:

 baca=digitalRead(kaki);

that means invalid conversion from int* to 'unit8_t'.

but another thing appears as an error in this code:

So, look at that that code is doing. It is trying to read from an array of pins, when it is designed to read from a pin. The function is not designed to take an array of pins, so the compiler is telling you that.