Pages: [1]   Go Down
Author Topic: trouble sending sensor data to visual basic program  (Read 450 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok guys, first post on here so let me know if i am posting in the wrong thread. I have this visual basic program which every half second reads the existing serial data sent by my arduino mega microcontroller. the controller reads 6 motion sensors (soon to be more if i can get this fixed) and sends a character through the usb serial according to which moiton sensor is triggered. the problem is that after a few hours of the arduino sending serial data my visual basic program sends me an error saying that the com port does not exist or is closed, the port which the controller is connected to. i have tried programming my arduino mega several different ways and am fed up with it so here i am. i think (think) the issue is in my mega programming and that it is disconnecting because of the amount of serial print it is doing, the only thing that fixes my problem is unplugging the arduino and plugging it back in the usb port.ill post the code below. thanks in advance! (oh and i know there is un needed code, i am in the process of adding more sensors but hit this speed bump..)


const int motion = 7;
const int motioncabinet = 8;

const int narvin = 5;

const int frontmotion = 10;
const int frontmotion2 = 11;
const int backmotion = 12;
const int backmotion2 = 13;

int val = 0;

const int phase = 0;   
   
 
   
void setup() {
  Serial.begin(9600);
  // set the digital pin as output;


  pinMode(frontmotion, INPUT);
  pinMode(frontmotion2, INPUT);
  pinMode(backmotion, INPUT);
  pinMode(backmotion2, INPUT);

  pinMode(narvin, INPUT);


  pinMode(motion, INPUT);
  pinMode(motioncabinet, INPUT);
 
}

void loop()
{

 int narvinnum = 1;
 int sensor = digitalRead(motion);
 int sensorcabinet = digitalRead(motioncabinet);
 int sensorfront = digitalRead(frontmotion);
 int sensorfront2 = digitalRead(frontmotion2);
 int sensorback = digitalRead(backmotion);
 int sensorback2 = digitalRead(backmotion2);
 int narvininput = digitalRead(narvin);
 
 String tosend = "a";
 String addedsend = "a";
   if (Serial.available()) {
     
     //Serial.flush();
   
  if(narvininput == HIGH){
  {
    //tosend = addedsend + 'b';
   
  }
   
   if(sensor == HIGH){
     Serial.print('g');
   delay(200);
      //tosend = addedsend + 'g';
     //Serial.write('g');
     //delay(100);
   }
   if(sensorcabinet == HIGH){
     Serial.print('i');
   delay(200);
      //tosend = addedsend + 'i';
     //Serial.write('i');
     //delay(100);
   }
 
   if(sensorfront == HIGH){
     Serial.print('c');
   delay(200);
      //tosend = addedsend + 'c';
     //Serial.write('1');
     //delay(100);
   }
  if(sensorfront2 == HIGH){
     Serial.print('d');
   delay(200);
      //tosend = addedsend + 'd';
     //Serial.write('2');
     //delay(100);
  }
   
   if(sensorback == HIGH){
     Serial.print('e');
   delay(200);
      //tosend = addedsend + 'e';
     //Serial.write('3');
     //delay(100);
   }
     
   if(sensorback2 == HIGH){
    Serial.print('f');
   delay(200);
      //tosend = addedsend + 'f';
     //Serial.write('4');
     //delay(100);
   }
   
   
 
     {
   
   Serial.print(tosend);
   delay(200);
   //tosend = ('a');
   
     }
   
   
}
   
}
}
Logged

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

oh i forgot to add the //then code under each if statement was my previously tried thoughts that did not work.
Logged

Ottawa,Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

blame windows ...
if you look up "usb disconnecting" you see a raft of issues
 
looks like the "power down scheme" is the thing to blame
Logged

Pages: [1]   Go Up
Jump to: