Skip to main content

I am new to stack overflow. I have a question regarding using the USB serial communication sending data from an OS X app to the Arduino Mega 2560.

What happenhappens is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Arduino does receive the data for a few secondseconds, then it stops.

This is the simplified Object-C code on the Mac side:

-(IBAction)sendData:(id)sender{
    

        NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x];
    //vector is the continuous data generated by the Mac
        const char *toCSend =[toSend UTF8String];
    //converting to c string
        printf("%s", toCSend);
        popen(toCSend, "r");
    
}

This is the code on the Arduino side:

// Read Serial input:
void setup() {
  // Open Serial commurial1.beginnications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for Serial port to connect. Needed for Leonardo only
  }
}

void loop() {
  
  // Read Serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();
 
    if (inChar != '\n') {
      inString += (char)inChar;
      Serial.read();
    } else {
      // if you get a newline, print the string,
      // then the string's value as a float:
    else {
      Serial.println(inString.toFloat(), 6);
      // clear the string for new input:
      inString = "";
 
    }//end of if else
  }//end of while (Serial.available() > 0)
}

I am not sure what the problem, could it be the OS X app send out too much data to quickly? Or could it be the Arduino serial buffer is overflowed?

I really don't know much about serial communication so I don't know what I am missing. Any help will be greatly appreciated.

I am new to stack overflow. I have a question regarding using the USB serial communication sending data from an OS X app to the Arduino Mega 2560.

What happen is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Arduino does receive the data for a few second, then it stops.

This is the simplified Object-C code on the Mac side:

-(IBAction)sendData:(id)sender{
    

        NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
        const char *toCSend =[toSend UTF8String];  //converting to c string
        printf("%s", toCSend);
        popen(toCSend, "r");
    
}

This is the code on the Arduino side:

// Read Serial input:
void setup() {
  // Open Serial commurial1.beginnications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for Serial port to connect. Needed for Leonardo only
  }
}

void loop() {
  
  // Read Serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();
 
    if (inChar != '\n') {
      inString += (char)inChar;
      Serial.read();
    }
    // if you get a newline, print the string,
    // then the string's value as a float:
    else {
      Serial.println(inString.toFloat(), 6);
      // clear the string for new input:
      inString = "";
 
    }//end of if else
  }//end of while (Serial.available() > 0)
}

I am not sure what the problem, could it be the OS X app send out too much data to quickly? Or could it be the Arduino serial buffer is overflowed?

I really don't know much about serial communication so I don't know what I am missing. Any help will be greatly appreciated.

I am new to stack overflow. I have a question regarding using the USB serial communication sending data from an OS X app to the Arduino Mega 2560.

What happens is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Arduino does receive the data for a few seconds, then it stops.

This is the simplified Object-C code on the Mac side:

-(IBAction)sendData:(id)sender{
    NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x];
    //vector is the continuous data generated by the Mac
    const char *toCSend =[toSend UTF8String];
    //converting to c string
    printf("%s", toCSend);
    popen(toCSend, "r");
}

This is the code on the Arduino side:

// Read Serial input:
void setup() {
  // Open Serial commurial1.beginnications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for Serial port to connect. Needed for Leonardo only
  }
}

void loop() {
  // Read Serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();
    if (inChar != '\n') {
      inString += (char)inChar;
      Serial.read();
    } else {
      // if you get a newline, print the string,
      // then the string's value as a float:
      Serial.println(inString.toFloat(), 6);
      // clear the string for new input:
      inString = "";
    }//end of if else
  }//end of while (Serial.available() > 0)
}

I am not sure what the problem, could it be the OS X app send out too much data to quickly? Or could it be the Arduino serial buffer is overflowed?

I really don't know much about serial communication so I don't know what I am missing. Any help will be greatly appreciated.

code block
Source Link
Gerben
  • 11.3k
  • 3
  • 22
  • 34

What happen is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the AriduinoArduino does receive the data for a few second, then it stops.

-(IBAction)sendData:(id)sender{
    NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
    const char *toCSend =[toSend UTF8String];  //converting to c string
    printf("%s", toCSend);
    popen(toCSend, "r");

}

-(IBAction)sendData:(id)sender{
    

        NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
        const char *toCSend =[toSend UTF8String];  //converting to c string
        printf("%s", toCSend);
        popen(toCSend, "r");
    
}

This is the code on the Arduino side: // Read Serial input: void setup() { // Open Serial commurial1.beginnications and wait for port to open: Serial.begin(9600); while (!Serial) { // wait for Serial port to connect. Needed for Leonardo only } }

void loop() {

// Read Serial input: while (Serial.available() > 0) { int inChar = Serial.read();

if (inChar != '\n') {
  inString += (char)inChar;
  Serial.read();
}
// if you get a newline, print the string,
// then the string's value as a float:
else {
  Serial.println(inString.toFloat(), 6);
  // clear the string for new input:
  inString = "";

}//end of if else

}//end of while (Serial.available() > 0) }

// Read Serial input:
void setup() {
  // Open Serial commurial1.beginnications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for Serial port to connect. Needed for Leonardo only
  }
}

void loop() {
  
  // Read Serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();

    if (inChar != '\n') {
      inString += (char)inChar;
      Serial.read();
    }
    // if you get a newline, print the string,
    // then the string's value as a float:
    else {
      Serial.println(inString.toFloat(), 6);
      // clear the string for new input:
      inString = "";

    }//end of if else
  }//end of while (Serial.available() > 0)
}

I really don't know much about serial communication so I don't know what I am missing. Any help wiwill be greatly appreciated.

What happen is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Ariduino does receive the data for a few second, then it stops.

-(IBAction)sendData:(id)sender{
    NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
    const char *toCSend =[toSend UTF8String];  //converting to c string
    printf("%s", toCSend);
    popen(toCSend, "r");

}

This is the code on the Arduino side: // Read Serial input: void setup() { // Open Serial commurial1.beginnications and wait for port to open: Serial.begin(9600); while (!Serial) { // wait for Serial port to connect. Needed for Leonardo only } }

void loop() {

// Read Serial input: while (Serial.available() > 0) { int inChar = Serial.read();

if (inChar != '\n') {
  inString += (char)inChar;
  Serial.read();
}
// if you get a newline, print the string,
// then the string's value as a float:
else {
  Serial.println(inString.toFloat(), 6);
  // clear the string for new input:
  inString = "";

}//end of if else

}//end of while (Serial.available() > 0) }

I really don't know much about serial communication so I don't know what I am missing. Any help wi be greatly appreciated.

What happen is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Arduino does receive the data for a few second, then it stops.

-(IBAction)sendData:(id)sender{
    

        NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
        const char *toCSend =[toSend UTF8String];  //converting to c string
        printf("%s", toCSend);
        popen(toCSend, "r");
    
}

This is the code on the Arduino side:

// Read Serial input:
void setup() {
  // Open Serial commurial1.beginnications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for Serial port to connect. Needed for Leonardo only
  }
}

void loop() {
  
  // Read Serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();

    if (inChar != '\n') {
      inString += (char)inChar;
      Serial.read();
    }
    // if you get a newline, print the string,
    // then the string's value as a float:
    else {
      Serial.println(inString.toFloat(), 6);
      // clear the string for new input:
      inString = "";

    }//end of if else
  }//end of while (Serial.available() > 0)
}

I really don't know much about serial communication so I don't know what I am missing. Any help will be greatly appreciated.

Source Link

Serial communIcation from OS X app to Arduino Mega

I am new to stack overflow. I have a question regarding using the USB serial communication sending data from an OS X app to the Arduino Mega 2560.

What happen is, when I have the Arduino running with the Serial monitor open, then I run the OS X app to send data, the Ariduino does receive the data for a few second, then it stops.

This is the simplified Object-C code on the Mac side:

-(IBAction)sendData:(id)sender{
    NSString *toSend=[NSString stringWithFormat:@"echo %f > /dev/tty.usbmodem1a1341" ,vector.x]; //vector is the continuous data generated by the Mac
    const char *toCSend =[toSend UTF8String];  //converting to c string
    printf("%s", toCSend);
    popen(toCSend, "r");

}

This is the code on the Arduino side: // Read Serial input: void setup() { // Open Serial commurial1.beginnications and wait for port to open: Serial.begin(9600); while (!Serial) { // wait for Serial port to connect. Needed for Leonardo only } }

void loop() {

// Read Serial input: while (Serial.available() > 0) { int inChar = Serial.read();

if (inChar != '\n') {
  inString += (char)inChar;
  Serial.read();
}
// if you get a newline, print the string,
// then the string's value as a float:
else {
  Serial.println(inString.toFloat(), 6);
  // clear the string for new input:
  inString = "";

}//end of if else

}//end of while (Serial.available() > 0) }

I am not sure what the problem, could it be the OS X app send out too much data to quickly? Or could it be the Arduino serial buffer is overflowed?

I really don't know much about serial communication so I don't know what I am missing. Any help wi be greatly appreciated.