Thursday, September 17, 2015

X-Carve: TinyG and Raspi

Well, I finally decided to pull the trigger on purchasing the X-Carve from Inventables. Now you may be wondering, what is an 'X-Carve'? Basically, it is an open source CNC mill based on the Shapeoko style CNC mill. And now you may be wondering, 'why the heck would you want a CNC mill?' To make things, of course! A CNC mill is basically the reverse of a 3D printer; you start with a block of material and then remove material to expose your creation. Warning: you may be fascinated for HOURS watching CNC milling videos... 

The X-carve is still back ordered for 3-4 weeks; however, over the past year and a half, I have been attempting to put together a DIY version of a CNC mill made from MDF and makerslide. Therefore, I already have the controller(s), stepper motors, and numerous other things required to make a CNC mill. 

About two years ago, I wanted to learn how to program the Arduino and set out with the ambition of building my own motion controller for CNC. After about one hour of time, I realized this was a little over my head and there were numerous options available on the market with great communities behind them. Needless to say, I ended up purchasing the TinyG motion controller board for ~$130. Here is a link to a nice comparison of the TinyG versions; there are some benefits and set backs to each version, it basically comes down to personal preference.

Now, I plan to set up my CNC in the garage (or basement in the cold northern winters), but do not have a laptop that I want to dedicate to a dust infested room that contains my X-Carve. Welcome Raspberry Pi! My plan is to set up a Raspi to send instructions to my TinyG that will in turn control the X-Carve and make awesome stuff!

As I have not found a single source that compiles a step-by-step tutorial on how to do this, I figured I could write one up as I do it. 

Note: I am not a programmer nor a Raspi or TinyG expert. I am just your average nerd with about 10% of a plan...

How to Make your X-Carve Wireless Using Raspberry Pi and TinyG

Step 0. Connect TinyG locally and test JSON Server (5 mins)

Download 1.83 or higher in order to program firmware from TinyG. This is much easier to do then the older way that requires several programmers.

Step 1. Install OS on Raspberry Pi (15 mins)

Download and install an OS for the Raspi. I chose Raspian - Here is an installation guide.

Step 2. Install JSON Server on Raspberry Pi (5 mins)

Connect the Raspi to your network and internet (wifi or ethernet). Attach a keyboard and monitor or use a terminal service (like Putty) to remotely control the raspi. 

Enter the following commands into your Raspi to install the JSON server. Latest versions located here:

tar -xzvf serial-port-json-server-1.92_linux_arm.tar.gz
If you get the following error, 
Connecting to (||:80... failed: Network is unreachable
you must first set your default gateway on your raspberry pi before you can download things...

Then to run it:
Notes: You may have to change folders (cd command).
You can stop the JSON Server with "Crtl+C"

If the JSON Server is running successfully, the output should look like this:

pi@raspberrypi ~/serial-port-json-server_linux_arm_v1.92 $ ./serial-port-json-server

2015/09/18 03:34:50 main.go:89: Version:1.92
2015/09/18 03:34:50 main.go:96: Hostname: raspberrypi
2015/09/18 03:34:50 main.go:102: Garbage collection is on using Standard mode, meaning we just let Golang determine when to garbage collect.
2015/09/18 03:34:50 main.go:115: Starting server and websocket on ###.###.#.###:8989
2015/09/18 03:34:50 main.go:118: The Serial Port JSON Server is now running.
2015/09/18 03:34:50 main.go:119: If you are using ChiliPeppr, you may go back to it and connect to this server.
2015/09/18 03:34:50 main.go:129: You can enter verbose mode to see all logging by starting with the -v command line switch.
2015/09/18 03:34:57 main.go:144: Your serial ports:
2015/09/18 03:34:57 main.go:151:        {/dev/ttyAMA0 ttyAMA0 []      }
2015/09/18 03:34:57 main.go:151:        {/dev/ttyUSB0 FTDI FT230X Basic UART (ttyUSB0) [] DA00CQIM 00 FTDI  6015 0403}

Step 3. Test JSON Server (<1 min)

Now, in your browser (Chrome works best) navigate to and find your Raspi JSON Server (In the lower right corner)
Notes: Be sure search with the correct subnet!

Once you have connected to the JSON Server, there should be a list of devices in the Port List. To connect to your TinyG, select the port that looks something like this: FTDI FT230X Basic UART (ttyUSB0)

Step 3.1. Set up JSON Server to Auto Start (<1 min)

In order to start the JSON server any time the Raspi boots up, we need to do some stuff. On the Github page, look for the section titled "Startup Script for Linux". Follow these instructions to set up the JSON server to auto start whenever you Raspi powers on.

Notes: Be sure to enter the following line to make the file executable!
sudo chmod +x /etc/init.d/serial-port-json-server

Step 4. Connect Tiny G to Raspberry Pi (<1 min)

Wire everything up... Try to connect to the Tiny G with Chilipeppr...

Try to move your X-carve with Chilipeppr...

At this point, either everything worked, or somethings wrong. Step one of troubleshooting should be a power cycle. If that fails, there is a list of helpful resources I used to set this up below. If none of those resources help, Google your error message and start learning!
Hope this helps!


Tiny G:
TinyG Wiki


Raspberry Pi:


  1. Your instructions helped me setup a wireless CNC connection, thanks! Do you ever have problems with Chilipeppr stuttering on curves? It happened to me a few times but not on UGS.

    1. Glad to hear the tutorial worked for you!

      I have not had any issues with curves on Chilipeppr; however, I have not completed to many complex cuts. One thing to note is that the Chilipeppr interface sometimes will not render the curve, but it does follow the path when cut (John Lauer is aware of this bug - basically avoids complex curve rendering to save on resources).

      What mill are you running? Do you notice any stuttering on a diagonal cut (two motors active)?