Pages: [1] 2   Go Down
Author Topic: VB 2010 & Arduino Uno - Serial Communication  (Read 3019 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can not make VB 2010 to work with  Arduino Uno. I am a beginner. Please check my attached files and tell me where i am wrong.
Thanks



* StepperMotor28BYJ.txt (1.19 KB - downloaded 26 times.)
* Form1.pdf (16.34 KB - downloaded 27 times.)
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using Linux and it's a long time since I did anything with VB.

In this Thread I recently wrote a Python program and corresponding Arduino sketch to illustrate communicating with a PC. The principles will be the same whatever language you use.

...R
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You probably ought to call Serial.begin() in setup. Without that, nothing gets written to the serial port, or read from it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I add Serial.begin(9600);
Nothing happen.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I add Serial.begin(9600);
Nothing happen.

This doesn't sound like a serious attempt at debugging.

Have you tried sending/receiving data to/from the same Arduino sketch using the Serial Monitor? Does that work?

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI Robin2,
Your are right. I checked it again and realized that I put "Serial.begin(9600)" in "void loop()".
Once I moved it to "void setup()" section, everything work. ...... Beginner at the beginning.
Sorry guys. It works now. Thanks..
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Robin2,
After one run with VB 2010, Arduino stops responding. I have to unplugged/plugged USB in order to make it work.
I have to do the same procedure again. Do I miss anything ?.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you get the same problem when using the Arduino Serial Monitor, or only with VB?

It sounds like the Arduino is resetting, and a common cause of that is someone trying to power a motor from the Arduino board. Motors generally draw too much current and should have their own power supply.

Does the program seem to work properly if you disconnect the motor?

If the problem exists with both the Serial Monitor and VB then you should sort out the problem with the Serial monitor before you introduce the complication of VB.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Motor works OK all day long without VB. There is no one else using the same com port but me.
After loading VB, the motor responses one time and no more. I have to close both VB and Arduino sketches, then unplug USB
After that, I plug USB back, load VB and Arduino sketch. It works for one time and stops.
I think my VB program is the culprit.
Thanks for looking into it.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible your VB code is inappropriately closing (or not closing) the serial port?

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Robin2,
Found the problem. I did not reset my variable "count" in Sketch.
So after the first run, the variable is out of range. That is why the Sketch stops
Thanks for all your help.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad it's working and thanks for telling us what solved the problem.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Today, I have another problem with Arduino Uno to receive string text.
from VB 2010:
SerialPort1.Open()
 SerialPort1.Write("ABC")
 SerialPort1.Close()

then upload the attached *.ino file. Then open Arduino serial monitor to track progress.
NOTHING

Please help.
Thanks

* VB_ARDUINO_STRTest.ino (0.57 KB - downloaded 13 times.)
Logged

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7724
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't seen anyone testing for the serial buffer being less than empty before.

Nevertheless look very carefully at how your IF statements are organized and ask yourself when the second one will be triggered.

"Very carefully" means go through the code step by step with a pencil and paper.

...R
Logged

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1593
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some help...
Code:
//You need space for the null terminator, since you want 3 characters you need an extra to the null terminator 3+1
#define STR 4
char buffer[STR];
//--------------------------------------------------
void setup(){
  Serial.begin(9600);        
}
//---------------------------------------------------
void loop(){
  if (Serial.available() <0) {   //Ok if you dont have nothing print like crazy ...
    Serial.print("Empty");
    delay(1000);
  }
  if (Serial.available() >=3) {//It will need 3 bytes to run, this way you insure it's safe to read the 3 bytes in a while loop
//Serial comunication are very slow, if you try to read the 3 bytes when you detect the first one you will not get the next because the second one hasn't arrived yet
    int i = 0;
    while (i <= 2) {
      Serial.print(i);
      buffer[i++] = Serial.read();//Use i and then increment it after
    }
    buffer[3] = '\0';//In order to print it below like a string you need to terminate the char array with a 0
    Serial.print("OK I received");
    Serial.println(buffer);    //Here you should get the string correctly
  }
}

Obvios this is presuming you are just sending 3 characters from the VB
« Last Edit: April 23, 2014, 05:29:39 pm by HugoPT » Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Pages: [1] 2   Go Up
Jump to: