Go Down

Topic: VB6 to arduino OUTPUT Slow (Read 465 times) previous topic - next topic

jazmie

Code: [Select]


//O/P ADD
int K01 =  22;      // PIN OUTPUT 01 LED
String incoming = "";   // for incoming serial string data


void setup()
{
// initialize O/P:
  pinMode(K01, OUTPUT);

  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
CheckOUTPUT();
}

void CheckOUTPUT()
{
  if (Serial.available() > 0)
  {
    // read the incoming:
    incoming = Serial.readString();
//    Serial.println(incoming);
   
    if (incoming == ("K01_ON") )
    {
      Serial.println("K01_ON");
      digitalWrite(K01, HIGH); 
    }
    else if (incoming == "K01_OFF")
    {
      Serial.println("K01_OFF");
      digitalWrite(K01, LOW); 
    }     
  }
   
   
    Serial.flush();   
  }





VB Code:

FormMain.Com1.Output = "K01_ON"



i send K01_ON frm vb6 to arduino.

but it take about 2 second for LED response to power on.

ist normal?

sterretje

Yes, readString has a timeout value. It's basically used to determine when no more characters arrive.

Further you should not use String (capital S) if you don't want to experience unexplainable behaviour when you start making heavy use of Strings.

I suggest that you read the serial input basics to get some ideas.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Robin2

Serial.readString() is a blocking function with a timeout.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this - you can get the same effect in any programming language
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


There is no added value in sending "K01_ON" rather than just 'N' for ON and sending a single character will make the Arduino code simpler.

There is this clever idea if you just want to check for single characters.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

jazmie

Serial.readString() is a blocking function with a timeout.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this - you can get the same effect in any programming language
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


There is no added value in sending "K01_ON" rather than just 'N' for ON and sending a single character will make the Arduino code simpler.

There is this clever idea if you just want to check for single characters.

...R

i cant use single character because im planning to control more than 10 Output separately

sterretje

i cant use single character because im planning to control more than 10 Output separately
Just a statement?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

jazmie

Just a statement?
Code: [Select]


void CheckOUTPUT()
{
  if (Serial.available() > 0)
  {
    // read the incoming:
    incoming = Serial.readString();
    Serial.println(incoming);
   
    OUTPUT01();       
    OUTPUT02(); 
    OUTPUT03();   
  }
   
   
//    else
//    {
//      Serial.println("something else");
//      incoming = "";
//    }
    Serial.flush();   
  }

void OUTPUT01()
{
    if (incoming == ("K01_ON") )
    {
      Serial.println("K01_ON");
      digitalWrite(K01, HIGH); 
    }
    else if (incoming == "K01_OFF")
    {
      Serial.println("K01_OFF");
      digitalWrite(K01, LOW); 
    }     


void OUTPUT02()
{
    if (incoming == ("K02_ON") )
    {
      Serial.println("K02_ON");
      digitalWrite(K02, HIGH); 
    }
    else if (incoming == "K02_OFF")
    {
      Serial.println("K02_OFF");
      digitalWrite(K02, LOW); 
    }         
}

void OUTPUT03()
{
    if (incoming == ("K03_ON") )
    {
      Serial.println("K03_ON");
      digitalWrite(K03, HIGH); 
    }
    else if (incoming == "K03_OFF")
    {
      Serial.println("K03_OFF");
      digitalWrite(K03, LOW); 
    }         


Robin2

#6
Oct 17, 2018, 10:06 am Last Edit: Oct 17, 2018, 10:08 am by Robin2
i cant use single character because im planning to control more than 10 Output separately
At last count there were over 60 human readable ASCII characters, and there are 255 in total.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Whandall

I believe you think the following statement does something different than it really does.

Code: [Select]
    Serial.flush();   
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

jazmie

At last count there were over 60 human readable ASCII characters, and there are 255 in total.

...R
now temporary i change using character as advise...its working perfectly.
for string matter just easier for me reference for future and arrange which output etc if compare character that hard to refer.


anyway tq all's

jazmie

I believe you think the following statement does something different than it really does.

Code: [Select]
    Serial.flush();   

ok noted...tq

Go Up