My introduction to OpenSCAD through a quick, practical project
My friend Alex came to me with a project last week. His Logitech WingMan Rumble Pad gamepad was missing an analog stick and could I possibly print a replacement? (Answer: yes!)
It came up when talking with Andrew Plumb – if you’ve got something small and measurable to do, OpenSCAD is a great way to go. It lets you precisely script 3D primitives into position to make cool stuff. And of course it exports to STL format, perfect for your home 3D printer or your Personal Factory!
First I’ll show what the printing process on my MakerBot Cupcake was like, then I’ll walk through making a similar stick in OpenSCAD. Here’s gamepad as I received it:
My MakerBot has done some nice prints, but it has trouble with narrow items. Like this:
ReplicatorG can fill in support material though, so as a comedy option I tried the model standing-up “T”-style and it worked!
There was a lot of cleanup afterwards, but the sticks turned out pretty well.
How did I do it? Easy! I measured the remaining original stick with calipers and started placing cylinders in OpenSCAD. Here’s the main UI, just paste in what I’m writing and press F5 to refresh the 3D view after each step:
The analog stick has three main parts: the stick, the wider base of the stick, and the head of the stick. First I’ll enter these measurements that I took earlier:
// Measurements (in mm)
post_height = 10.30;
post_radius = 2.55;
post_base_height = 1.78;
post_base_radius_narrow = 2.55;
post_base_radius_wide = 3.88;
head_height = 3.5;
head_radius = 10;
$fn = 100; // special variable that affects output quality
Now I’ll define the cylinder for the main part of the stick and press F5:
cylinder(h = post_height, r1 = post_radius, r2 = post_radius);
Then the overlapping base of the stick:
// Stick base
cylinder(h = post_base_height, r1 = post_base_radius_wide, r2 = post_base_radius_narrow);
And finally the head of the stick:
cylinder(h = head_height, r1 = head_radius, r2 = head_radius);
Oops, that’s not right. Use the translate() function on the cylinder() function to fix it:
translate([0, 0, -head_height]) cylinder(h = head_height, r1 = head_radius, r2 = head_radius);
That’s it, a functional analog stick replacement in three lines of code. In the final version I added rounding on the head, a depression for the thumb, and a hole for attaching to the gamepad. Check it out on Thingiverse: http://www.thingiverse.com/thing:8544
Looking at other people’s OpenSCAD scripts was intimidating at first, but it really does start very simply. Keep the language reference handy and you’ll be making stuff in no time.
Derek Quenneville is a 3D printing evangelist who posts weekly on the Ponoko blog. Follow him on Twitter @techknight.