Introduction: Mug-O-Matic: a Modular Tiny CNC Drawing Robot!
Mug-O-Matic is a one of a kind DIY toy, a real 3-axis Tiny CNC drawing robot that can customize coffee mugs!
This capable little robot can draw anything you want via manual control, bluetooth, calculated algorithms, or even g-code. So you can enjoy your custom mug creation, then wipe it clean and draw something totally different every day and never have the same thing twice!
The intent of this project is to produce fun and accessible educational tools. We want to encourage & inspire people to engage in tinkering and making things, because the creative process is a powerful way to learn.
To best serve that purpose, these robots are designed with hackable open source hardware and are controlled by free open source software. Building this bot offers an opportunity to experiment with 3D printing & useful software such as Processing, Repetier Host, Slic3r, and of course Arduino - the most common and universally applicable microcontroller for physical computing. So knowledge gained playing with this toy is transferable to real life applications!
As of this writing we are preparing for a crowdfunding on CrowdSupply.com in the coming weeks. The TinyCNC robots require the use of a custom PCB & numerous random components so the easiest way to reproduce this work is to pledge support & receive a kit early next year.
The kits we offer are self-sufficient and contain all the hardware & tools necessary. No soldering or bread-boarding is required; controls are plug-&-play. And like all EngineerDog.com projects, these items are supported with great online instructions such as this one!
As you can see in the promotional video below, there are many possible robots you can build using the same core control elements. To keep things simple this instructable will focus on assembly, wiring, & controls of the Mug-O-Matic robot specifically.
This robot is of moderate difficulty to build and operate. If you are interested in a similar but less challenging toy, check out the Desktop Sentry. (Separate Instructable for that coming soon!)
Step 1: THE BIG PICTURE
Mug-O-Matic is driven by arduino nano & a custom PCB breakout running 3 metal geared mini hobby servos. The device sits on top of a specific 11 Oz coffee mug and uses a sharpie to draw on the side. The image will remain their until you manually remove it with a warm soapy wash or a magic eraser.
Mug-O-Matic's primary means of interface are a joystick & bluetooth module for fiddling around, and a usb tether to your computer for 2 way communication to make detailed drawings from user created gcode. Drawings typically take 1-10 minutes depending on complexity and the device is mesmerizing to watch the whole time, just like a 3D printer.
The drawable resolution is 0.3mm with great repeatability in terms of being able to trace the same lines over & over. That resolution is more than adequate for novelty purposes however I would not classify this device as anything more than toy.
The TinyCNC collection has 60+ parts and 2 major recurring design patterns:
- The Snap on Lid- No tools required to swap PCB enclosure cover.
- The 20mm screw hole pattern- Enables different modules to be screwed together.
This robot is powered by 4x AA batteries and I only recommend using Energizer Ultimate Lithium batteries. These batteries have a high constant voltage that doesn't sag under load or as it nears end of life. (Data sheet here.) They are a little more expensive up front but they dramatically improve performance and last long enough to make the upfront price worth the trade off. (In any case do not use rechargeable batteries since they operate at a lower voltage & performance will suffer.)
REQUIRED SOFTWARE DOWNLOAD LINKS TO PROCEED:
Arduino IDE (Arduino User Interface)
NotePad++ (Strongly recommended for viewing/editing/saving code)
Github.com Repository (Released programs for Mug-O-Matic & Post-It-Plotter drawing robots)
Processing for sending commands line by line from computer over usb. (Required)
Step 2: GATHER PARTS, MATERIALS, & TOOLS
PARTS & MATERIALS:
Full Bill of Materials linked here. If you just want to tinker & source everything yourself please note that the collection is designed around the TinyCNC PCB and a specific mug so that much you'll need from me.
Mug-O-Matic has 17 unique 3D printed parts, all printed from rigid PLA-Pro plastic or from flexible TPU. An updated folder of 3D printable parts is saved here:
If you have your own 3d printer you can get a 'maker kit' and print out your own plastic parts. Attached are the STL files in a zip doc, please note all parts must be printed with: 0.4mm nozzle diameter, 0.2mm thick layers, 4 perimeters, 10% infill, and be printed in the orientation they appear by default. No supports needed. eSun PLA+ is the preferred material for all parts except the 'bracket-flex-limiting' which is to be printed from shore 95A TPU material at the same print settings as above. If you don't want the hassle of printing then you can pick up a complete kit from me!
*Plastite Screws: The TinyCNC collection is held together using a single size of screw to make things easy! This 'plastite' screw type forms its own reusable threads as you drive it in. For this reason it can be hard to drive in the first time so I recommend pre-screwing all your holes to form the thread before assembling parts together so you don't have to drive them from funny angles during assembly.
*Phillips Screwdriver- size #2.
*Driver Handle- (3D Printed)- A handle that sticks on the back of the driver to give you more grip. Its note that it is a separate part for times when you want the screwdriver to be smaller. The back side of the handle is also shaped to help you install servo horns.
*Magnet- Tiny screws are easy to drop so a magnet (included in the kit) attached to the driver makes your life much easier!
*Grease- For all surfaces that make sliding contact we want to add the thinnest sheen of grease. I recommend spreading a pea-size using a paper towel to apply it between the two surfaces that will move against each other. Wipe the grease into the crevices and then wipe off 90% of excess and basically just leave a shiny surface behind! It will feel wasteful but in this application too much grease can have an unintended effect like walking through deep mud!
*Tweezers- (3d Printed)- Used to grab and pull cables through small slots. The screwdriver can also be installed inside the tweezer hole to make a friction ratchet so you can drive it from the side as well.
Step 3: Setup Arduino & Center Servos
To get started well need to unpack the arduino & get connected to a computer. The hobby servos need to be set to their center position electronically prior to assembly so everything is where we think it is.
The code we will use for everything Mug-O-Matic related is all in the same arduino sketch. We just (un)comment out certain functions when we want to do different things. At the github repository, in the GCODE READER folder there is a sketch called "Arduino_Code_Gcode_Reader".
Copy its contents and paste them into notepad++. Make sure the language of notepad++ is set to C++ so the syntax corrections it suggests will be relevant. Then uncomment the "AssemblyAid()" function located in the Setup section by deleting the two forward slashes in front of it. This function contains a permanent loop so the program will be stuck doing the assembly command.
This function sets your servo pin s8 to follow a sweep motion (for testing purposes) and pin s9 to go to the center position for assembly purposes.
Any time I say Center your Servo I am saying plug your servo in and power on the arduino to center it. You can leave it powered on while you assemble it BUT BE CAREFUL! These servos are small and you can break them if you try force them against their will while they are powered on!
Copy and paste the code from notepad++ into the arduino IDE. Make sure your nano is connected to the computer via usb and that your arduino IDE connection settings are correct as shown in the picture. Upload the code. (Note the batteries can be set to ON or OFF for this, but if they are on beware the arm swinging around.)
See Picture attached for PCB Pinout Diagram for reference. Note the servo motor cables are color coded and will not move if connected in reverse, see attached picture.
Step 4: First Linear Actuator Assembly: Y-axis
Use the screws that come with the servo to attach it to the top of the gearbox cover.
Remember to lightly grease the surfaces that will have sliding motion, this includes:
- The bottom face of the gear and the bottom of the gearbox cover.
- The 4 pockets in the gearbox base on the posts that the rack will straddle.
- The tensioner/handle surface that will touch the back rack wall
Center the servo electronically, then attach the horn & gear oriented vertically as shown by pressing it on with the press tool/screwdriver handle. Use the machine screw in the center of the horn, screwing it down snugly, then once again use the last tiny pointy screw in the servo bag to secure the horn to the gear to prevent wiggle. Verify motion is smooth with the S8 pin sweep function.
Now drop the rack onto the gearbox base and center it. Then drop the servo cover assembly into place so that the center gear tooth on the rack falls into the center valley on the gear while the servo motor is set to the center position. This will properly clock the system.
Attach 3 plastite screws snugly (Do not over tighten these) to hold everything together. Verify with the sweep function that the rack moves smoothly. It if stalls or is jerky then barely loosen the two plastite screws in the rack.
The final part is the tensioner which we use to get the last bit of wiggle out of the system. It is held in place with 1 vertical snug plastite screw. And finally, screw in the screw set at a 45 degree angle in the tensioner to flex the wall out until it is touching the rack with the rack in the center position. It will not need to be scrwed in all the way, just enough to touch to prevent wiggle. Use the sweep function to verify smooth motion at the very end.
Step 5: Assemble End Effector & Flex Bracket
These parts attach to the Y axis actuator you just built. Note part orientations in the images as they are important.
To assemble the end effector gather the m4 cap screw, the m4 nut, and the plastic parts shown. Place the screw into the round plastic knob and loosely press it into place.
Then use the tweezers to hold the m4 nut in the inside of the plastic marker mount and use the m4 cap screwto catch it and pull it into place. Use the leverage of screwing the m4 cap screw all the way down to press the nut & knob firmly into their places.
Mount the end effector to the actuator in the orientation shown using two plastite screws positioned diagonally from each other in any of the 4 holes. (We only need 2 for a firm connection. If it helps you can temporarily remove the tensioner from the last step to make room for your screwdriver to do this.)
Next use the tweezers to load up 4 plastite screws into the flexible bracket. Then mount the bracket such that the end with the slit is pointing toward the end effector. (See cad image) To access the screws inside the bracket you stick the screwdriver through the holes in the bracket, see pics.
Step 6: Build Mug Lid Assembly X-axis
Grab the parts shown and mount your X-axis servo. Note the shaft end sticks out a bit so it can help to set your assembly over a gap while you screw things down.
We are going to mate the two big plastic pieces together at a specific orientation but first apply a thin layer of grease between the two surfaces that will be in moving contact.
Then with your servo centered, line up the two notches on the sides of the parts as shown BEFORE pressing on the horn and screwing it down with the machine screw. You will need to use the head & handle of the screwdriver to get the horn pressed on.
Screw the machine screw all the way down to a snug seat. Then use the last remaining tiny pointy screw from the servo bag and screw it into one of the horn holes firmly, making sure it goes all the way it. This screw assures that the horn is attached to the plastic part is sits in.
Plug your servo into pin s8 to do a sweep motion check. The movement should be smooth and not jerk around or stall (jerking means the machine screw is too tight!). The assembly should also be tight and not wiggle freely.
Step 7: Second Linear Actuator Assembly: Z-axis
Same exact procedure as the first linear actuator assembly with 2 exceptions.
1. Per pics 5-7 on this step, you have to route the Z axis servo cable through the groove under the rack prior to screwing down the 3 plastite screws that hole everything together.
2. At the very end leave the handle/tensioner off for now. It will be in the way for the next step.
Step 8: Join the Sub-assemblies
(I used cad here because I changed the order of operations later to make it easier for you.)
Mount the two assemblies together oriented as shown. Use all 4 plastite screws to attach the rack end to the flexible bracket. Screw down snugly but not overtighten at the risk of stripping out the hole.
Now you can add the mount the handle as shown. (it would have been in the way if you did it first.). Then adjust the tensioner on the handle to bring it into contact with the rack to prevent the rack from wiggling. Use the sweep function to verify that you have achieved smooth wiggle-free motion.
Note you can also add holder to hold up to 4 sharpies to the handle but that component is not going to be included in the kit.
Step 9: Assemble PCB Box
Order of operations is important here because later steps can prevent earlier steps.
1. Route the X-axis motor cable through the only slot in the mug lid part it is attached to.
2. Then route the Zaxis & Xaxis cables into the PCB box before screwing down the box.
3. Then use 2 screws to mount the box before installing the PCB.
4. Next clip on the small rectangular cover onto the arduino nano.
We will connect the cables in the next step but make sure to leave slack outside of the box on the Xaxis cable so the device can rotate freely.
Step 10: Install Cables & Pen. Physical Assembly Complete!
Route & Connect the cables like this:
- S2 = X (twist)
- S3 = Y (vertical)
- S4 = Z (pull-pen-to-mug) (I had to make room for the gripper cable in slot S1 because the cable couldn't stretch to the other end.)
Assemble the joystick to its mount exactly as shown, orientation matters. The Joystick has a 5pin ribbon cable to connect it to the joy1 row on the PCB. Make sure to match the cable color to the corresponding labels between the pcb & joystick. (GND, +5V, VRX, VRY, SW)
Use double sided tape to mount the battery case on top of the pcb case with its on/off switch pointing up and the cable on the same side as the pcb power inlet. Use a zip tie to further restrain the battery box cable to itself to make a little loop & prevent the excess cable from flopping around.
You can now set the device on top of your mug. When you want to draw attach the sharpie mini as shown. Press the cap over the back of the marker and use it to locate the depth of where you mount the marker. When not in use cap the maker and store it in the same location.
Remember to leave the mug on top of the rubber coaster when you print to keep it from sliding around.
Step 11: Calibration
Go back to your Notepad++ program and re-comment AssemblyAid() out. Then uncomment ManualControl. Again, this function contains a permanent loop to give you full control using the joystick.
If you followed these instructions all of your motors should be within a couple degrees of where mine are, this step is to make sure, particularly for the X axis.
Upload that code and use the joystick to drive it around. If the Xaxis places your pen over the top of the plastic mug lid then the Xdmin variable needs to be adjusted. Similarly, the Z axis should toggle the pen between floating just off the surface and fully engaged. (The joystick is also a button that we use to engage the Z-axis.)
After making those adjustments try to draw an algorithm shape. Comment out the ManualControl and uncomment out these three lines:
// drawDotRect(Xmin+33,Ymin+29,Xmin+53,Ymin+49,true); //(x0, y0, x1, y1, boolean pen toggle)
//drawRectSpiral(Xmin,Ymin,Xmax,Ymax,6, true); //(x0, y0, x1, y1, spiral spacing, boolean pen toggle)
//home(); detachAll(); delay(9999999999); //Home & Kill unit indefinitely
This will show you drawing using dots vs drawing direct lines as nested squares and then home the machine and turn off.
Step 12: Gcode Drawing- Preparing Your Image
Summary of Steps:
1. Create or find desired Image. You can use MS Paint to edit any image and save it as a PNG file. (For finding great ready to use images google search "black & white emoji" or "black & white clip art")
2. OPTIONAL: Convert Image to black & white high contrast outline. (white to become empty space, black to be printed. You can use color images but then you might not know if a color will be detected as more white or more black) Use Pixlr.com or Microsoft Office tools.
4. Convert SVG to STL file type, selecting a 0.1mm thickness. SVG2STL.com.
5. Optional: You can edit STL files here: TinkerCAD.com
6. Optional: Add words of any font. MXS Text-STL.com
Notes on Jargon:
- .PNG file = A very common image file. Is the most common lossless image compression format on the internet.
- .SVG file = A vector based image readable by 2D CNC software (CNC routers & lasercutters.)
- .STL file = The standard 3d printable 3d model file type.
Step 13: Repetier Slic3r Initial Setup
We use a combination of RepetierHost and Slic3r to prepare the gcode. Both are free open source actively supported programs.
If you are doing this for the first time you will have to setup the printer dimensions.
Repetier has to be setup manually. Do this by hitting the Printer Settings Tab and typing in the values shown in the picture. These values are the travel limits in mm of the Mug-O-Matic. They are mathematically derived based on the draw-able area. This is important or your image will get cut 'off screen' in the X axis when you draw.
You may need to adjust these to match the any changes you made to Xdmin in the earlier calibration step. See, the x axis can twist from 0-180 degrees, but we only use a portion of that movable area and repetier host thinks in millimeters, not degrees. My Xdmin was 31 degrees so I convert that into mm by dividing it by 1.5 deg/mm. (This is setting is based on the dimensions of the mug.) The result is 20.67 mm that I type into Repetier.
(Note the conversion from deg to mm for the rack axes is 2.25deg/mm (180deg/80mm).)
Also in Repetier you can get that fancy teal mug background like I have shown to help orient you, scroll down in that printer settings window and import the STL file from this step named "CoffeeMug-RepetierHost")
Next, in RepetierHost on the 'Slicer tab', select 'Slic3r' from the slicer dop down menu and then click 'configuration'. This will open Slic3r. In Slic3r click File > Load Config Bundle, and import the file named "Slic3r-config-Bundle-Nov2018.ini" from Github.
Its a bit of a mouthful to describe but once you get it you can draw & edit gcode to jump in and out of a drawing really quickly!
Step 14: Drawing- Convert Image to Gcode & Send
To prepare a drawing click 'load' in repetier host to import an STL file.
Scale it how you want, the bigger it is the easier it will be to draw. Just make sure not to scale the Z axis so the stl file remains at 0.1mm tall. (Otherwise it will try to trace over the drawing a second time when its done. )
Then Click the big slice with Slic3r button to generate the gcode. You can check the toolpath to make sure it is only drawing one layer in the Z axis. (You can view the code generated by clicking Edit Gcode but the code is completely usable as it is now.)
Now export the gcode by clicking on the 'print preview' tab and click the 'save to file' button. The name you choose is important because our processing program will have to find this file and read it. Pick the name "GCODE" (without the quotes).
Note that you will need to change the filepath in the code to change where it looks for the gcode. I saved mine on my desktop, but notice that my desktop file path will have a different username than yours. Right click on the icon for the GCODE file you created and check the filepath. That is what goes into the processing code, but notice that the
Copy the folder path from here and paste into processing, BUT NOTE, you have to change every \ into a // because thats how processing likes it. See the orange box in the processing screenshot.
Everything else is automatic. Make sure your TinyCNC is connected to your computer by USB and you have the power turned on. Press play in processing and it will begin drawing! Communication with the arduino is 2WAY, so it sends a line and waits to receive a //LineComplete feedback message before sending another line without delay. The gcode is usually hundreds or even a couple thousand lines long but the whole drawing process takes only a couple minutes depending on complexity.
Step 15: Experiments & Expansions
A really cool thing about this toy is that you can rebuild it into completely different kinds of robots. All using the same hardware, electronics, & tools and sometimes with adaptations of the same arduino code.
For instance if you add a gripper and a couple joysticks you can make Mug-O-Matic into a claw crane. The TinyCNC PCB is custom designed to allow for easy additions of electrical accessories you might want like an ultrasonic sensor, a built in buzzer, up to 2 joysticks, an IR remote, and bluetooth control from an android smartphone.
All parts in the Tiny CNC collection have the same mounting pattern and have proven designs which means this is a great tool for building whatever robots that peaks your curiosity. (And fyi it can drive larger servos as well.) At the moment I have built around 10 different useful combinations.
The models & basic code for those are shared freely but the primary robots that I will support are the Mug-O-Matic & and the Desktop Sentry. Also the STEP files have been shared which means that you can alter the 3d models as you wish. Please respect the sharing license (CC BY-NC-SA) which means you can do anything but sell them.
Another further experiment I am playing with is the idea of drawing via dot matrix. Basically send the Mug-O-Matic an array of 1's and 0's for every deg of possible travel, and having it move in a typewriter-like path and making a single dot every time it gets to a one.
Step 16: Electronics Tips & Tricks
Since this project required the design of a customized PCB (in KiCad) I thought I would share some interesting electronics tips & tricks I learned. (FYI I am a mechanical engineer professionally so forgive me if some are obvious but I thought they were interesting)
- Fastening & locating the PCB is an easily overlooked concern. When you are thinking in electrical terms you can forget that the board itself is a mechanical part. Dont forget to include an adequate number of holes for locating & securing the pcb.
- If you have more than a couple servos routed through blind holes it can help to label the servo & its header using a silver pen so it is easy to identify.
- Surface Mount components vs Through hole have different kinds of cost considerations. Each requires a different machine to install so if you are having them manufactured in bulk consider the tool change cost. On the other hand sometimes the component cost of one type is significantly cheaper than the other.
- It costs more to increase trace thickness, but not trace width. If you have a need to reduce trace resistance wider traces is the first option. Standard PCB copper thickness is "1Oz Cu" and there is a significant cost to jump to 2Oz.
- Making one prototype pcb costs essentially as much as making 10 because of machine setup charges.
- Upfront dollar spent increases reliability. Specifying an aluminum capacitor instead of an electrolitic gives you a larger range of acceptable input voltages and increases working life.
- Clever design can prevent user error. I placed the bluetooth module mount such that the bluetooth pcb blocks the usb port on the nano. This is because having both connected simultaneously confuses the arduino so I saved the user that potential frustration.
So that's all for now, stay tuned as this instructable will be updated if necessary! I hope you enjoyed reading about and learned something from this project! This has been the work of many months and if you would like to support me you can do so by:
- Check it out on CrowdSupply here!
- Share this project with your friends!
- Vote for this in the Instructables Plastics Contest because of my original open source 3D printed designs!
First Prize in the