Jump to content

Ways to send gcode direct to printer or control during printing?


helical

Recommended Posts

Posted · Ways to send gcode direct to printer or control during printing?

Hi, I've got a few Ultimakers (2's and 3's) and would like to directly control them from my computer.  That means moving the print head, extruding, controlling temperature, and all functions that can be described in gcode (and more?)  What I would like to do, ideally, is to bypass Cura completely and use a remote control protocol like OSC, or serial, or even JSON to have direct printing control.  But, as you can imagine, these would be time-sensitive commands so I'd require something reliable and quick.  Right now, I'm just looking for options.  I figured direct serial control would work but now I see that UM3's are running a full Linux stack so it's all a black box to me.  As far as I can tell, this hasn't been done before on Ultimakers, although similar things exist for Makerbots, etc.

 

And I'm well aware that there are serious risks of this, it's for a research project and I have experience with hardware and software development.  That said, I'd be an idiot if I said that I know what all of them are before starting, so any warnings and suggestions would be appreciated!

 

Thanks!

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Well the Um2 is simpler.  You can control it through USB (it's not officially supported but it works pretty well).  It has Marlin firmware which is on hundreds of different types of printers (most printers out there).  There is software called "octoprint" that allows you to control printers through USB or you can simply send gcodes with any software you want to write.

     

    The um3 indeed has a linux stack.  You can log in with ssh username and password is root/ultimaker.  You have to put the printer into developer mode first (it's a menu option on the printer).

     

    Everything is in python so the source code is all visible and commented on the printer itself.  Well some of it is in json files (javascript).

     

    Once in you can go to the /usr/share/griffin folder and do this:

    python3 command_util.py

     

    Then do "sendgcode" followed by the gcode you want to send.  This might be too slow (not real time enough for you) so you might want to create some kind of web service.  If you do *please* share. :)

     

    If you prefer - here is a video of someone doing just what I describe.  There are more details on this forum but you can ask more questions on this topic if you want.  For example the M104 and M109 commands might not work without enabling the hot end.  That gcode is um3 specific and is somewhere on this forum.  But here it is: M145 T0 -- enables ability to heat that core.

     

    Oh and be very very careful when editing json files.  If you have a parse error in a json file (missing comma for example), the boot process halts *before* it starts the ssh daemon so you effectively brick the machine but I here are 2 methods for unbricking if that happens - you might want to buy these cables ahead of time if you will be editing json files:

     

     


     

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Oh and EVERYTHING can be done in gcode.  So there is no "and more".  I mean you can home, turn power on and off, control steps/mm, basically you can do much more from gcode than you can do from menus.  On um3 you can control color of lights from gcode.  On um2 you can change the display message form gcode.  For um2 the best gcode reference is here (just look at Marlin gcodes):

    http://reprap.org/wiki/G-code

  • Link to post
    Share on other sites

    Posted (edited) · Ways to send gcode direct to printer or control during printing?

    You might want to look at Repetier-Host. RH lets you control - bed temp.; extruder(s) temp.; print speed; filament flow rate and flow %; fans speed; all during the print. You can also send individual lines of g-code to the printer (whether this works during a print I do not know). I have used it to control my prints on my 3ntr for the past 4 years. It has a server version too which allows you to control multiple printers and provides remote access/control. Cura and other slicers can be invoked.

    It also provides velocity painting to change the look and feel of the object surface but I have not tried that yet, although the pics look good!

    https://www.repetier.com/

    Edited by yellowshark
  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Thanks! That's a great start.

    For the python code that comes with the UM3, is it on one of the github repos?

    Is there a description of the boot process (so I'd know where to hook in a web service)? Or should I poke around in /etc/services ?

     

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    poke around.  The code is not on github.  I think.  Not sure.  But it's in /usr/share/griffin I believe.  And subfolders.  Maybe tar that up into a tar zip file and scp it back to your main computer?

     

    Or, you can just go to this page, download it and unzip it: http://software.ultimaker.com/jedi/releases/

     

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Hi again, thanks for all the help.  I've dug through the files and figured out that the UM3 uses a python web app that uses FLASK to manage script/web/printer control. From that, it looks like adding services (FLASK hooks?) to the current web app is the best idea rather than simply sending gcode directly (although one web service could do that pretty easily by sending JSON ).  

     

    Now my question is, what's the best way to develop and test my own services?  Obviously, it's hard to do this directly on the UM3 because I'd be worried about bricking it.  Is there a suggested development system for this purpose? I noticed that there is a fake printer ('mock' in the griffin folder) that could be for testing?

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    I recommend you order the cable in my above link - it's not expensive - I think around 10 euros or $10.  Then you don't have to be afraid of bricking the printer - the cable is a serial cable that connects to any computer and you have a terminal window directly into the linux machine and you can see it booting and when it's done booting you can log into root (password ultimaker) and do whatever you want.  The "bricking" that can happen with bad json files still allows the computer to boot - it just blocks the ssh daemon and never tries to connect to the arduino computer.

     

    However maybe @Daid can answer your question about flask hooks and the "mock" printer in the griffin folder.  Please publish whatever you come up with on github and link to it here in this subject as many other people can use this kind of 3rd party improvement to the printer.

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    The mock printer hasn't been updated, and thus isn't current, and thus useless.

     

    I highly recommend the cable so you can always debug/recover from a brick. Even if the risk is fairly low. The recovery by micro SD card also works to fix a brick.

     

    Next to that, you can also run the whole system on a virtual machine, there is actually a software setting somewhere (I forgot where) that allows you to use the "marlin simulator" instead of talking to most of the main hardware. But setting that up is quite a bit of work.

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Hi, thanks again for your help. This is slowly but surely taking form. Now my question is, how quickly (but still safely) can I send G Code movement updates to the UM3? If I wanted to do something like draw a complex curve by drawing lots of little connected lines while at the same time varying temperature, is that doable? Or are drawing and temperature changing commands blocking? And is there a way to get feedback from the controller as to what it's current state is?

     

    If it's possible, it would be great to chat to one of the UM team about this! I think it might ultimately be pretty useful to you, too.

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?
    35 minutes ago, helical said:

    Hi, thanks again for your help. This is slowly but surely taking form. Now my question is, how quickly (but still safely) can I send G Code movement updates to the UM3? If I wanted to do something like draw a complex curve by drawing lots of little connected lines while at the same time varying temperature, is that doable? Or are drawing and temperature changing commands blocking? And is there a way to get feedback from the controller as to what it's current state is?

     

    If it's possible, it would be great to chat to one of the UM team about this! I think it might ultimately be pretty useful to you, too.


    I might have some DBUS commands that you can use when SSHing into the machine lying around somewhere. It's a bit of a hacked together interface and it comes with absolutely 0 warranty, but it should at least enable you to send raw g-code. 

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    If you know you printer's IP address and it's in Developer mode:

    ssh ultimaker@<printer_ip>

     

    You get a special shell in which you can do a 

    sendgcode <your gcode comes here>

    But as @nallath says: 0 warranty

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Hi, I did see the dbus and sendcode scripts on the UM so I'm able to send G Code via ssh.  What I'm more interested in is the limits of the G Code for the UM3, whether I can send a lot of movement commands over a short time safely, and whether there is a way to get back a response from the printer when it's finished moving.  I can see on the list of G Code commands on the Sailfish website that some are blocking commands, like moving and printing at the same time, so I assume that there are limits to the amount of instructions that can be sent but I'd like to get a clearer idea what those limits look like.  Thanks!

    • Like 1
    Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    I think it's trial and error for now.

    You can keep an eye out on http://<printer ip>/api/v1/debug/marlin/errors for buffer underruns which is an indication of marlin having an empty planner buffer.

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Hmmm... that link didn't work for me, I get a 404.

     

    Also, I've been trying to send G Code and the LED change code and movement code and home position codes work but not any temperature related ones.  these seemt o do nothing:

     

    M145 T0 ;enable temp
    M104 S200 ; set temp to 200C
    M109 S200 ; wait for temp to get to 200
    M106 ; set fan speed to full
     
    I'm a bit unsure about the syntax for the UM3, it sounds like there's more to it than just G Code from the other posts on the forums? Is that verbose header text from the GCode files required too?  Perhaps someone has an example of manually choosing a print head, setting the temperature, and extruding a line that they can share?  Or is this not possible via the "sendgcode" command?
     
     
  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?
    On 4/27/2018 at 4:42 PM, helical said:
    M145 T0 ;enable temp
    M104 S200 ; set temp to 200C

    this works fine as long as it's directly after eachother, for instance if you paste:

    sendgcode M145 T0

    sendgcode M104 S200

    into the (cmd) shell

    After a millisecond it is turned back off. Since the temp is 0 and the target is 0... I think this was done to avoid the hotend error uppo removal of the hotend as much as possible.

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?
    5 hours ago, robinmdh said:

    this works fine as long as it's directly after eachother, for instance if you paste:

    sendgcode M145 T0

    sendgcode M104 S200

    into the (cmd) shell

    After a millisecond it is turned back off. Since the temp is 0 and the target is 0... I think this was done to avoid the hotend error uppo removal of the hotend as much as possible.

     

    Hi robinmdh,

     

    I used the same method but the temperature didn't change at all.  I'm not sure what you mean by "after a millisecond it is turned back off?"

     

    I had the LCD showing the current nozzle temperature at the time, could that have something to do with it? Otherwise, how would I know what the current temperature is after executing a command?

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    If you issue just the M145 T0 command and then a quarter second later you issue the other command it will be too late.  You need to issue both commands REALLY FAST together or the M145 will be reversed again.  So robin recommends you do a cut and paste both in simultaneously.

     

  • Link to post
    Share on other sites

    Posted (edited) · Ways to send gcode direct to printer or control during printing?
    53 minutes ago, gr5 said:

    cut and paste both in simultaneously.

    indeed, including enter, I've tested this and it works but you can also set te temperature property.

     

    in the debug shell you get by loggin in as ultimaker:
     

    select printer printer/head/0/slot/0
    set pre_tune_target_temperature 200

     

    and since you asked to see the temperature you can also either enter the

    list

    command or the

    get current_temperature

    command to see the temperature instead of looking at the screen.

     

    the same properties exist for the bed and both hotends, type select <tab><tab> to get an idea of how to set the properties of those sub-systems

     

     

    Edited by robinmdh
    • Like 1
    Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    That's great, I understand now. Thanks for the help!

     

     

  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?

    Bump with thanks to @gr5 -- great info. Thinking about how my printer routinely drags the prime blob into the print (it looks like it tries to wipe the nozzle but the nozzle is still too hot) and wanted a repl to experiment with - this seems like it might be close enough.

     

    You mentioned a web service, and I guess it'd be easy enough to flask something, but is there any real interest in poking at this kind of level by other people?

     

    If so, maybe I'll look at making time to write a Jupyter kernel (https://github.com/jupyter/jupyter/wiki/Jupyter-kernels)

  • Link to post
    Share on other sites

    Posted (edited) · Ways to send gcode direct to printer or control during printing?
     
     
     
     
     
     
     
     
     
     
     
     
    11
    On 2/8/2018 at 9:25 AM, gr5 said:

    Well the Um2 is simpler.  You can control it through USB (it's not officially supported but it works pretty well).  It has Marlin firmware which is on hundreds of different types of printers (most printers out there).  There is software called "octoprint" that allows you to control printers through USB or you can simply send gcodes with any software you want to write.

     

    The um3 indeed has a linux stack.  You can log in with ssh username and password is root/ultimaker.  You have to put the printer into developer mode first (it's a menu option on the printer).

     

    Everything is in python so the source code is all visible and commented on the printer itself.  Well some of it is in json files (javascript).

     

    Once in you can go to the /usr/share/griffin folder and do this:

    python3 command_util.py

     

    Then do "sendgcode" followed by the gcode you want to send.  This might be too slow (not real time enough for you) so you might want to create some kind of web service.  If you do *please* share. :)

     


     

    I tried to realize this by PHP or Python as the following code. But after running that py file, any command doesn't work. Do you have any idea about how to fix this? Thank you very much!

    <?php
    set_include_path('C:/xampp/htdocs/phpseclib1.0.15');
    include('Net/SSH2.php');
     
    $ssh = new Net_SSH2('ip');
    if (!$ssh->login('root', 'ultimaker')) {
    exit('Login Failed');
    }
    echo $ssh->exec('python3 /usr/share/griffin/command_util.py && help');
     
    ?>
     
    #
    import paramiko
    # realize transport
    trans = paramiko.Transport(('ip', 22))
    # connection
    trans.connect(username='root', password='ultimaker')
     
    # Specify the transport of the sshclient object as the above trans
    ssh = paramiko.SSHClient()
    ssh._transport = trans
    # execute command
    stdin, stdout, stderr = ssh.exec_command('python3 /usr/share/griffin/command_util.py \n sendgcode G28')
    print(stdout.read().decode())
     
    # close connection
    trans.close()
    Edited by sxj1121
  • Link to post
    Share on other sites

    Posted · Ways to send gcode direct to printer or control during printing?
     
     
    1
    20 hours ago, sxj1121 said:

    I tried to realize this by PHP or Python as the following code. But after running that py file, any command doesn't work. Do you have any idea about how to fix this? Thank you very much!

    <?php
    set_include_path('C:/xampp/htdocs/phpseclib1.0.15');
    include('Net/SSH2.php');
     
    $ssh = new Net_SSH2('ip');
    if (!$ssh->login('root', 'ultimaker')) {
    exit('Login Failed');
    }
    echo $ssh->exec('python3 /usr/share/griffin/command_util.py && help');
     
    ?>
     
    #
    import paramiko
    # realize transport
    trans = paramiko.Transport(('ip', 22))
    # connection
    trans.connect(username='root', password='ultimaker')
     
    # Specify the transport of the sshclient object as the above trans
    ssh = paramiko.SSHClient()
    ssh._transport = trans
    # execute command
    stdin, stdout, stderr = ssh.exec_command('python3 /usr/share/griffin/command_util.py \n sendgcode G28')
    print(stdout.read().decode())
     
    # close connection
    trans.close()

    Just delete "&&" in PHP or "\n", then it would work.

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...