!!! Mediawiki has been upgraded !!!
Slack integration has been disabled for now due to an incompatibility.
If you want to testdrive the new skin (Tweeki), make sure your language settings are set to 'en - English' in your preferences!

3D Allen Key

From Brixel - Hackerspace Hasselt
Jump to: navigation, search


Project: 3D Allen Key
350x350px
Description: Create your own Allen key set with OpenSCAD.
Status: In progress
Participants: Johan
Expertise: 3Dprinting, OpenSCAD
Edit tags: 3D Allen Key


Intro

The right tools for the right job! But what if you don't have the required tool, but merely a 3D printer?
Well, let's print the needed tool!

For a repair I needed an "Allen Key", also known as a Hex Key. ("Inbussleutel" in Dutch.)
Although I have a set of Allen keys and some variants of Allen keys, I needed a very strange size and the tool also needed to be made out of soft material as the thing I wanted to repair had a smooth surface finish. (It was Chromed.)
I could have used a smaller Allen key with some cloth around it, but where is the fun in that? ;-)

As tools come in various sizes, these are the ideal things to make parametrized, so I used OpenSCAD.

Let's make an Allen key in OpenSCAD!

Circle trick

A hexagon created from a circle.

An Allen key is basically a streched hexagon with a 90° bend. But how do we create a hexagon in OpenSCAD?
We create one with a circle off course! ;-)

OpenSCAD has several special variables and one of them is $fn.
As explained on WikiBooks:

The $fa, $fs and $fn special variables control the number of facets used to generate an arc: ... $fn is usually 0. When this variable has a value greater than zero, the other two variables are ignored and full circle is rendered using this number of fragments. The default value is 0.

As a Hexagon has 6 sides, or fragments, we can create one very easily with a statemant like circle(r=5,$fn=6);

The only problem here is: If I need an Allen key of size 10, what should I use as radius? (The r parameter.)
5 is not the right answer, as the Hexa-circle has then angles that are 10 apart, and we need the sides to be 10 apart.

Geometric math learns us the right formula is circle(r=Maat/2/cos(30),$fn=6);, where Maat is the required size.

Straight parts

An extruded hexagon.

The straight parts are very easy. The hexagon we just created will be extruded. We rotate the hexagon 30° before extruding because it will change the position of the flat part of the Allen key in order to help printing it.

 module Kort_Stuk()
 {
 	// Kort Stuk
 	color ("Green")
 		linear_extrude(height=Kort)
 			rotate(30,0,0)
 				circle(r=Maat/2/cos(30),$fn=6);
 }

The same applies for the long part, but off course we need to translate (move) it to the correct place.
I also wanted to add some text to this part of my Allen key, therefor I used the Write library.

An extruded hexagon with text.
 module Lang_Stuk()
 {
 	// Lang stuk
 	color ("Blue")
 		translate(v=[-Lang - Bocht, 0, Kort + Bocht])
 			rotate(a=90, v=[0,1,0])
 				linear_extrude(height=Lang)
 					rotate(30,0,0)
 						circle(r=Maat/2/cos(30),$fn=6);
 	
 	color ("Yellow")						
 		translate(v=[-Lang - Bocht + 30, + FontSize/2, Kort + Bocht - Maat/2])
 			rotate(a=180, v=[1,0,0])
 				write(TXT,h=FontSize,t=0.8,font="knewave.dxf");
 
 }

The bend

Now comes the tricky part, creating a bent hexagon.
Unfortunately, OpenSCAD doesn't have a native way of bending, or manupilating 3D objects. There is some discussion about that.

OpenSCAD is able to manipulate 2D objects, like our hexacircle, with a rotate extrude:


"rotate_extrude" on a hexagon
"rotate_extrude" on a hexagon with blocks
 1 module Tussenstuk()
 2 {
 3   color ("Red")
 4     translate([-Bocht,0,Kort])
 5 
 6     // Rotate_extruded hexagon
 7     rotate([90,0,0])
 8       rotate_extrude($fn=64)
 9         translate([Bocht,0,0])
10           rotate(30,0,0)
11             circle(r=Maat/2/cos(30),$fn=6);
12  }

However, this creates a full rotation and OpenSCAD also doesn't have a way to limit the rotation to a certain angle. (Although there is an external library for that.)
As we need a straight bend (90°), we simply need to keep 1/4 of the rotation, or with other words, subtract 3/4. We simply use some blocks for that. (Second picture.)

We now have all the parts required to create an Allen key!
We just need to put them together and maybe add some text.

Complete Code

 include <write/Write.scad>;
 
 Maat  = 5.5;
 Kort  = 30;
 Lang  = 70;
 TXT="Johan Braeken - 5.5";
 
 FontSize = Maat / 2;
 Bocht = Maat;
 
 union()
 {
 	Kort_Stuk();
 	Lang_Stuk();
 	Tussenstuk();
 }
 
 
 
 module Kort_Stuk()
 {
 	// Kort Stuk
 	color ("Green")
 		linear_extrude(height=Kort)
 			rotate(30,0,0)
 				circle(r=Maat/2/cos(30),$fn=6);
 }
 
 module Lang_Stuk()
 {
 	// Lang stuk
 	color ("Blue")
 		translate(v=[-Lang - Bocht, 0, Kort + Bocht])
 			rotate(a=90, v=[0,1,0])
 				linear_extrude(height=Lang)
 					rotate(30,0,0)
 						circle(r=Maat/2/cos(30),$fn=6);
 
 	// Tekst
 	color ("Yellow")						
 		translate(v=[-Lang - Bocht + 30, + FontSize/2, Kort + Bocht - Maat/2])
 			rotate(a=180, v=[1,0,0])
 				write(TXT,h=FontSize,t=0.8,font="knewave.dxf");
 }
 
 module Tussenstuk()
 {
 	color ("Red")
 		translate([-Bocht,0,Kort])
 			difference()
 			{
 				// Rotate_extruded hexagon
 				rotate([90,0,0])
 					rotate_extrude($fn=64)
 						translate([Bocht,0,0])
 							rotate(30,0,0)
 								circle(r=Maat/2/cos(30),$fn=6);
 	
 				// Bottom Cube to subtract
 				translate([0,0,-Bocht])
 					cube([4*Bocht,2*Maat,2*Bocht],center=true);
 					
 				// Side Cube to subtract
 				rotate([0,-90,0])
 					translate([-1.5*Bocht,-Maat,0])
 						cube([4*Bocht,2*Maat,2*Bocht],center=false);
 			}
 }

Result

Complete rendering