How to use a secondary Arduino to control GRBL

Hi,
I have a grbl shield running on Arduino Uno and I want to add some more functionalities to my project using a secondary arduino.

For example, one arduino drives grbl and is connected to my motors. And a master arduino for reading digital/analog sensors and sending appropriate commands to the first arduino (grbl).

Please note that my second Arduino is also connected to a PC through serial communication.

Diagram:

// +------------+        +---------------+       +--------------+
// |            |        |               |       |              |
// |            | serial |               |       |              |
// |    PC      +-------->   Arduino     +------->    Arduino   |
// |            <--------+   master      +------->     grbl     |
// |            |        |               |       |              |
// +------------+        +---^--------^--+       +------+-------+
//                           |        |                 |
//                       +---+---+ +--+----+        +---v---+
//                       |sensor0| |sensor1|        | Motor |
//                       +-------+ +-------+        +-------+

Also I don't want to use Arduino AccelStepper library for precision reasons.
Does anyone know a standard way to achieve this efficiently?

Thanks in advance.

To use the AccelStepper library to control your steppers you would have to remove grbl which has its own stepper control. That would be fine if you didn't need the gcode interpreter in grbl. You would need to define a protocol the master Arduino would use to tell your AccelStepper sketch what to do.

To make that work the master would need 2 serial ports. The serial port that talks to the "slave" Uno would need to be capable of 115200 baud. So the master might better be a Mega with its 3 extra hardware serial ports.

To talk to grbl the master would need to be like a gcode sender (see interfacing with grbl).

Can you explain why you think AccelStepper to be imprecise?

I see. I didn’t know that mega comes with 3 ports.

Grbl implementation is much more fine tuned. It can more precisely drive multiple stepper at a time using the interrupt handlers.
Accelstepper suffers from numerous reported issues like loosing step in reverse direction. Less accurate acceleration profile and lower max speed.
For sensitive applications I found grbl more reliable.

Actually I dont want to use accelstepper library. That’s why I wanted to use grbl. Accelstepper is not precise compared with grbl.

OK, I did not know those things about AccelStepper versus Grbl.

So the master will take measurements and generate G code to send to Grbl on the slave Uno or does the PC send the G code and the master will pass it on and insert G code into the stream?

Not sure how would be the impact of delays but I was thinking of the latter.
I plan to read an encoder reading by the master (which should be in high rate) and then send the proper gcode command to the slave to make it closed loop control.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.