arduino+vb6

Gosh Glen, we seem to be going around in circles.

The code I gave you in reply #22 works... I tried it, it works with your Arduino script.

You still seem to be thrashing around trying to get the VB app to read COM 1.

The code should work if you are sending data from the Arduino to the VB on COM 1.

Even if the data doesn't match what VB is looking for, it should not give you a error message. it should just do nothing.

Are you sure that the Arduino board is sending data out on COM 1? When you open Tools/Serial Port from the menu does it say COM 1 and can you then look at the serial monitor sending out data on this port?

I guess the other question is... is your Arduino board a real Arduino board made by the folks in Italy or is it some clone made by some other company. I bought a couple of clones from China that had different chips for serial communication and I had trouble with them using the Arduino 1.0 rev and had to go back to rev .021 to even get a download.

This is probably not your problem, but I can see nothing much else to try.

Oh buy the way, it seems like way back some time you actually did get the VB to connect with the Arduino. Is that true or just my imagination?

hi RPCoyle am sorry if i keep on inquiring 'coz until now still i find nothing..

base on what you said, i had two installer of arduino the latest version which is the 1.0 and also the .0021....i used the old version which is the .0021 and yet it works on the arduino..i can see in the serial monitor the and so on when i press the switch button but when i run the vb6 application and press the button switch nothing happens..seems it goes back to the problem before that when i run the arduino then next to that is the vb app then as i pressed the button switch the LED will not flash or nothing happens to it... :disappointed_relieved:

hope you understand me.. :frowning:

thanks

hello again...

i just want to show you my edited code..this code will be able to access the switch button which is connected in arduino when i run the vb application..i just inserted your code RPCoyle in finding the commport...just take a look if what is lacking on this because i can only access the button switch but nothing sends to vb application or we may say the circle doesn't fill any color.... :sweat_smile:

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


Private Sub Form_Load()
Dim mystr As String
Dim FoundIt As Integer
Dim ComFail As Integer
Dim FailErr As Integer
Dim n As Integer

MSComm1.Settings = "9600,N,8,1"
FoundIt = False
' find USB port
ComFail = False
FailErr = False
For n = 1 To 1
  If MSComm1.PortOpen Then MSComm1.PortOpen = False
   On Error Resume Next
   MSComm1.CommPort = 1
   On Error Resume Next
   'MSComm1.DTREnable = True
    'MSComm1.RThreshold = 4
    'MSComm1.SThreshold = 3
   MSComm1.InputLen = 0
   MSComm1.PortOpen = True
Next
End Sub

Private Sub LEDOn(col As Long)

 Shape1.BackColor = col
End Sub

Private Sub LEDOff()

 Shape1.BackColor = &HFFFFFF
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 "<Y>"
                        Text1.Text = ("The pressures value is 80 psi")
                        Call LEDOn(&HFFFF&) ' this is in hex
                    Case "<B>"
                        Text1.Text = ("The pressures value is 60 psi")
                        Call LEDOn(&HFF0000) ' this is in hex
                    Case "<R>"
                        Text1.Text = ("The pressures value is 20 psi")
                        Call LEDOn(&HFF&) ' this is in hex
                    Case "<G>"
                        Text1.Text = ("The pressures value is 40 psi")
                        Call LEDOn(&HFF00&) ' this is in hex
                    Case Else
                       Call LEDOff
                End Select
         End If
        
End Sub

thanks :wink:

Sorry Glen, we are still going in circles. I asked you what COM port showed up in the Tools/Serial Port menu in the Arduino IDE when you are seeing the correct data coming out on the Serial Monitor window.
Answer this question, and then maybe we can go further.

actually, you can set the comport on any vacant or not in used port...right.?. now base on what you've ask RPCoyle it's Commport 1..whenever i open the arduino then go to tools/serial port it's comport 1..then when i open the serial monitor it's still com1... but i can change this if ever i want by just right clicking the computer/properties/device manager/port(COM & LPT)/port settings/advance/comport number..

You may see more than one com port listed in the tool/serial port menu, but only one com port will work to give you the output from the board. you can not set the comport for the Arduino to any vacant or not in used port. If you do not select the correct port you will not see anything on the serial monitor.

The only valid port for you is the com port that shows the correct values on the serial monitor for your board... Which com port selected from the tool/serial port menu gives you the correct output on the serial monitor?

it's comport 1 RpCoyle...i can see on the serial monitor the "" and the rest of this when i hit the button with the commport value which is commport1...

how about correcting those components i put on my vb.?.just try to correct this:

as i open the vb application first thing i did was inserting the component, i open the Project/components/controls/(i check the) micsrosoft comm control 6.0..after that i put the component that appears on the toolbox picture like a telephone on the form, then i put a textbox and a shape on a form also..
my regard is, is this all right.?. :roll_eyes:

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