Just in time for Christmas Eve, 2021, we completed The Claw!
This is a project that was a befuddling concept from July, 2021 until November, 2021.
In initial conception, I mainly looked to the Arduino Claw Machine v4 videos on youtube. The concerns rolling in my head, in no particular order, were:
- How does the claw mechanism work? How much power does it need? How much does it weigh?
- How do people do the linear motion for these? Lead screws? Belt-drive mechanisms? Rack-and-pinion?
- How will I build a frame for it?
Sadly, due to the pandemic, I'd lost access to my preferred makerspace.
It was my good fortune in July to have gone to a garage sale where they had been remodeling, and were giving away some clean bathroom cabinets. Those would form the basis of the physical structure.
I ordered a solenoid claw on eBay in July, 2021, just to get an idea of how it worked. I was surprised by how heavy it was, and that made me think that I'd need a strong framework for the X-Y linear motion mechanism.
The Cubex Duo
In November, the project got a big boost when a friend gave me the frame of his old Cubex Duo 3D printer, after he'd heard I was building the claw machine.
The machine had a belt-driven motion assembly and reed limit switches for both axes. All of that was working. The print bed and extruder and hot end were removed, and weren't necessary for my build. The main frame was comprised of 12mm rods in a cube layout, where the rods were about 18 inches (500mm) apart.
The Cubex also came with a BigTreeTech SKR 1.3 motor driver board, and several BTT TMC 2209 v1.2 motor drivers. There was a 12v power supply, too, but I ended up using a separate DC transformer. (This was only because I was doing prototyping in my kitchen, and the 12v PSU would pop the GFCI circuit.)
For my purposes, I intended to use the joystick signals to indicate motor movement, and just step the motors in different directions. The SKR 1.3 motor driver board was more geared toward having a Marlin implementation set up on it, and having motion managed by gcode. I ended up just using the TMC 2209 boards directly, leaving the SKR 1.3 out of it.
Unfortunately, most web sites that talk about the TMC 2209 don't address direct usage in an Arduino style. I had hoped to take advantage of some of the sensorless homing capabilities of the drivers. After a few experimental attempts at that, I just went with a basic bit-banging implementation. That worked out really well, and I still got very quiet motor movement.
The Cubex Y axis actually has two NEMA 17 motors driving belts that move the X axis motor and rails. With some clever wiring, they made it such that both motors could be driven from a single stepper controller. In fact, the machine could run with just one or the other motor, as long as it's properly lubricated.
The Cubex X axis moves the print head platform left and right. That platform rides along two 12mm rails and has its own magnet for triggering the X axis minimum limit reed switch.
When I got the Cubex, it still had its NEMA 23 motor and centered lead screw that would have raised or lowered the print bed. I didn't need that motor or lead screw, so those were removed.
The Z axis (spool/winch)
For this build's Z motion, I needed a reel or winch-type assembly to reel in or release the cord holding the claw. I didn't want to disassemble the platform, because it was already clamped to the X axis belts, and properly tensioned. Instead, I measured it and chose to use its center hole for the rope.
I printed a NEMA 17 motor mount so that the motor could directly drive a spool. That was designed to allow it be held in place with screws and fender washers, but I ended up placing it with double-stick tape, and it remains that way now. I might revisit that when it comes time to transport the machine, especially if I have to lay it down sideways.
I lathed the spool out of some excess hardwood. One end of the spool had a 5mm hole and set screws to attach it to the NEMA 17. The opposite end had an 8mm nub sticking out, and that went into a pillow block. The pillow block rested atop another printed plastic block so that the spool could run level.
The claw rope isn't held to the spool in any clever way. It's just taped to the interior of the spool, and sufficient excess rope is wound around it to keep it in place.
There is a printed gland that the rope goes through, and it serves two purposes. First, it prevents the rope from chafing against the sharp aluminum edges of the platform hole. Second, it has mount points for a microswitch. I used an existing microswitch and bent its metal lever so that it'd be hit by the claw. That serves as my "Z up" limit switch. (The picture shown here has v1 of the gland, where I hadn't added the limit switch mount points yet.)
This is "version 2" of the gland, shown from below, including the Z limit switch. The gland was extended to be a longer tube, and the microswitch is held in place with just some twist ties.
Breadboarding motor controllers
The TMC 2209 motor controllers are mounted in two 1x8, 2.54mm pitch, female headers. Those, in turn, are soldered to solderable breadboards (ElectroCookie 9 pack, $21). One easy mistake to make with TMC 2209 boards is to have their DIAG or INDEX pins touch the breadboard. I bent those out of the way but kept them in case I reuse them in some other way in the future.
I wired up the TMC 2209's in a pretty basic way.
- EN is always low, hardwired to GND. As such, I don't control motor enablement in software.
- MS1 and MS2 are set for half-stepping. It's interesting to note that these same pins are used for UART addressing. Many web sites don't mention that.
- I'm keeping the motor voltage and ground isolated from the Arduino 5v and GND lines. Some sites suggest tying the Motor and Arduino GND lines together, but I like the isolation.
- The motor outputs are connected to JST-SM headers (pack of 20, pre-wired, $10). While not as neat as having JST-XH headers, these JST-SM sets allowed me extra wire length, and it was nice having four wires for each.
- I did put in a 100uF 50V capacitor across motor GND and motor V. The specs typically call for a 47 uF or larger cap there. If you're using a motor carrier board, it's probably built on to the board already. (NB: specs also call for small caps near digital GND and 5V, but those actually already are on the TMC 2209 boards.)
As I soldered breadboards, I found that it was useful (from a physical layout perspective) to have the limit switch signal lines of each axis co-located with the axis motor lines.
Solenoid and relay
For the claw solenoid, I found a 30V power supply at the thrift store. Based on what was written on it, I think it was originally for some kind of powered speakers. I wired that through a relay module and it worked fine. I'm pretty sure the relay module has built-in flyback diodes to avoid reverse power spikes that solenoids can generate.
Sound
- Communication is done on a Serial line. The Arduino TX line runs at 5V and the module's RX runs at 3.3V, so you have to step it down or reduce it in some way. Many sites just have a 1k resistor in line between the two. I don't totally get how that works, but it does. There was one site showing how they'd voltage-divide it down to 3.3, and I think that's a better reasoned approach.
- For my purposes, sound files go onto a FAT32-formatted SD card and within the /mp3 folder. They must follow a nnnn_<whatever>.mp3 file naming convention. And despite the numeric nnnn prefixing, the actual play order and file indexing is based on the order in which the files are added to the SD card.
- The Busy line coming from the module is directly useful. There are some sites out there where people are asking, "How can I tell if the song is done playing?" and then people tell them to use the API to figure that out. Instead, I wired directly to BUSY line and check its value with digitalRead.
- I couldn't find a way to pause a song and resume it. Ideally, I'd want to signal recognition of a coin drop by playing a special sound, but if that happens in the middle of a long file, I end up fully stopping the current song, playing the "coin drop" song, and then not restarting what I'd interrupted. Of course, one way around this would be to have a second Mini DF Player.
Front panel controls
The Arduino loop polls the coin on each pass, and it's fast enough to recognize the coin drop without needing an interrupt. It also ignores duplicate coin slot signals within a 1 second period.
Keeping the signal wires tight
The front panel electronics -- joystick microswitches, button
microswitch, coin microswitch -- all connect their lines through an
MDFLY ethernet breakout board.Motion control prototype
During this phase of prototyping, the Cubex Duo was just that -- a cube. It's shown operational here.
Physical structure
Upper cabinet
Front Panel (physical)
Electronics (PC) assembly
- One Arduino Mega 2560
- One breadboard for the X, YLeft and YRight motor drivers
- One breadboard for the Z motor driver and MiniDF Player module
- One mini breadboard for hardwired pull-up resistors
- One MDFLY ethernet board (to talk to the front panel via an ethernet cord)
- One relay module (for the claw solenoid) and the appropriate jack for the 30V power supply
- One wire connector for the 12v motor supply
Front window
Hopper bin
I was pleasantly surprised with the acrylic bending technique. I used a hot gun on low setting, warming the acrylic for a little over 2 minutes. Then, I bent it over an edge of a makeshift vise.
This mostly worked, but to make sure the edges were square in both dimensions, I reheated it and bent it within a garage cabinet. That let me keep an eye on the alignment of all the edges as it cooled.
Back panel
The cabinet back panel is just a sheet of 1/4" plywood. We added contact paper on the inside to hide its wood look. Holes were cut out of the top to allow the motor control, solenoid, and limit lines through. There are three 3D-printed pieces that keep it in place, two on the bottom, and one on top.
PC-to-Back panel mounting
I printed my own panel holders to support the PC on the back panel. They provide about 5mm separation between the PC base and the back panel, allowing room for the standoff nuts and such. There are six of them holding the PC in place.
I only had #6 x 1/2" machine screws and nuts for this part, and they extend as far as I wanted to get through the back 1/4" plywood panel and Con-Tact paper, so I used the heated insert trick: I put a hot soldering iron to the screw, and melted it into all but one of the 3D-printed panel holders. That got the screw in farther, and also made the screw fixed to the plastic.
Roof
There is a simple hardboard panel that serves as the roof for the machine. I drilled holes so that it could be positioned using the cabinet's existing corner braces, which I assume had holes for holding a countertop or similar. The holes allow bolts to keep the roof in place. But, I chose not to actually have nuts attaching the roof firmly. That way, one can open up the roof to do repairs or even toss in toys.
The roof also serves as the mount point for interior lights. But since it's hardboard, and the rough side is on the inside, it's not something that would work for adhesives, such as are found on LED light strips.
Speaker
The speaker is visible in the picture above at the lower edge of the PC board. By size and shape, I'm assuming it's a typical coaxial car stereo type of speaker, and thus probably 4-ohm impedance. (The DF Mini Player specs I've seen online recommend 3-ohm or higher impedance.)
Out of sheer laziness, I attached the speaker with just one screw to one of the bottom PC wooden standoffs. That saved me the effort of cutting a speaker hole, etc.
Lighting
The initial build didn't have any lighting. It looked good in earlier pictures, but that's just because it was positioned under a garage light fixture (exposed LED T4 bulbs) with the roof off.
I had three under-cabinet, LED puck lights that ran on 12v (1.1W) so I positioned them inside -- two in front, one in back -- and hooked them up. The wires ran out the back, and all I had to do was power them.
Using the same power connection point as the motors, the lighting was pretty good. It wasn't as bright as the garage lighting. The problem was that the lights flickered a lot as the motors would run. I was using a 12V (measured 11.5V), 2.1A wall wart.
I tried running the lights off a separate 12V supply and that went better, but the lights constantly flickered. I attribute that to having a bad power supply.
Finally, I got a 12V, 4A wall wart, and used that on its own for both motors and lighting. That went well, so now I have lights.Cabinet stacking
The upper cabinet is stacked atop the lower cabinet. I used some spare 1/2" plywood to make something akin to mending plates in order to join them.
These mending plates were roughly 6" tall and 10" wide. I kind of blew it with their positioning. Originally, the plan was to mount them near the rear of the cabinet. That's because cabinets come with a toe kick area, which makes the range of placement shorter for the upper cabinet. I just habitually put one side's mending plate centered, and then did it the intended way for the other side. Measure twice, right?
The mending plates were sanded on all edges. Part of the reason for that was so that the upper cabinet could slip over the plates more easily.
I pre-drilled 3/16" holes at four points on each plate, and drew a midline horizontally on each. With the midline facing outward, I positioned one on a side, and drilled 1/4" holes through the plate and the lower cabinet side wall. I used 1/4" carriage bolts, so I had to make a little extra room for the "square" inner portion of the bolt head. I had hoped that simple compression into the cabinet wall's MDF would work, but the MDF was too strong for that. So, I ended up using something like a 19/64" drill, and just drilled a small amount inward to help seat the bolt head.
After both plates were installed on the bottom cabinet, we lifted and positioned the upper cabinet on top, sliding it over the mending plates. Then, I repeated the hole drilling -- again from inside to outside -- on the upper holes of each plate.
This is roughly what it looks like on the inside, though by the time I'm done it'll have fender washers. Without fender washers, due to how soft the plywood is, the nut and lock washer bite too deeply (for my tastes) into the wood.
Painting and cosmetics
My wife did all the painting of the exterior and interior of this, and it really made a difference. We used black semi-gloss (Behr Urethane Alkyd Enamel, Home Depot, 29 fl oz for $18!!). That stuff has gotten so expensive!
It was really cold and humid during the build, so the paint wasn't completely dry by Christmas Eve. We accelerated some of the drying by moving smaller parts indoors, and using a heat lamp on the upper cabinet.
Inside the cabinets, we used Con-Tact white shelf lining. Doing that as a two person job was a requirement, at least the way we were doing it.
Doing both the painting and lining made the machine look much, much better.
Power
Software
- Init state does X, Y, and Z homing and moves to Advert mode
- Advert state plays a random song every 15 seconds. If credits are added, it moves to Play Intro state. Advert state also moves the claw to a Y position of 100 steps.
- Play Intro state plays a start song, waits for it to end, and then moves to Play state.
- Play state looks for joystick and button operations. Joystick positions set up dx and dy values of 1 or -1 as appropriate. If the button is pushed it moves to Grab Descend state.
- Grab Descend state drops the claw a pre-determined number of steps, and then goes to Grab Engage state.
- Grab Engage state activates the claw solenonid and goes to Grab Ascend state.
- Grab Ascend state raises the claw until the Z limit switch is seen (and re-zeros the Z axis when the limit is hit). It then moves to Grab Deliver state.
- Grab Deliver state moves the claw to the hopper bin location and moves to Grab Release state
- Grab Release state releases the claw solenoid and goes back to Advert state, which moves the claw back to Y position 100 (which is roughly 1/6th inch from the back edge). Part of the reason for the move to Y 100 is to get the claw over the toy bin, so if someone turns off the machine, the claw falls in an area that's away from the hopper acrylic.
- Check to see what the current song number is. If the DF Mini Player is busy, wait. Otherwise, play the current song, if the repeat counter is 1 or more, and decrement the repeat counter.
- Based on the current mode, check input mechanisms (coin slot, joystick, button, timer).
- Depending on inputs, set up dx/dy/dz values (1, 0 or -1) and/or stop the current song and/or move to the next state.
- Process motor controls. At this point, dx, dy, dz are set up with some values. If those are non-zero, and if we're not already at limit points, perform stepper motor steps, and possibly add a short delayMicroseconds delay for smoother motion (and to avoid stalling).
Additional steps
There remains one last ugly bug in the software. If the machine is turned on when the Y axis is already homed, it seems like it thinks Z is homed. I'm not sure why.
As it turns out, I circumvented this problem by adding the Advert state function, which moves the head to Y position 100. I had done that to get the claw away from the hopper bin acrylic, because upon power-off, the claw drops rapidly, and I didn't want the hopper bin to be damaged. But as it turns out, that same function moves the head away from Y position zero in this errant case, so a second boot will start normally.
I have a sneaking suspicion that the root cause of that bug is in the limit switch wiring. I'm kind of thinking that all the limit switches should run with physical pull-ups that are the same, rather than using Arduino internal pull-up resistors. But that's totally a guess right now.
Final thoughts
What? "Final" thoughts? No way, I want to make another one!
The Claw was really, really well received by the kid. Merry Christmas!
Getting the Cubex Duo frame was the real kickstarter for this build. When I look back at the project timeline, it went in fits and spurts from July through mid-November, but then it kicked into high gear.
Having the bathroom cabinets for the frame also helped a ton. Overall, I was fortunate to have lots of stuff so I could do this on the cheap. I also was fortunate to have various power tools for this. I used almost every power tool at my disposal.
It was super useful to have a 3D printer for this. Modeling was done in Fusion 360. I'm using a somewhat aging Artillery X1 and mostly printed with Hatchbox black PLA. I printed pieces for
- NEMA 17 mount for the Z axis
- Z axis pillow block support
- Z axis gland and limit switch
- Blocks that prevent the whole assembly from falling into the cabinet
- Back panel clamps
- Jig for centering screw holes to attach FP to cabinet
- Front Panel L brackets (dual and single)
- PC supports/braces
- The coin slot top and bottom pieces
I didn't really get to learn how to build my own belt-driven, linear drive mechanism. Now that I've seen how they did it with the Cubex Duo, I feel like I could do it.
I don't quite understand how real claw machines leave their claws in an "up" position. When my system powers off, the claw falls. I'm guessing that they use geared DC motors, and it's the gearing that provides really strong physical resistance.
Next time, I'll have a better way to lay out the circuit boards. I'll put limit switch circuits, including pull-ups, closer to each motor, and I'll plan for having limit switches on both ends of the X and Y axes.
I'd like to learn more about those TMC 2209 motor drivers and get them documented better for Arduino people.
If I were to build this again, I think I'd have a different layout of the window and window frame.
Huh. I should probably post a video of the thing in action.