Problems with the serial buffer

hello everyone :)

I started to build a CNC mill controlled by an Arduino board :D it's all going pretty well. I made a little app using "processing" and it sends instruction to the arduino with "Serial.Write()". (so far so good) the problem is that it sends instructions faster than the CNC mill can deal with. It seem that if Data is sent when the buffer is full, data is ignored.... wich in ma case leads to strange behaviour of my CNC

I can't figure out how to cope with that. I tried adding delay() but it's not the good option, Then I tried this: while (Serial.available()>10){delay(1);} in order to stop the processing app sending data until the buffer is free..... but it works not :-/

any answer will help...

thx

It seems to me that your problem lies with Processing, not the Arduino. Why don't you slow that down?

thx for the fast answer.

i think you are right, but I need to know how slow should i go. of course it'll work if I add 1 second delay after each instructions but then the router will take ages to drill my PCBs.

So, you need to implement some handshaking. Maybe XON /XOFF.

handshaking would be IDEAL!!!! :D but I got no clues about how to make it between processing and an arduino... :-/

Well, the Arduino monitors how many characters it has in its buffer, and if it is greater than say 7/8 the capacity, the Arduino send an XOFF character. Processing receives the XOFF and stops sending. When the Arduino's buffer gets below, say 1/2 full, it sends an XON, and Processing starts sending again. What handshaking have you got between your CNC and the Arduino?

that seem a great idea, but how does the arduino knows about the buffer capacity? I shall read the reference a bit more I suppose;

is the Serial.Write("Xon"); ok? or is there anyother methods for 2 devices to communicate?

thx for all your precious answers ;)

but how does the arduino knows about the buffer capacity

Well, the buffer is 128 bytes long (look at the source), and there's the "Serial.available" method.

is the Serial.Write("Xon"); ok

No, that would send the three byte string "Xon".

Look up the ASCII codes DC1 and DC4 (I think)

ok mate, I'll try to set up some handshake =] I'll let you know and post videos on youtube as soon as it works !! ;)

hey AWOL!!! I finally got My CNC working propperly thanks to you =] I add and "ACK" but no "NACK" after each byte that the arduino board receive so that the computer waits for it before sending the next byte!!! making a video soon!! can't wait to drill my first PCB XD