Ascii text to 3D Printer Plotter

36 views Asked by At

My Problem: So, I wanted to modify a 3D printer to function more like a plotter for text writing. I attached a pen holder to it for writing, but in addition to that, I wanted it to write continuously. What I mean is, for example, if someone started to follow my Instagram, the program would take the nickname of the person and then send a request to the 3D printer to write, for example, "ADAM132". Then, after writing the text, the printer should return to the starting position and wait for the next request (the nickname of the person who followed). However, I want to focus only on the part where I send commands to the printer to write text. I wrote a program in Python, but it could be in another language. (I know how to, for instance, take text, make an STL file from it, then slice it and send it to the printer, but that's not the case here; it's not dynamic and can't be.)

What I did: I wrote some programs, but basically, only one worked for me, but it has problems - it's too slow, and I know that the printer can perform the same task 100x faster.

import serial
import time
from ttgLib.TextToGcode import ttg

# creating object ttg
text_to_gcode = ttg("ADAM123", 1, 0, "return", 4000)

# generating gcode from text
gcode = text_to_gcode.toGcode("G1 Z26", "G1 Z31", "G0", "G1")

# adding +100Y to every Y axis coordinate because of the pen position
modified_gcode = []
for line in gcode:
    parts = line.split()
    for i, part in enumerate(parts):
        if part.startswith('Y'):
            y_value = int(part[1:]) + 100
            parts[i] = 'Y' + str(y_value)
    modified_line = ' '.join(parts)
    modified_gcode.append(modified_line)

# combining lines to one gcode list
gcode_str = "\n".join(modified_gcode)
print(modified_gcode)
# showing gcode command that is sent
print("Sent gcode command:")
print(gcode_str)

# connecting to the printer
ser = serial.Serial('COM10', 115200, timeout=2)

# sending gcode to printer
for line in modified_gcode:
    if line.startswith(('G0', 'G1')):
        ser.write((line + "\n").encode())
        time.sleep(0.2)  # pause between sending commands, if deleted printer skip commands
    else:
        print("Ignored: ", line)

# responses from printer
print("Response from printer:")
while True:
    response = ser.readline().decode().strip()
    if response:
        print(response)
    if not response:
        break

# closing connection
ser.close()

0

There are 0 answers