How to send GCode commands using Processing to arduino motorshield 2.3

I managed to find a working Gcode solution for adafruit motorshield v 2.3

this is the code i found and edited a little to make it for 2 axis cnc machine.I have connected two stepper motors taken from 2 dvds and they work from the commands i give from arduino serial.
it has a preleminary support for some basic commands of gcode.

My problem is while it works and i can go to serial and i can manually send commands like G0 X100 Y100
it would be very difficult to execute a gcode script by hand.I managed to insert a pen down and pen up command as M115 and M116 .

I checked and tried to use a serial solution with processing app but it doesnt work.
attached is the pde file and ino arduino file…
I want to use another application to feed the data to arduino.And maybe implement proper penup and pen down solution.That way we could use gcode for adafruit motorshield 2.3
Anyone can help?

gcode_executer.pde (4.18 KB)

STEPPER_MOTOR_FOR_ARDUINO_SHIELD_V2.3b.ino (13.1 KB)

I think you need to change your Title to something like "How to send GCode commands using Processing". If you modify your Original Post you can change the title.

It should certainly be possible but I am not familiar with Processing.

...R

Thank you i changed the title name.The truth is that adafruit motorshield 2.3 does not have support for gbrl so sending gcode seems difficult.Some people have done something.
But sending commands through python programs or processing does not work.
I think it may have something to do with the serial handling?
I think if someone checks how the serial is used in the example i posted maybe it could help me?

Nikodr:
The truth is that adafruit motorshield 2.3 does not have support for gbrl

I am confused. The first line of your Original Post said “I managed to find a working Gcode solution for adafruit motorshield v 2.3”. So which is correct?

What do you need to send from a PC to your Arduino? If what you really need is the number of steps that each motor should make then you can interpret the GCode on the PC to figure out the numbers of steps. I do this with Python for controlling my small lathe.

…R

i am sorry for creating a confusion.I managed to install it.It works,and i can type the commands i want and the axis x and y move.However it is impossible for me to do this by hand.I want to be able to use a python or processing script to do it.I attached the one i found but it doesn't work.While typing in arduino serial terminal the gcode commands it works when i used the attached pde file and running it under processing it does nothing.i can choose the serial port it finds it but when i use a gcode file it does nothing.Nor the buttons move the axis.

I used a terminal program connected to the arduino port and tried to copy paste my gcode to the program.It seems to mess up.All lines are sent at once and the lines are not executed by order and most of them are missed even though are typed on screen.

I want a program so i can send many gcode from a file and that to be executed one by one instruction.

Nikodr:
i can type the commands i want and the axis x and y move.However it is impossible for me to do this by hand.I want to be able to use a python or processing script to do it.

Post some examples of the commands that you type at the serial monitor.

Also copy and paste several lines from the serial monitor so I can see if there is anything being sent to the serial monitor by the Arduino.

...R

here is the serial when the program runs on the adafruit motorshield v2.3
"GcodeCNCDemo4AxisV2 2
Commands:
G00 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)] [F(feedrate)]; - line
G01 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)] [F(feedrate)]; - line
G02 [X(steps)] [Y(steps)] [I(steps)] [J(steps)] [F(feedrate)]; - clockwise arc
G03 [X(steps)] [Y(steps)] [I(steps)] [J(steps)] [F(feedrate)]; - counter-clockwise arc
G04 P[seconds]; - delay
G90; - absolute mode
G91; - relative mode
G92 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)]; - change logical position
M18; - disable motors
M100; - this help message
M114; - report position and feedrate
All commands must end with a newline.

"

i type G00 X100 Y100
then both axes move.
i type G00 X80 only one axes move.I know instructions work.the G90 G91 also work and the m114 and m18.

However whenever i use the processing application with the pde file i posted nothing goes to the serial port.

the source of the processing script is in the attachments of the first post.

The same script works for my other cnc that is with an arduino and 2xld293 chips that drive the motors(but with no shield,just 2 chips connected to arduino with an external power supply but with a different arduino program).I can move both axes and commands send to serial through the script work

on the motorshield the other script run with the same program proccesing does not work.
Any ideas?

Nikodr:
here is the serial when the program runs on the adafruit motorshield v2.3
"GcodeCNCDemo4AxisV2 2
Commands:
G00 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)] [F(feedrate)]; - line
G01 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)] [F(feedrate)]; - line
G02 [X(steps)] [Y(steps)] [I(steps)] [J(steps)] [F(feedrate)]; - clockwise arc
G03 [X(steps)] [Y(steps)] [I(steps)] [J(steps)] [F(feedrate)]; - counter-clockwise arc
G04 P[seconds]; - delay
G90; - absolute mode
G91; - relative mode
G92 [X(steps)] [Y(steps)] [Z(steps)] [E(steps)]; - change logical position
M18; - disable motors
M100; - this help message
M114; - report position and feedrate
All commands must end with a newline.

"

i type G00 X100 Y100

I'm not sure I understand this - correct me if I am wrong. The stuff I have coloured purple looks like a startup message from the program rather than the line-by-line activity as you type things.

If that is correct can you enter a few commands and copy and paste what appears on the Serial Monitor. I particularly want to see if the Arduino sends something back after it has finished responding to G00 X100 Y100 and similar commands.

...R

What i posted is what appears when the program runs on the arduino serial
when i type commands i get this

G00 Y100

Start >
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY< Done.

G00 X100 Y0

Start >
XYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXY< Done.

M114

X100.00
Y0.00
ABS

G00 X50
Start >
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX< Done.

That is what I wanted to see.

Your PC program will have to be able to receive all this data

Start >
XYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXYXY

and effectively ignore it.

but it needs to be waiting to see the tail-end which looks as if it is

< Done.CR LF CR LF>

and only when it gets all that should it send the next command

HOWEVER …
This sequence seems to end differently

M114

X100.00
Y0.00
ABS

>

which will make it a lot more complicated for the PC program to detect when the Arduino is ready for a new message.

A big part of the problem is that the Arduino seems to send a ‘>’ after the word “Start” as well as when it is waiting for input. To be honest if this was my problem I would try to modify the Arduino program so it only prints the ‘>’ when it is ready for more input.

If you are happy to program the PC using Python then this Python - Arduino demo should give you some ideas. But, beware, that my code uses < and > as start end markers and won’t work directly with the output from your Arduino program. Of course if you can modify the Arduino program to put a ‘<’ at the start of every message …

This rambles a bit - hope it makes sense.

…R

This is the arduino program.Can you take a look at it and advice me wether it would be useful for me to try to change it?I have some experiance with coding but i really don’t know if it worth the effort to tackle it.Reason is i found a gbrl port that supports the motorshield 2.3 and i am thinking to switch to that program that supports gbrl.

STEPPER_MOTOR_FOR_ARDUINO_SHIELD_V2.3b.ino (13.1 KB)

First of all, make a backup copy of the existing program.

At the moment line 191 is

Serial.println(F("Start >"));

Change that to

Serial.println(F("Start ="));

Then the only output of the character '>' will be from line 429

Serial.print(F(">"));  // signal ready to receive input

and then your PC program will know that the Arduino is ready for more data when it receives a '>' character.

(Obviously I have not tested any of this :slight_smile: )

...R

For some reason it doesn't work,but i have to check the source of the proccessing script.Thank you for explaining what to do...!

Nikodr:
For some reason it doesn't work,but i have to check the source of the proccessing script.Thank you for explaining what to do...!

There could be 100 reasons why it does not work. And the suggestion I made only makes sense if the PC program is designed to make use of it.

...R