Gcode Help for newbie

A little help please. Newbie trying to understand gcode and SM CNC. I’ve read several posts about gcode and SM, but I’m obviously missing something. I’ve read the posts @scyto and @Artezio about SM 2 Marlin 2 gCode Support. I’ve got @JKC20 G-code Reference for SM. I’ve looked at the Marlin.org site and All3DP G-code tutorial. It all looks fairly simple. I try to modify a cnc file (using Windows Notepad), save it to USB (as a cnc file) and try to run it on the A350, the touch-pad ‘runs’ the timer, but the tool-head does nothing. So, I start with some basic gcode, just moving the head around.
G28
G90
G21
G0 X0 Y0 Z0
G0 Z100
G0 X-120 Y-120
G0 Z10.00 F1500
G1 X120 Y-120
G0 Z1.00
M3 P100
G0 X0 Y-120
G1 X120 Y-120 F1000
G0 Z100
G0 X-120 Y120
G1 X120 Y120
M3 P0
G0 Z10.00
G1 X0 Y120
G0 Z20
M5

Loads into Luban Workspace and it looks fine in Workspace Preview. Yet when I try it from the USB, the A350 doesn’t do anything except run the timer. I try it from Luban (Start on Luban; serial connection) and all I see in the console is echo:Unknown command: “”. I know I’m connected; G28 from the console and a few other things, including the individual G commands, work fine. Obviously, I’m missing something that I haven’t seen in the forum (or at least not by the keyword searches I’ve tried) or on the other sites.

Thanks

I really don’t see anything wrong with that gcode. Can you run the commands line by line manually through the Luban terminal, connected either over wifi or USB? I’d wager all of those commands work. Alternatively, could paste that all into a Luban macro and run the macro.

If I had to guess what the problem is, maybe a line ending problem from your text editor. Zip and post the file for review?

Also I have a stylistic comment. If you’re manually writing the codes you can save some effort by omitting the Y param when you’re only moving in X.

G0 X-120 Y120
G1 X120 Y120 ; Unnecessary Y on this line, it's the same as previous

Also it seems you have certain speeds in mind for G0 and G1. You can put this at the top of the file if you like:

G0 F1500
G1 F1000

And then you don’t have to include feedrates on the first line that uses it, makes it a little easier to change in the future. Also it will prevent slight errors like you have where the first G1 is used before the F1000 speed is set later. The speed at which that first G1 runs is undefined and is dependent on what previous file ran or if it’s fresh machine startup (1500mm/min default I think).

1 Like

Thanks @brent113, I thought the code should work also, that’s the problem.
As I mentioned, if I feed each line separately into the A350 via Luban and a serial connection, each line does what it should. It is trying the code with ‘Start on Luban’ from the Workspace or via a USB that it doesn’t work. I agree it sounds like the text editor, but I’m using Windows NotePad, which in the past has done well on VBA and some Python code. It should be a simple text editor. What does @xchrisd or others use when editing code?

As far as stylistic comments, yeah, I know, but I’m playing around and doing the full line codes and speed changes ‘just to be sure’. I also tried it with headers but deleted the headers ‘just to be sure’ they weren’t causing issues for some reason.

Attached is a zip file for the cnc code, all 2 kb worth.
Test2.zip (464 Bytes)

Thanks.

Missed that. Good to know.

Can’t speak for chris but I use notepad++ on windows. Your line endings are \r\n which is valid.

Are you on the latest firmware? Could be something with that.

Does it run from Luban using the macro feature? Does it work from the touchscreen as a .nc file with the laser head or a .gcode file with the 3DP head?

This feels like a bug to me. Would be more likely to have a productive conversation with support if you can hand them a repeatable test case with specifics.

For simple files i use editor which is notepad in english, i guess. For huge things i use visualstudio code.

Interesting case, anyway.

What version of Luban do you use?
I guess there is something screwed up in wifi transfer with terminal, may you try a older version? - Sending lines of code did work the whole time i can remember.

Edit: Did the machine home if you start your code right after turning on?

Thanks @ Xchrisd and @brent113. Traced the problem down to something about Windows Notepad and the way I was opening the code. Not sure exactly what yet, but creating a new file without reusing the previous file, the new raw code worked fine from both USB and serial Luban.

Brent, how do you see the \r\n at the line ends; I just see it as a CR or HRT? I’d like to explore if there is any other ASCII code that might make the file invalid.
Chris, just for completion, Luban 4.2.2 and A350 is 4.4.16, and, yes, it homed upon startup just fine.

Again, thanks for pointing me in a better direction.

I ‘think’ mystery solved. For some reason, the original file was saved using UTF-16 coding. Changing it to UTF-8 and things seem to work. I’ll re-look at my original project now.

Oh yea can’t do utf-16. In notepad++ you can turn on visibility of all symbols, they show up as CR LF but I usually use \r \n escape sequences to refer to those since that’s what C, regular expressions, and most everyone else uses, same thing though.