I'm working on a project for which I use the Printrun package to serial communicate my G-code to my 3D printer (Creality Ender 3, Marlin firmware). The idea is that I have an external button connected to an Arduino such that whenever I press this button, the M114
command should be sent and I want to receive the nozzle Z-position.
At the moment the code looks like this:
from printrun.printcore import printcore
from printrun import gcoder
# some code for button
import serial
import time
arduino = serial.Serial(port = 'COM5', baudrate = 9600, timeout = 0.1)
def Button():
data = arduino.readline()
time.sleep(0.05)
return data
printer = printcore('COM4',115200)
gcode=[i.strip() for i in open('MyCode.gcode')]
gcode = gcoder.LightGCode(gcode)
printer.startprint(gcode)
button = Button()
if button == b'1':
printer.pause()
print(printer.send_now("M114"))
printer.resume()
The code is running but I don't get any information about the outcome of the M114
command when I press the button.
Questions:
- Is there something in my code that I'm missing? How can I receive the answer from the
M114
command using Printrun? - Do you know any other package that allows me to receive the answer from the 3D printer?