Best solution to managed big data through rs232

Hi, I'm trying to create a CNC machine by using Arduino UNO and Visual Basic code.

Up to now, I'm able to get the information from the gcode, I am able to control the stepper motor sending just one command per time between PC and Arduino, via RS232.

Now I send number of steps for motorx, number of steps for motor y and speed and then the motor does his job..

Now, I want to start with a complete cycle, so to simulate a bunch of information from pc to arduino to stepper motors. My question is: which is the best way to send these information from pc to arduino?

May be, for a complex gcode file, i will need to send thousands of messages with the information for the motors, so thousands of rs232comunication. So a RS232 message, then a motor movement, then another comunication and a motor movement and so on.
My doubt is related with the slowness of the comunication and maybe this is not the best solution.

A better solution could be to send all the information to arduino and only after, start with motor movement.

For me possible solution could be a big multidimensional array, or maybe read the value from the file directly from arduino or..... I don't know.

Any suggestion? Thanks

it depends on the size of your file... will it fit in the Arduino memory if you send it all in one go ? or do you have local storage (like save what you get in SD card and then read it from there to perform the actions)

otherwise you'll need some way to sync the 2 processes, ie have a way to tell the PC - I'm done with the last operations, please send some more

this can be handled over Serial

I suggest that you could investigate now the Grbl firmware handles serial communication.

My doubt is related with the slowness of the comunication

It’s not the limited speed of Serial, but the limited RAM of the UNO, which requires a handshake communication.

The Arduino can handle serial input at 115200 baud or faster. At that speed, it can receive ~11520 characters a second. Lets say a G-code command is 10 characters on average, transmission will take ~a thousandth of a second.

So the slowness will be in your mechanicals, not data transmission.

Moreover, the Arduino has a 64 character buffer, so while your cnc head is making it’s lethargic (by comparison) move to where the first command told it to go, the next several commands can already have been transmitted. You will in fact need to have a mechanism to stop them being sent or the buffer will overflow.

I think that you need to define a protocol.

Send instruction from PC
2)
Wait for a reply from Arduino. The reply can either be send when the command is received or after the instruction has been completed by the cnc or both.
3)
If not all instructions done, back to (1).

Ok thank you very much for all the answer.

I will try with the communication, and I will try to define a way to have a stable data transmission.

From your discussion, you seem to more concerned with the volume of data than with the correctness of the data the Arduino receives. How would you ever know if one of the messages got corrupted by a noise signal?

Paul

To add to Reply #5, if every message from the PC is less than 64 bytes long (so it will fit in the Serial Input Buffer) you can have the Arduino ask for (say) message 7 before it starts the movement determined by message 6, then, when it has finished the movement message 7 should be waiting in the buffer and can be accessed almost instantly, then it asks for message 8 and starts implementing message 7

...R