Get continuous data from Mac

Hello,

I have a simple code like this:

int incomingByte;

void setup() {
Serial.begin(9600);
}

void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
Serial.print(incomingByte);
Serial.flush();
}
}

What I am doing in my project is from an Mac OS X app, sending continuous data to the serial port(USB).
Then on the Arduino, using the above code to print out the reed data, it works fine for a second or two, the the serial monitor stops printing out. What caused this? Is the OS X app sending out to much data which causes the Arduino serial data buffer to overflow? What do I need to do to in order for the Arduino to display the data for as long as the OS X app is running?

Thanks.

1) Loose the Serial.flush() it does not do what you think.

2) You are sending the data back from where it came, if something is jamming up it is the code that is receiving the data. You can't have two things accessing the same port on the Mac ( or any other machine )

Grumpy_Mike: 1) Loose the Serial.flush() it does not do what you think.

2) You are sending the data back from where it came, if something is jamming up it is the code that is receiving the data. You can't have two things accessing the same port on the Mac ( or any other machine )

Thank you for your quick reply.

More questions.

1) I probabaly misunderstood Serial.flush(), so it does flush the buffer, then what does it really do? 2) Are you saying that by using Sreial.print() or Serial.println() actually send data back to the OS X app? If that is the case, then how do I debug to make sure the Arduino actually receives the desired data and how do I make the Arduino to receive data only since my project doesn't require the Arduino to send data back to the app?

Thanks again. :)

1) I probabaly misunderstood Serial.flush(), so it does flush the buffer, then what does it really do?

When in doubt read the manual:- http://arduino.cc/en/Serial/Flush

2) Are you saying that by using Sreial.print() or Serial.println() actually send data back to the OS X app?

Where else would it go?

how do I debug to make sure the Arduino actually receives the desired data and how do I make the Arduino to receive data only since my project doesn't require the Arduino to send data back to the app

If you want a debug feed back channel then you have to have a second serial port. There is only one on a UNO so you have to use software serial. Then in order to get it into your Mac you have to have an separate serial to USB converter as well.

The examples in serial input basics may be useful.

It is generally better to receive the data first and then do something with it. Sending each byte back immediately it is received is not very useful. The Mac should already know what it sent. :)

An Arduino (or anything else) can't receive data faster than it can make use of it so you need some arrangement to stop the Mac sending too much data.

...R