Introduction: Control Your CNC Over Wi-Fi
Hi everyone! This is my first Instructable, ever. I hope you enjoy it.
I recently built my own CNC router and ever since I got it up and running I have been obsessed with it. It's been a great learning experience both in terms of CNC hardware and the software that you need to run it. Throughout my first cuts, I noticed that between design and fabrication I was making lots of trips between my shop area (outside) and my desk (inside). Each time I moved I was dragging my laptop, charger, mouse, cables, etc. along with me either to draw more stuff or to actually run the machine. I knew there had to be a better way...
After some browsing of the software section of the Shapeoko Wiki (check it out), I came across GRBLWeb. I'll spare the details, but the bottom line is it allows you to control your GRBL board over Wi-Fi using a Raspberry Pi. The software runs in a browser, meaning you can run your CNC machine from any device on your Wi-Fi network...no software to install, no cords, etc. This means you can do cool things like:
1. Use your phone or tablet as a pendant at the machine - very useful for homing.
2. Hang out inside at your desk drinking coffee and designing your next part while your machine runs - my preferred option.
3. Keep your laptop out of your dirty shop - to save $$$ on keyboard cleaner.
4. Free up some space in your work area - because Raspberry Pi's are SOOO big...
Installing some software sounds easy enough, but I had a few minor struggles getting everything to come together and work properly --- namely, setup on the Raspberry Pi. I thought it would be helpful to detail my experiences for all of you so you can avoid some of the frustration. With that being said, let's do this!
Step 1: Assumptions & Disclaimer
1. You have a working CNC machine running GRBL 0.8. You can run this on GRBL 0.9 as well but there are additional steps (changing the baud rate) that I will not cover here.
2. Your Raspberry Pi is straight out of the box. There are certainly ways to do this (possibly easier) if you already have one up and running, but I'm covering the whole thing for completion sake.
3. You will running your Raspberry Pi "headless" (i.e. without using a monitor, keyboard, etc.). Having these things certainly makes it easier, but they add to the required materials and we want to minimize those as much as possible!
3. You want to network with your machine using Wi-Fi (hence the title) This process can be greatly simplified if you can just plug your Raspberry Pi into your network using an ethernet cable. But, if you're like me, your router is a long way from your shop and you despise cords.
4. You're using a Windows PC to setup your Raspberry Pi. Sorry, I'm a Windows guy (at least for now). The only major differences occur in Steps 3-4, and beyond that, things should be the same on all systems.
I'm no expert in any of this. These are just the steps and tools that worked for me. It is highly likely that there are better methods out there for performing some of these tasks that I am unaware of. If you have any tips or tricks please share them in the comments.
Step 2: Gather Materials & Software
You'll need the following to complete this Instructable.
- CNC Router running GRBL 0.8
- Raspberry Pi (I used a Model B) --- $39.95 --- Buy a Raspberry Pi Model B
- Wi-Fi dongle --- $11.95 --- Buy a Wi-Fi Dongle
- USB A-B cable (probably came with your CNC; can also get one off an old printer) --- $3.95 --- Buy a USB Cable
- SD card (I used a 4GB one, but you could go bigger if you like) --- $7.95 --- Buy an SD Card
- 5VDC USB Power Supply --- $5.95 --- Buy a "Wall Wart"
- USB A-MicroB cable --- $2.95 --- Buy a Micro USB Cable
- Ethernet cable --- $2.95 --- Buy an Ethernet Cable
- Wi-Fi router with DHCP enabled & at least one free ethernet port --- Assuming you already have this...
ALL of the above parts will run you around $75 + shipping. Obviously if you have some of these lying around (you probably do) then the cost can be greatly reduced!
- SDFormatter --- FREE --- Download SDCard Formatter
- Win32DiskImager --- FREE --- Download Win32 Disk Imager
- WinZip or any other unzipping utility - I'm using 7-Zip --- FREE --- Download 7-Zip
- PuTTY SSH client --- FREE --- Download PuTTY
If you don't know how to access/lookup devices on your router then Fing is a useful app for finding devices connected to your network.
Step 3: Download GRBLWeb
Go to http://xyzbots.com/grblweb.html and download the Raspberry Pi Image file. It is the standard OS that most people start out with (Raspbian) plus all the GRBLWeb software, pre-installed. As soon as it's finished downloading, unzip it and store it away somewhere safe.
Step 4: Format Your SD Card
Insert your SD card into the slot in your computer. Your computer should recognize it and you should see it pop up as an external drive. Pay close attention to the drive letter your computer assigns to it.
Open up SDFormatter. In the drop down menu, select the drive letter for the SD card. Be absolutely sure you select the right one! Failing to do so could cause you to overwrite another, more important drive!
Click the Options button, select "Quick Format" & press Format. The program will reformat your SD card so it is compatible with the Raspberry Pi. NOTE: It's probably obvious, but anything you had on it previously will be deleted.
Step 5: Copy the Raspberry Pi Image to Your SD Card
Open Win32DiskImager. Select the drive letter of your correctly formatted SD card and use the file explorer to select the image file you saved earlier.
Click "Write" and the program will move the file onto your SD card.
Now you've got a full OS stored on your SD card! Time to fire it up!!!
Step 6: Boot Up Your Raspberry Pi
Insert the SD card into the slot on the back of the Raspberry Pi.
Connect the Raspberry Pi to an open ethernet slot on your router using the ethernet cable.
Do not plug in the Wi-Fi dongle yet. We have some setup to do before it is needed.
Plug in your 5V micro USB power supply and connect it to the Raspberry Pi. You should see some LEDs light up indicating that it is starting the boot process. It's alive!
Step 7: Get an I.P. for Your P.I.
In the boot sequence your Raspberry Pi will request an IP address from your router. The router will then use DHCP to find an available one and assign it to your Pi.
I used the Fing app on my phone to scan my network and list all the devices on it. Here I can see that my Raspberry Pi is at 192.168.0.15. Perfect!
Step 8: Login to Your Pi
Open Putty and enter the IP address of your Raspberry Pi that you found in the last step. Select SSH and press "Open." A terminal window should pop up with the login screen.
By default, your username is "pi" and your password is "raspbian." Go ahead and enter these now. If you entered them correctly, you should be looking at a blank line on the Raspberry Pi terminal.
Next we'll re-configure some things on the Raspberry Pi.
Step 9: Setup Your Raspberry Pi
Since we're here it's probably a good idea to modify some basic settings on the Raspberry Pi.
Start by entering sudo raspi-config in your terminal. The configuration menu for the Raspberry Pi should open.
Use the arrow keys to scroll to "Change User Password" and press Enter. You will be prompted to enter a new password. I'll leave it up to you to choose one.
Back in the configuration menu, use the arrow keys to scroll down to "Internationlisation Options" and hit Enter. Inside this menu, select your language and timezone. You shouldn't have to worry about the third option, the keyboard layout.
There's plenty of other settings we could change here but that's all we really need for now.
Step 10: Setup Wi-Fi on Your Pi - Part 1
Probably the most important step in all of this is instructing your Raspberry Pi how to sign onto your Wi-Fi network. Before we get too involved we need to collect some basic info. Write all these values down as you will need them in the next step.
Enter ifconfig into the terminal. A list of all your available network interfaces will be displayed.
At this point we are only interested in the eth0 portion. Look for the following items and write down their values.
inet addr - IP ADDRESS - i.e. 192.168.1.15
Bcast - BROADCAST ADDRESS - i.e. 192.168.1.255
Mask - SUBNET MASK - i.e. 255.255.255.0
Now enter netstat -nr in the terminal. Another list of network information will be displayed. This time we are looking for the following.
Destination - DESTINATION ADDRESS - i.e. 192.168.1.0
Gateway - GATEWAY ADDRESS - i.e. 192.168.1.1
NOTE: The values I have provided above are only examples to give you an idea of the format. The addresses on your network will differ slightly.
Step 11: Setup Wi-Fi on Your Pi - Part 2
Your Raspberry Pi connects to networks using instructions provided in a configuration file. We need to modify the instructions in this file to fit our needs. Open up the configuration file by typing sudo nano /etc/network/interfaces in the terminal. A simple editor similar to the one in the pictures should appear.
We are going to setup the Raspberry Pi to have a static IP address, meaning it never changes. This is good practice for any kind of major equipment because it ensures that you can always find it at the same address and, thus, can also bookmark it in your browser for faster, easier access.
Type the following text in the body of the configuration file, entering in the information you recorded in the previous step in bracketed areas. NOTE: You must use the arrow keys to navigate.
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
address [DESIRED IP ADDRESS, i.e. 192.168.1.111]
netmask [NETMASK ADDRESS]
network [DESTINATION ADDRESS
broadcast [BROADCAST ADDRESS]
gateway [GATEWAY ADDRESS]
wpa-ssid [SSID OF YOUR WI-FI NETWORK, enclosed in double quotations, i.e. "MyWIFI"]
wpa-psk [Your Wi-Fi Password, enclosed in double quotations, i.e. "Password"]
After you are finished, press Ctrl+X to exit the file. You will be asked if you want to save your changes. Type "Y" for yes and then press enter. You should be returned to the command line.
Pro-Tip: Choose an IP address that's well outside the normal range, or at least looks way different than your other devices. This should make it easier to remember/find later.
Step 12: Try Out Your Wi-Fi Connection
Shut down your Raspberry Pi by entering sudo poweroff in the terminal. Your connection should terminate. Unplug the ethernet cable from the Raspberry Pi and plug the Wi-Fi dongle into one of the USB ports.
Disconnect/reconnect the power supply to reboot the Raspberry Pi. Once it reboots it should follow the instructions you wrote in the last step to sign onto your Wi-Fi network.
Give your Pi a minute or so to get going and hit refresh in the Fing app to see if your Raspberry Pi is on the network. You can identify it by the IP address you chose in the previous step. If you see it then congrats! You're almost done! If not then return to the previous step, check the configuration file, and ensure you've set up your Wi-Fi correctly.
Now for the fun part...
Step 13: Plug in Your CNC Machine
All that's really left to do is test it out on your machine. To do this all you need to do is connect the GRBL board to the second USB port on your Raspberry Pi using the USB A-B cable. The software onboard the Pi should recognize the Arduino connected to your GRBL shield and take care of everything.
Power up your CNC machine and get it ready to go.
WARNING: I wouldn't recommend turning on your spindle or attempting any cuts yet. Patience!
Step 14: Launch GRBLWeb in Your Browser
Head over to your device of choice (connected to your Wi-Fi network, of course), open a fresh browser, and type http:// + [your Pi's IP address]and hit Enter. Example: http://192.168.0.111. The program should open up and you should see the live status of your machine.
In the drop-down devices menu, find and select the Arduino running GRBL. Now you're ready to go!
Pro-Tip: My computer is not in the same room as my CNC router, so I like to launch the program from the browser on my phone. This way I can stand right next to my machine (and the killswitch) and test it out.
Step 15: Check the Settings on Your CNC Machine
Take special note to the feed rate and step size selected in the combo boxes above the X, Y & Z jog buttons. For initial testing I would recommend a low feed rate and step size for safety reasons. Pressing a button and watching your CNC machine fly off into destruction would be a horrible way to end this project! You should already know what feed rate and steps are from setting up your CNC machine, but bottom line is they need to be within the safe operating range of your equipment. On my Shapeoko 2 I typically use a feed rate of 500 and a step size of 2 or less for testing and small movements.
It's also a good idea to double-check your GRBL settings before you attempt any moves. To do so just hit the Settings ($$) button in the top right corner of the screen. If you have been using your CNC machine prior to attempting this then your settings should already be correct and this step is completely unnecessary.
Step 16: Try It Out!
Try jogging each axis of your machine using the controls in the program. If you're a G-Code wiz you could try out some various commands too. If everything seems to be functioning properly then you are finished!
Step 17: Conclusion & Final Thoughts
Congratulations! If you've made it this far then you are now the proud owner of a networked CNC machine! Enjoy the fruits of your labor by using your machine from nearly anywhere on any device. So far, I have thoroughly enjoyed the flexibility and ease of use with this system. I'm anxious to try out some other features in it as well. Not to mention it's just really cool!
Advice & Thoughts:
REMOTE CNC AT YOUR OWN RISK! Running a CNC machine remotely is not necessarily the safest idea without some good safety & monitoring systems in place. Your machine could run off an axis, stall, miss some steps, or lose a bit, among other things and without you (or something else) around to stop it, it could cause some serious damage.
Spend some additional time learning the GRBLWeb software. I only cover initial setup here, but it's equipped to handle more of your CAD/CAM/Testing/Sending workflow as well. It could be a very powerful tool in your CNC toolbox!
You'll notice in my photos that none of my devices (Raspberry Pi, Arduino, GRBL shield) have enclosures. They are certainly not required, but are always a good idea. I'm hoping to get some as soon as I settle on an overall layout for my Shapeoko.
I recently attempted running this setup completely from my phone and experienced great results! As a quick insight into my workflow, I do all my CAD/CAM processing on my laptop, upload G-Code into Google Drive, open GRBLWeb in a browser on my phone, home the machine using the buttons on the main screen, upload the G-code file, then send it to the machine. Pretty easy!
Step 18: Credit Where Credit Is Due
This Instructable, or even owning my own CNC machine, would not have been possible had it not been for the generosity and hard work of many others. In particular I'd like to thank the creators of GRBLWeb, the folks over at Inventables, and the Raspberry Pi Foundation. If you enjoyed this Instructable please check out and/or show your support for these groups.
And I'll end with a horrible pun...CNC you later!!!
First Prize in the
We have a be nice policy.
Please be positive and constructive.