Help Needed: Configuring Klipper to Receive G-Code Commands via Serial on Raspberry Pi

Hello fellow Klipper enthusiasts!

I’ve been diving into Klipper firmware recently, and I’m looking for some guidance on how to configure it to receive standard G-Code commands via the serial port on a Raspberry Pi. I’ve done some research and experimentation, but I’m still facing some challenges, and I hope some of you might have some insights to share.

Here’s what I know so far:

Klipper uses a virtual serial port, which is essentially a file located in either “~tmp/printer” or “~/printer_data/comms/klippy.serial” to communicate with other software on the same device. This virtual serial port acts as a bridge between the printer and the host software.

My goal is to send G-Code commands to Klipper from a separate device, which, for various reasons, cannot be directly connected to the Raspberry Pi. This means I need to find a way to forward commands from a physical port on one device to the virtual serial port on the Raspberry Pi.

I’ve considered a couple of potential solutions:

  1. Serial Forwarding:
    One option I’m exploring is using a serial forwarding tool to redirect data from a physical serial port on my other device to the virtual serial port on the Raspberry Pi. There are various tools and software available for this purpose, but I’m not sure which one would be the best fit for my setup or how to configure it.

  2. Ethernet Connection:
    Another approach that crossed my mind is setting up some form of Ethernet communication between the two devices. I wonder if it’s possible to establish a network connection between the Raspberry Pi and the other board, allowing me to send G-Code commands via Ethernet. But again, I’m unsure about how to configure this effectively with Klipper.

If anyone has experience with a similar setup or can provide some guidance on how to configure Klipper to receive G-Code commands from a remote device, your insights would be greatly appreciated. Any tips, advice, or suggestions would be incredibly helpful as I work towards achieving this goal.

Thanks in advance for your help, and I’m looking forward to learning from your expertise and experiences.

Depending on your needs, there are a few possibilities:

Thank you for the valuable information, the first two links seem more complicated and can’t be applied easily for me, however what I need is the third way and I see it now has three ways to do the job:

  1. use socat to open one physical serial port and bidirectionaly forward it to the virtual port (tmp/printer)
  2. edit klippy to use a physical serial port rather than using a virtual serial port to communicate with a host software however considering that the work order is host software ---> virtual serial ---> klippy ---> klipper ---> physical serial ---> mcu , I can see that the physical serial port is already busy so this moves us to the third solution
  3. use TcpIp and configure it to recieve commands and forward it to the virtual serial port (tmp/printer) (using socat ?)

Do you have any helpful information about how to do the tcpip way ? I tried to search and read about this since yesterday but I can’t find a straightforward working way.

what I am thinking about now to find a way to achieve this
A host software that send gcode form any board or computer ---> someway to open tcpip connection through ethernet port ---> lan cable ---> raspberry pi ethernet port ---> a software to forward gcodes from tcpip to klippy (tmp\printer) (this is the tricky part ) ---> klipper ---> serial port ---> mcu board

Thank you in advance

I have never tried such a setup, so I cannot provide you any more guidance here, unfortunately.

In the beginning you have this with the terminal input of the Klipper frontend of your choice.
You just need a plugin that does the input.

Or just upload a gcode file…

As mentioned previously, socat can be used to create a relay between the Pi’s UART and Klipper’s pty. You could go with your second option, fork Klipper and modify it to receive commands from the UART. Note that the Pi’s UART will only be used if you have an MCU connected to it. Generally MCUs are connected over USB.

I believe that socat can also be used to bridge a tcp connection to the pty, however your device will still be responsible for connecting to the socket, sending the gcode command, and handling responses from Klipper. This is likely going to require some programming.

lf all you want is to do is send commands over TCP then Moonraker is probably going to make that easier. Presuming Moonraker is installed configured on the host machine, connect your remote device to your LAN (make sure it can be configured via DHCP or give it a static address), then use curl:

curl -d "script=G28" http://my_printer.local/printer/gcode/script

The above will send a command to home the printer. If you want the gcode response things get more complex, you will need to use the websocket. This too will likely require some programming, as the responses need to be filtered and decoded.

That said, gcode responses aren’t the best way to collect data about the printer, Moonraker has other APIs that query Klipper directly and return more detailed info.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.