All,
I am trying to develop a HPGL plotter using Arduino (Mega 1280 board).
The PC (Autocad) sends data to Arduino via USB Serial port, but some bytes are lost (probably because of Arduino buffer size and timeout). How can I implement software handshake? Any working example would be very wellcome.
What baud rate are they set to?
You may slow down the baud rate to accomplish your goal.
Is the arduino doing other tasks while the serial signal is coming in?
Do you have any delay() commands in your sketch? If so, take them out to let the arduino run faster.
Hi,
I am trying with 9600 bps.
I am receiving HPGL codes, example "PD" means pen down, "PU" means pen up, "PD100,100" means move with pen down to position 100,100 (X,Y). So, after receiving some bytes (e.g. PD100,100), I have to move the motors to the target position, and I also use delay(2) for each motor step.
Any idea?
You may get better results with a slower baud rate ( try 300), on both arduino and PC
And reduced delays.
Maybe use the blink without delay code in the example code, to get rid of all delays.
I don't know of anyway to do software handshaking with the PC. Maybe someone else here does?
edumarzolla:
I have to move the motors to the target position, and I also use delay(2) for each motor step.
You need to design your solution so that the Arduino is capable of processing the commands at least as quickly as they arrive. A 2ms delay for each motor step makes me think that some movements could take tens, hundreds or perhaps even thousands of milliseconds to complete. In that case it would be very easy for the source of the commands to overrun the Arduino so you need to have a scheme to ensure that the commands aren't sent quicker than they can be received.
One option would be to have the Arduino read and buffer all commands that are sent and then execute them in the background, but the limited memory available on an Arduino would make that approach problematic.
The alternative approach would be to introduce flow control on the serial interface so that the Arduino only accepts commands as fast as it can handle them. Does the thing generating the commands support any form of serial flow control?
It appears your pc program is sending information faster than the plotter can preform them. Your pc program should have some governor to prevent that. Maybe that is where to look.
BTW, did the 300 baud rate help any?