ARDUINO WITH VISUAL BASIC 6

I want make communication between arduino and visual basic 6 through serial com.
For Send character frm vb6 to arduino its working.the LED function properly.
But for function arduino send to vb6 got problem.
Once i push the button,i check in vb,i no receive "c" or any response that should send frm arduino.
my arduino program as below:

//LED
int led= 9;
//_________________________

//BUTTON
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
//_________________________


void setup() 
{

Serial.begin(9600);

pinMode(led, OUTPUT);

pinMode(pushButton, INPUT);

}

void loop() 

{
  if (Serial.available())
  
  //---------------------OUTPUT--------------------------------------
  {
    int COMRead = Serial.read();
    
     if (COMRead=='a')
       {
        digitalWrite(led,LOW);
       }
     else if(COMRead=='b')
       {
        digitalWrite(led,HIGH);
       }
       
  //-------------------INPUT------------------------------------------
    // read the state of the pushbutton value:
    //buttonState = digitalRead(buttonPin);

    else if (pushButton == HIGH)
//        Serial.write('c');
        //int bytesSent = Serial.write("hello"); //send the string "hello" and return the length of the string

  // read the input pin:
{
  Serial.write(45); // send a byte with the value 45

   int bytesSent = Serial.write("c"); //send the string "c" and return the length of the string.
}
  }
}

Does your VB program leave the serial port open to receive data ?

if (pushButton == HIGH) it is very unlikely that two will ever equal one.
Did you forget a digital read?

Please remember to use code tags when posting code.

I use VB6 quite a bit for front-ending Arduino. One thing I have found to be useful, that by-passes everything built in to protect us from ourselves, is to have the comm port in VB configured for InputMode equal to 1 - comInputModeBinary.

You get past all the inherent checking, blah, blah, blah and end up dealing with a simple bit stream. Works (tested) to 1Mbps.

AWOL:

 if (pushButton == HIGH)

it is very unlikely that two will ever equal one.
Did you forget a digital read?

@OP
Have you taken care of the above comment – Did you forget a digital read?

Look at the following figure and observe that the MCU/program does not see your pushButton. The MCU reads the pin-value (via gate G2D). The pin-vale (DPin-2) assumes LH if the pushButton (K1) is closed, and it assumes LL if the pushButton (K1) is at open position. (Assuming that you have installed external pull-down resistor.)

So, you need to execute –

digitalRead(2);
===> digitalRead(pushButton);

UKHeliBob:
Does your VB program leave the serial port open to receive data ?

Yes port open

GolamMostafa:
@OP
Have you taken care of the above comment -- Did you forget a digital read?

Look at the following figure and observe that the MCU/program does not see your pushButton. The MCU reads the pin-value (via gate G2D). The pin-vale (DPin-2) assumes LH if the pushButton (K1) is closed, and it assumes LL if the pushButton (K1) is at open position. (Assuming that you have installed external pull-down resistor.)

So, you need to execute --

digitalRead(2);

===> digitalRead(pushButton);

{facepalm}

AWOL:

 if (pushButton == HIGH)

it is very unlikely that two will ever equal one.
Did you forget a digital read?

Please remember to use code tags when posting code.

What you mean two will ever equal one?

Digital read?

GolamMostafa:
@OP
Have you taken care of the above comment -- Did you forget a digital read?

Look at the following figure and observe that the MCU/program does not see your pushButton. The MCU reads the pin-value (via gate G2D). The pin-vale (DPin-2) assumes LH if the pushButton (K1) is closed, and it assumes LL if the pushButton (K1) is at open position. (Assuming that you have installed external pull-down resistor.)

So, you need to execute --

digitalRead(2);

===> digitalRead(pushButton);

Noted

Will try

What you mean two will ever equal one?

Digital read?

The pushButton variable is set to 2 by your program

int pushButton = 2;

So pushButton will never equal HIGH which has a value of one

To read the state of the pushButton pin you need to use the digitalRead() function
See digitalRead()

UKHeliBob:
The pushButton variable is set to 2 by your program

int pushButton = 2;

So pushButton will never equal HIGH which has a value of one

To read the state of the pushButton pin you need to use the digitalRead() function
See digitalRead()

Will try..thx

i wan try to make IO using vb6.im upload this code

//OUTPUT
int led= 1;
//_________________________

//INPUT
int pushButton = 2;
//_________________________

int button=0;

void setup() 
{

Serial.begin(9600);

pinMode(led, OUTPUT);

pinMode(pushButton, INPUT);

}


void loop() {
//___________________________________________INPUT____________________________________________________
  

  button=digitalRead(pushButton);

  if (button == HIGH)  
  {
    Serial.write('1');
    delay(0.5);        // delay in between reads for stability
  }  
  else (button==LOW);
  { 
    Serial.write('0');
    delay(0.5);        // delay in between reads for stability
  }

//__________________________________________OUTPUT___________________________________________________

    int COMRead = Serial.read();

     if (COMRead=='0')
       {
        digitalWrite(led,LOW);
        //delay(0.5);
       }
     else if(COMRead=='1')
       {
        digitalWrite(led,HIGH);
        //delay(0.5);
       }
}

but once done upload the LED suddenly power ON even i not yet open my vb.which part i do mistake.plz advise…tq in advance

(button==LOW);Oopsdelay(0.5); Oops

ist like this?

//OUTPUT
int led= 1;
//_________________________

//INPUT
int pushButton = 2;
//_________________________

int button=0;

void setup() 
{

Serial.begin(9600);

pinMode(led, OUTPUT);
pinMode(pushButton, INPUT);

}


void loop() {
//___________________________________________INPUT____________________________________________________
  

  button=digitalRead(pushButton);
  if (button == HIGH)  
  {
    Serial.write('1');
    delay(1);        // delay in between reads for stability
  }  
  else
  { 
    Serial.write('0');
    delay(1);        // delay in between reads for stability
  }

//__________________________________________OUTPUT___________________________________________________

    int COMRead = Serial.read();
    
     if (COMRead=='1')              //ON
       {
        digitalWrite(led,HIGH);
        delay(1);
       }
     else
       {
        digitalWrite(led,LOW);
        delay(1);
       }    
}

ist like this?

NO!

//OUTPUT
int led= 1;

Serial.begin(9600);

pinMode(led, OUTPUT);

Do you want to use pin 1 for Serial OR for the LED? Both is the WRONG answer. So is yes.

    delay(1);        // delay in between reads for stability

You misspelled stupidity. delay() does NOT cause stability.

PaulS:
NO!

//OUTPUT

int led= 1;

Serial.begin(9600);

pinMode(led, OUTPUT);



Do you want to use pin 1 for Serial OR for the LED? Both is the WRONG answer. So is yes.



delay(1);        // delay in between reads for stability



You misspelled stupidity. delay() does NOT cause stability.

Pin1 for OUTPUT(LED)
Pin2 for INPUT(Button)

that delay comment i just copy directly sample from arduino app…Examples>Basics>DigitalReadSerial

Serial.begin(9600);

pinMode(led, OUTPUT);

Don't you see the problem here?

(Hint: look closely at what is written next to pin one)