Search code examples
javaprinting3d

how to print stl files (3d) in java


As part of my school project, I have stl files and I need to print them one by one in 3d printer. How do i send it to the printer? is there a function that does that?

Thank you!


Solution

  • Sending commands to a 3d printer is a very large subject. In short, what has to be done is:

    1. An .stl file is a collection of polygons. A 3D printer cannot process those. Most 3D printers receive movement commands. These commands are called G code. Converting stl files to g codes is called slicing. There are softwares which do that. For example, the open source slic3r. You can try the console-slic3r to see how it works and use it within your Java code.

    2. After you have a G code file, you have to send them to the printers. Most 3D printers can communicate with your computer using serial communication. You have to connect to the right port, then start sending the G code line by line. Every time the printer finishes performing a command, it sends back an 'ok' response (It's ok for Marlin based printers, open a serial monitor and start experimenting yourself to see how your printer behaves). Every time you receive an ok, you send the next command, until you are out of them.

    So basically what you have to do (in steps)

    1. Using Slic3r, convert your .stl file to .gcode file.
    2. Read the output .gcode file that slic3r has generated.
    3. Open a serial connection to the printer and send the first line of the file.
    4. Wait for ok, and send the next line.
    5. Repeat step 4 until you are out of gcode lines.

    If you're new to this subject, I would download the Arduino IDE, open the serial monitor, and start sending some G codes to the printer.

    Some examples of G codes

    For example, the movement command is G0 or G1, and it has 6 parameters - X, Y, Z, E and F (e - extruder, f - speed). Try: (remember to send a newline after that)

    G1 X50 Y20 Z10 F5000
    

    And the printer is supposed to move to that coordinate. More information about G code commands can be found here (G code RepRap wiki)