You are not logged in.

#1 2021-10-06 00:39:19

eric.meehan
Member
Registered: 2020-01-01
Posts: 52

CLI 3D Printing

Hello everyone,

I have a CNC router and 3D printer connected to my Arch Linux machine (no GUI), and I want to control them directly via the serial ports.  The CNC router works great, it's CH340 chip with GRBL firmware takes G-Code commands from the terminal:

First I establish the baud rate:

stty /dev/ttyUSB0 115200 raw -echo

Then I can issue commands straight through the USB connection:

cat router_file.gcode > /dev/ttyUSB0

And I can monitor the output in a separate window:

cat < /dev/ttyUSB0

I can even send it commands in batches, meaning the output from a project file can simply be piped into the USB port, though I've only tried this in small numbers so far.  The 3D printer is a bit different.  It has the same CH340 chip, but with the Marlin firmware.  I set up the port in the same way as the router, but the output isn't quite as clean:

echo:busy: processing
                                       echo:busy: processing
                                                                                                   echo:busy: processing
                                                                                                                                                                                    echo:busy: processing
                                                                                                                                                                                                                                                                                          echo:busy: processing
                                                                                                                                                                                                                                                                                                       echo:busy: processing
                                                                                                                                                                                                                                                                                                                                         echo:busy: processing
                                                                                                                                                                                                                                                                                                                                                                                                echo:busy: processing
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            echo:busy: processing
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             echo:busy:
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             processing
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     X:0.00
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Y:0.00
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Z:0.00
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     E:0.00
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Count
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     X:0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Y:0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Z:0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ok

(I have no idea how the webpage is going to format that - on my machine it shows each echo on a new line with each one indented slightly more than the previous)

I can issue a single command to the printer successfully:

echo "G28" > /dev/tty/USB0 # return to home position

I can send a few commands in a script file:

cat file_with_several_commands.gcode > /dev/ttyUSB0

Each command in the file waits its turn and is issued one after the other, with some "busy processing" noise in between.  Now, when I send it a full 3D print job, things get a bit hairy.  The printer will dispense globs of filament, move sporadically, and is completely incapable of printing.  My guess is that sending such a large file all at once is causing the printer to miss some of the commands?  I don't have this output handy, but at one point it was displaying half of a G-Code command and saying "unknown command".  I was thinking that I could script the pipe such that each command would wait for a response from the previous, unfortunately the responses aren't consistent enough for that to be easy (at least on the scale that I'm playing with here haha).

So!  Might there be someone here who is esoteric enough to be able to help me with this?

Offline

#2 2021-10-06 02:12:50

eric.meehan
Member
Registered: 2020-01-01
Posts: 52

Re: CLI 3D Printing

A little progress - the Marlin firmware adds new commands to a queue, and the

echo:busy:processing

output is indicating that it is processing a long command (heating up the bed) and is unable to accept new commands, meanwhile my script has issued all of the commands at once... 

So I began working on a script that will control this execution a little more, waiting for the serial port to respond with "OK" before issuing the next command:

while read gcode
do
    echo "$gcode"
    if [[ $gcode == "" || ${gcode:0:1} == ";" ]]
    then
        continue
    fi
    echo "$gcode" > /dev/ttyUSB1
    while read resp
    do
        echo "$resp"
        if [[ $resp == "ok" ]]
        then
            break
        fi
    done < /dev/ttyUSB1
done < calibration_cube.gcode

Unfortunately, not all of the commands issue any output, so it gets stuck often (though it can be continued); additionally, the device sometimes responds with "ok" before the script switches to reading (?), so it misses some of the output from the device and thus gets stuck again.  The latter problem actually occurs whenever there is a command to move or extrude, since they respond instantaneously...

Offline

#3 2021-10-06 02:24:45

eric.meehan
Member
Registered: 2020-01-01
Posts: 52

Re: CLI 3D Printing

I've experimented a bit with applying a timeout to the inner while loop, but really I only want to timeout if no new input is written to /dev/ttyUSB1.

Offline

#4 2021-10-06 12:24:13

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 3,735

Re: CLI 3D Printing

Please stop bumping your topic. If you have something to add and no one has replied, use the Edit link to add to your existing post.

Offline

Board footer

Powered by FluxBB