This is my first attempt at an instructable. I hope it helps someone else.
Switches and Lights and fans, oh my…
I bought a CNC machine some time ago and I was never happy with it. It used a traditional parallel port controller and of course no modern computers have those. So it was always a point of frustration. I used an old Pentium based computer and ran LinuxCNC on it for a while but was still not happy with that. So I started looking for another solution. I decided that I would try to put together an Arduino based controller and try to use USB to communicate with it.
After studying that for a while I came to realize the Arduino was just not going to be able to do all that needed to be done on its own. The Arduino UNO just does not have enough memory or processing capacity to process a design file by itself. So I modified my solution and started working on using a Raspberry Pi as my host computer.
I created a Visio drawing of what I intended to do: It didn’t turn out that way and the drawing continued to evolve as I learned more. It kept on changing until I finally got my project completed.
I have now built an Arduino based CNC Controller system that uses a Raspberry Pi as its host computer. The Raspberry Pi processes an “nc” file that contains a design that is described in GCode commands that can be understood by the Arduino. I have used a few tools on my Windows 8.1 Pro laptop to design a few simple things (like tutorials in makercam here:http://www.makercam.com/). This is a great introduction to designing things for CAD/CAM and it is really easy to use.
After creating a design that I wanted to use I wirelessly connected to the Raspberry Pi using WinSCP to transfer design files to the Raspberry Pi. You can get WinSCP here: http://www.soft-now.com/listing/123823/WinSCP?did=11055&pid=1&ppd=search,44532390848,winscp20download,e,,c,0,,,&gclid=CJuIkNHds74CFagWMgodpxMAJw. Its great, you can just drag a file from one window to the other to move files between systems. You will have to know the IP address of your Raspberry Pi to connect to it. If you have gone through the initial setup of the Raspberry Pi and setup a network connection you can get the IP address by using the ifconfig command on the Raspberry PI. A really helpful tool for getting your IP address and seeing that your Pi is online is a tool called the Advanced IP Scanner here: http://www.advanced-ip-scanner.com/. Another great tool is Wireshark: http://www.wireshark.org/
I then used Remote Desktop Connection (Remote Desktop connection is part of Windows and should be on your Windows machine. It can be run by entering mstsc in the Run Open: box) to connect to my Raspberry Pi. Otherwise you could use VNC or TightVNC: http://www.tightvnc.com/. TightVNC is what you need to put on your Raspberry Pi to allow you to use Remote Desktop Connection from another machine. I can now run the Grbl Controller on the Raspberry Pi which in turn connects to an Alamode (an Arduino like board that plugs directly into the GPIO connector on the Raspberry Pi and provides automatic voltage level translation. So that the Arduino can communicate with the Raspberry Pi directly. The Alamode also provides Arduino headers to allow for Arduino shields to be plugged directly into it. So I ended up with a stack of three boards that are tightly integrated due to being plugged directly into each other. The Alamode (Arduino) processes the GCode commands from the Raspberry Pi into signals that are sent to the CNC Controller shield to run the stepper motors and passes the various function signals on to the CNC Controller shield too. They can then be accessed from the external world. All is well so far… But now I have to connect these things to the external world.
Step 1: 100% Grbl Compatible CNC Controller
First, I purchased the 100% Grbl compatible CNC Controller shield from:http://blog.protoneer.co.nz/arduino-cnc-shield. I already had an Arduino and intended to use that with the CNC Controller shield and run something on my laptop to control everything. Then I found out that the Arduino would not be able to process an entire design file all by itself. This is due to it not having enough memory to handle more than one GCode command at a time. In fact not all GCode commands are currently completely implemented in the Arduino Grbl software. However, the Arduino does directly interface with the CNC Controller shield and can pass commands to the stepper drivers on the CNC Controller shield without any additional circuitry.
The sets of three yellow jumpers that you see in the pictures set the micro stepping for the stepper motors. The one single yellow jumper selects how the limit switches work. Mine are set up so that when the switch closes a ground is detected (the default). The alternative is to sense a hi when Vcc is selected. That is to say that the limit switch logic can be set to sense a hi or lo, your choice. The two yellow jumpers on the left side of the picture are for selecting which axis the A-axis mirrors (two motors on one axis).
I used polarized headers to connect to the stepper drivers so that I would not be able to plug in my stepper motors backwards – that’s pretty important.
The 100% Grbl compatible CNC Controller shield does not actually include any stepper motor drivers. It is only a means of integrating the stepper motor drivers into an Arduino shield conveniently and it works great for that purpose. The CNC Controller shield is designed to use the Pololu type step driver modules like the A4988 stepper motor driver carrier that is shown here:http://www.pololu.com/product/1182
I purchased some from China that were about $4.00 each and appear to be exactly the same (we shall see when I actually try to use them). They came with some heat sinks too but I decided to use the ones you see (from Adafruit) instead of the ones that were included instead. You actually only need to populate the X, Y and Z stepper driver carriers on the CNC Controller board (because the Grbl software on the Arduino only knows about three axes). Unless you intend to use the A-Axis too (for a second motor on one of the primary axes). The CNC Controller allows you to mirror the control signals from X, Y or Z to the A axis by using jumpers. I am not using the fourth axis. I just included the fourth stepper driver carrier so that I would have a spare in case one of the others stops working. Then again who knows what might be in the future?
Step 2: Raspberry Pi
It became clear that I needed some way to process a complete design file and break it into individual GCode commands that the Arduino could then pass on to the CNC Controller shield. Many articles are available on the internet about running the Grbl Controller software which provides this specific function on a Raspberry Pi. I had a Raspberry Pi that I had played with a bit, some time ago, but it was an older version. I am sure it would have worked but I decided to get a new one and dedicate the new one to being the host in my new CNC Controller system. For more information about running the Grbl Controller software on a Raspberry Pi look here: http://zapmaker.org/raspberry-pi/running-grbl-controller-on-raspberry-pi/
Due to reading a lot of those articles that I mentioned I became concerned that the Raspberry Pi would overheat when inside of an enclosure so I put heat sinks on it. Then I had to trim down the heat sink on the processor as it was too tall.
I also came to realize that the Arduino and the Raspberry Pi are slightly, electrically incompatible. The Arduino operates with 5V logic and the Raspberry Pi operates with 3.3 V logic. So a voltage level translator of some sort is required as an interface between the two environments. I looked around for a solution and found a few. I didn’t really like anything that I was finding and it took a while to get to what I wanted but I eventually found the Raspberry Pi Alamode board.
Step 3: Raspberry Pi Alamode
The Alamode board plugs directly into the GPIO connector on the Raspberry Pi and provides the level shifting function that is needed for the Arudino to communicate with it. It also provides Arduino compatible headers so that any standard Arduino shield can be plugged into it too. Including the CNC Controller shield. So it now appeared that I could have a stack of three boards that communicate with each other properly and elegantly – with no additional circuitry required.
Some quick features of the Alamode – that I am interested in: The Alamode has a real time clock that is directly available to the Raspberry Pi (with a coin cell battery backup). The Alamode can be powered from the Raspberry Pi or it can be powered directly through its own micro USB connector. There is a tiny jumper that allows you to select how you want to power it. The jumper header fell off of my board (probably my own fault). I looked at it and decided I just didn’t need it as I intended on powering it through its own micro USB port anyway. The big deal is that the Alamode includes the signal level shifting that is required for an Arduino to communicate with a Raspberry Pi.
Once the Alamode is connected to the Raspberry PI you can then load the Grbl software onto the Alamode. The Grbl code is loaded into the Alamode with the Arduino IDE. You need to load the Arduino IDE onto the Raspberry Pi to load the Grbl code into the Alamode. The Getting Started instructions at the Alamode site are very good and complete:http://wyolum.com/projects/alamode. Refer to the User Guide for instructions on how to set up the real time clock.
Let me just say that it works exactly as they say it does. It is a bit of a task to get everything together to actually use it but once it is set up (mostly on the Raspberry Pi) it works great.
Step 4: Stack ’em Up
So now I have a stack of three boards. With the Raspberry Pi on the bottom, the Alamode in the middle and the CNC Controller shield on the top. All plugged together. One problem for me was that the Alamode does not provide any mounting holes. It does provide a rubber pad that goes on the top of the RJ-45 Ethernet connector on the Raspberry Pi and is the right height (must be very carefully positioned on the RJ-45 connector) but there is no solid connection point other than the GPIO connector. The CNC Controller shield is like most other Arduino shields and is very well held in place due to the friction of the header extenders that are on the Arduino. My original Raspberry Pi did not have mounting holes in it either. That is part of the reason why I decided to get a new one and use it instead. Later on, I purchased an assortment of nylon standoffs and attached a couple of them to the Raspberry Pi – with a couple of washers to get the height right. Then I very carefully put a drop of super glue on the top of each of the nylon standoffs and put the Alamode onto the Raspberry Pi. I then left it alone for a while. I was later able to take the screws out of the bottom of the Raspberry Pi and take the Alamode off with the standoffs attached to the Alamode – it worked! I also attached a standoff between the Alamode and the CNC Controller shield as there was a hole in a place that made that possible on both boards. So now I have all three boards securely connected together.
Step 5: An Enclosure
Early on I decided to use some sort of enclosure to protect my finished project. So I bought one and then came to realize it was not large enough and had to measure everything and buy another one. The one I used is is nice box but turned out to be a challenge anyway. This box is made by Bud and I got through Amazon here:http://www.amazon.com/dp/B005T7ARB6/ref=pe_385040_30332190_TE_M3T1_ST1_dp_1. It is a BUD Industries PN-1339-DG High-Impact ABS NEMA 4x Indoor Box, 6-19/64″ Length x 6-19/64″ Width x 3-17/32″ Height, Dark Gray Finish enclosure.
There are some nice brass threaded mounting holes in the corners inside of the box and the box comes with screws to secure the top to the bottom with the brass threaded holes in the outside corners. The box also has a gasket to make it waterproof if you need that. In my case it just makes for a very nicely sealed box.
I came to believe that I needed to have some sort of carrier to mount my “stack” to inside of the box. So I bought a sheet of acetal from Zoro Tools:http://www.zoro.com/g/Acetal%20Sheet%20Stock/00153128/. Acetal is supposed to be somewhat ESD safe but I have not studied that out entirely either. After I got the sheet of acetal I cut a piece that would fit inside of the enclosure with my Dremel tool. It isn’t pretty and this is one of the things I plan to replace when I finally get my milling machine working again. I ended up having to cut cutouts on both sides of my initial carrier to provide better access for the wires and cables that connect the “stack” to the external world.
I also felt that it was important to make sure that there is adequate ventilation in the box. So I mounted two 40mm, 12 VDC, exhaust fans on the top and two inlet vents with filters on the bottom.
In the pictures you can see that there are a couple of extra holes in the carrier – Oops.
I made a 1:1 scale drawings of the openings to be put into the box in Visio and then printed those out on my printer. Then I cut out the printed drawings and taped them to the box and used them as templates. It wasn’t perfect, of course, but was pretty good. I started each modification to the box by using an Exacto knife to carefully mark through the templates and then used a Sharpie to make sure I got it right. Then I used my Dremel to cut out the various openings in the box. Not too difficult to do but you have to be patient and let the Dremel do the work or you will end up with a lot of melted plastic on your hands and the nib that you are using in the Dremel will try to dig into the material occasionally. My only advice is be patient, take you time, don’t press to hard, cut in the right direction and it will all work out acceptably – no one is perfect. The hardest openings to cut were the ones for the switches and the connectors. Each of the connectors and switches have flat spots on opposite sides. All of my switches and connectors are 16mm. The flat spots keep the switches or connectors from turning in the chassis. That is great if you are using chassis punches but I do not know of any of those that are designed to work on plastic. So I had to very carefully cut the holes by hand with my Dremel. I cut them and test fitted each connector one at a time and as soon as I was able to get the switch or connector in the hole I stopped. They are pretty good but a nice CNC machine would have done a better job than I did – maybe next time I will have a working CNC machine and I can try that.
Step 6: The Hard Part
So here is the hard part. Most CNC machines (milling machines, laser cutters, engravers, water jets, etc.) use stepper motors to position the axes. The CNC Controller board provides X, Y and Z axes as well as an A-Axis that can be used to supplement one of the other axes if needed with an additional motor or a fourth axis could be implemented (but Grbl only knows about three axes right now). My implementation is only going to use three axes at this time. However, I decided that I needed to bring the A-Axis out because I might someday want to use it. Further, the CNC Controller board provides for the control functions to enable the spindle as well as two other functions. By default they are spindle cooling and spindle direction (alternately these functions can be used to control a laser, a vacuum hold down or a blower / fume extractor and a heating mat for a 3D printer). I did not know what I might want to control later on so I decided to bring those signals out of the box too. I ended up with five connectors on one side of my box that can be used to connect to the machine that I want to control. I have labelled everything and everything is also color coded.
I want to mention that I used expandable sleeving to bundle wires together where ever possible and to reduce the number of unbundled wires in the build. It helps in a lot of ways and protects the wires a bit but most importantly it makes it really clear what each of the bundles is for. It also makes the entire project a lot better looking. Here is one place that you can get expandable sleeving: https://www.parts-express.com/Search.aspx?keyword=expandable%20sleeving&sitesearch=true. NTE provides wire and heat shrink tubing assortments that are really useful in building electronics.
NTE / Elenco hookup wire assortment: http://www.amazon.com/Elenco-Electronics-WK-106-Storage-25-Feet/dp/B008L3QJAS/ref=sr_1_1?ie=UTF8&qid=1400363023&sr=8-1&keywords=elenco+wire
Heat shrink tubing assortment: http://www.amazon.com/NTE-Heat-Shrink-Assorted-Colors/dp/B000FIDTYG
Other useful things are like these:
Crimping Tool to put pins onto the ends of wires to be plugged into the various places: http://www.pololu.com/product/1928. This is a really nice tool and works better than a lot of other crimpers that are a lot more expensive. Of course, you need to have pins and housings to complete a connection. You can see that I used many pins and housings in building my CNC Controller.
Step 7: The External World
The next thing that had to be done was to connect the inside of the box to the external world. Switches to control the system and plugs to get the signals to the stepper motors and the spindle and finally a connection to a power supply.
The switches are all connected to one header that plugs into the CNC Controller shield and another one that plugs into the power distribution board for the LEDs that are in the switches. So the switches have a connection both below the carrier and above the carrier.
For more detail: Raspberry Pi Alamode CNC Controller