How do I send GCode using Arduino through USB Serial

Hey all,

I’m trying to build a z-probe for the snapmaker. I’m trying to use an arduino to do this by sending gcode instructions to the snapmaker through the USB mini B port, which AFAICT is meant for sending gcode via serial connection. I’ve seen a lot of people talking about setting up a Pi with Octoprint and sending gcode over the same port, so in theory an arduino should be able to do the same thing, it’s just a matter of protocol.

I thought sending gcode instructions over serial was just plain text (like “G0 X10”), but this doesn’t register anything when I do it with my arduino, so I’m guessing I’m missing some kind of protocol.

Things I’ve tried:

  • I noticed the usb port doesn’t supply power, so I’m powering it separately
  • The snapmaker USB seems to use a CH340 USB to Serial chip, so I’ve also attached a CH340 chip to my arduino, so there shouldn’t be any driver issues
  • I’ve tried sending the instructions while the machine is in the control screen (and just on the home screen)
  • I’ve tried sending the instructions with the touch screen unplugged and plugged in

Is anyone familiar with how Snapmaker requires input in the USB-B port to be formatted to correctly execute it as gcode? Does it need to be set into a special mode?


It’s plaintext. Not sure you can back-to-back USB client devices like the CH340. You’ll need a USB host device to command the controller which afaik the arduino cannot be except with certain exceptions like here and here. Double check baud rates too.

I think you’ll find using an arduino to send gcode is not the best here. an rPi that is a computer and USB host with included serial drivers is the more proper tool.

And if you are going the RPi route (assuming you find a shop that still has one in stock) you could also put octoprint on it and use the API to send the gcode commands.

Some things to watch out for.

  • I’m assuming you’ll want to use this for cnc, not necessarily for the 3d print head? The cnc toolhead does not have a probe, so you can’t just use the gcode probe commands.
  • Whenever a gcode command is run, it’s running until it is finished. i.e. if you do a 10mm move down, it will finish that. You can’t just stop it midway with another gcode command. As a consequence, you would be doing a lot very small moves. (or you have a touch probe with spring that can be compressed significantly to work around that.

Hey @haoyudothis,

The Snapmaker is a USB client, and as such, does not supply power as you have found. I know that machines like those from Creality do, but that is not a proper USB interface and causes problems. As for the CH340, that is inside of the Snapmaker, and you don’t need one for your Arduino. The Arduino simply needs a USB port, and a driver library for the CH340 chipset. I would think that there is a library publicly available for that, but you’ll need to find one.

Once you have that, you simply need to configure the driver with the serial characteristics that Snapmaker is using. This is mostly just setting the correct baud rate, and then it should work. BTW, the GCode commands do need to be in uppercase, in case you didn’t know that.

Best of luck!