Pages

Showing posts with label 3D modelling. Show all posts
Showing posts with label 3D modelling. Show all posts

Friday, August 10, 2018

OpenSCAD: Camera case for the Raspberry Pi camera module

Introduction

At the end of 2015 I placed a DIY security camera in our house with a view on our backyard. The camera consists of a Raspberry Pi model B and a 5MP camera board module (It's been replaced by a 8MP version). I used Motion, a very flexible program that monitors video signal, on top of Raspbian. It worked all these years without problem but over time the wooden case that I made was starting to fall apart. I therefore decided to create a 3D printed camera case to replace it. I also wanted to use this opportunity to eliminate the problem of glare on sunny days.


Design of the Camera Case

The camera case consist of five parts. A back and a front of the case, a camera holder and lens to protect the camera module and easily insert it into front of the case, and a lens hood to prevent glare.  I used OpenSCAD, a free and open source program to design 3D CAD models. The Constructive Solid Geometry properties of OpenSCAD are excellent for these kind of designs. The back case has mounting points for the Raspberry Pi. I use the Raspberry Pi B but the mounting points are easily changed for other Raspberry Pi models, in fact I already added the coordinates for some other models.

I updated the design with stop ring for the lens module to prevent the lens to slide into the camera a little so this is a link to version 2. If you want to make the case yourself or just want to tinker with it here is a link to the OpenSCAD file: https://drive.google.com/open?id=1qJ7picRoSDI_HNSntF7nptrMazSRV3FF


Thursday, February 15, 2018

OpenSCAD: A Curved 3d Printed Lithophane

Important

This blog post has been reposted and updated on my current blog: https://homehack.nl/a-curved-3d-printed-lithophane-in-openscad/. You'll find the accompanying OpenSCAD file there too.

Introduction

How can I wrap a flat surface around a cylinder in OpenSCAD. This was a question I asked myself. OpenSCAD doesn’t provide a ready made method so we need to write our own. Luckily we don’t have to invent the wheel here, others have done that already. Justin Lin has written a very handy tutorial on his website Openhome.cc how to wrap a text around a cylinder.  In this project I took it a step further and wrapped a png image over part of a cylinder resulting in a curved image.

3D printed curved lithophane

Curved lithophane

It seemed like fun to combine this technique of wrapping with the 3D print of a lithophane. A lithophane is an engraved image on translucent material. Many 3D printers have already produced lithophanes sometimes with stunning results. For this experiment I’ll use white PLA because it  has excellent translucent properties.

Now first let me explain the basics on how to wrap a 2D image around a cylinder. First we create a circle out of triangles. These triangles are then extruded to segments to form a cylinder.  Next all segments of the cylinder are lined up in a row and the image is place on the far side but just within the limits of the segments. When we intersect the image with every individual segment and return the segments to their original position in the cylinder, a curved image emerges (see images below).

A circle created out of triangles
The extruded triangles form a cylinder
The segments are lined up in a row

Image placed on the far side of the triangles
The triangles returned to their original positions
The image intersected with the triangles and returned to their original position.

If you want to know more please watch my video. In this video the OpenSCAD script is explained and demonstrated. Also is shown how to import the stl file in Cura and what settings are used.

Thursday, December 14, 2017

OpenSCAD: Generating Triangles and Poyhedron

Polyhedron, vertices and faces

OpenSCAD offers three methods to make 3D model. First is Constructive Solid Geometry where primitive objects are combined using boolean operations. The second method uses two dimensional shapes that are extruded either in the z direction (linear_extrude)) or around the the z-axis (rotate_extrude). In the third method vertices (or points) and faces are defined to shape the surface of a 3D model (polygon mesh). This, at least in theory, provides us with a method to create the most complex 3D shapes.

Polygon mesh of a dolphin. In this example a triangle mesh is used. A public domain image from Wikipedia (https://en.wikipedia.org/wiki/Polygon_mesh#/media/File:Dolphin_triangle_mesh.png)

The third method can be achieved with the polyhedron function of OpenSCAD. The description polyhedron function in the OpenSCAD manual is more than adequate but it only provides the user with examples where the vertices and faces are manually entered in OpenSCAD. This can be a cumbersome process that is prone to bugs, leading to a non-valid solid. Having OpenSCAD generate these vertices and faces is a method that is more favorable (at least to me) for two reasons. First once the algorithm is correct the chance to generate non-valid solids is minimized but more importantly computer is so much faster in calculating the vertices needed.

Triangle mesh of a sphere

An important question is what kind of faces are needed for our polygon mesh. From OpenSCAD version 2014.03 onward a face description can have any number of vertex larger than two however I think that the triangle mesh is still the best choice. If the user chooses more than three vertices OpenSCAD subdivides the faces to triangles and this can cause problems as is demonstrated in an article of Justin Lin where a cube that consist of four vertex faces and one of the faces is not planar with the other three. So in conclusion the triangle mesh provides the best control over the 3D model in OpenSCAD.

In the following video tutorial I'll explain how to create such a 3D model of a sphere, cone, torus and cylinder in OpenSCAD.

Here is a link to the video:

https://peertube.linuxrocks.online/w/mohQABzAQ7FVapu4npswoJ

Wednesday, November 1, 2017

Raspberry Pi Squeezebox server with 3d printed enclosure

The need for a enclosure

Back in August I created a Squeezebox server using a Raspberry Pi 2 and a USB harddrive I had both lying around. I quickly had the server up and running and I'm using it ever since but I didn't have a enclosure. A 3D printed enclosure would enable me to give the server a more permanent place and at the same time I'm getting rid of these components and cables lying around on my desk.

The Squeezebox server sitting nicely into the 3d printed enclosure that I designed for it.

Solvespace for the enclosure

As a 3D CAD tool to design the enclosure I choose Solvespace. Solvespace is free and open source available for Windows, OSX and Linux. I use Solvespace a lot and it has it's limitations but I felt it was fully capable for this job and indeed it didn't disappoint. Before starting I made a couple of simple drawings with pen and paper, I measured the size of the harddisk and the Raspberry Pi. I also used a template for the Raspberry Pi mounting holes that I found online.

With all this information I started drawing with Solvespace. The power of Solvespace (and other 3D CAD programs) is that's it's very easy to make changes to the 3D design. While working on the design I noticed that USB harddisk can become hot so I figured it needed to be cooled. In the drawing I elevated the harddisk a bit by adding four supports one on each corner of the disk and made four ventilation slots in the bottom of the enclosure thus allowed air to flow freely around the harddisk. The Solvespace files of this enclosure are here. Make sure to adjust the size to the USB HDD you're using.

The 3D design I came up. The printed parts, bottom and lid, are grey, the green part is the Raspberry Pi and the red part is the USB harddrive.

3d printing and assembly

I printed all the parts on my Hephestos 2 printer using black PLA filament and the result looks pretty good. Assembly of the parts is simple. First I used 2.5mm bolts and nuts to mount the Raspberry Pi upside down to the lid of the enclosure. Next I insert the USB HDD into the bottom placing it on the elevated supports.  The enclosure is fastened with four bolts 5x60mm and 5mm nuts. The nuts fall nicely into the hexagonal cavity of the feet. Finally the USB cable of the HDD is connected with the Raspberry PI and the ethernet cable is connected from my router to the Pi. The server has run for several weeks in the 3d printed enclosure without any problem. For those that want more information I made a YouTube video about this project.

Tuesday, October 3, 2017

OpenSCAD Essentials: Lists and list manipulation

Lists

This is the second part in a series on OpenSCAD (here is a link to the first). This series will not cover the very basics of OpenSCAD, there is plenty of good material on that, but it's for those who want to advance beyond these basics. This part is about Lists, sequences of OpenSCAD values. These are very important in OpenSCAD because they are the equivalent of arrays. They're also referred to as vectors. Lists can contain values numbers, booleans and strings. For most examples below version 2015.03 is required.

Quicksort example from the OpenSCAD User Manual demonstrates how to manipulate a list. The red row of cylinders represents the unsorted list while the green row represents the sorted list.

First let's create some lists by typing the following in the OpenSCAD editor.

lst = [1,2,3,4,5,6,7,8,9]; //a list of numbers
lst2 = ["red","yellow","blue"]; //a list of strings
lst3 = [false,true,undef]; //a list of booleans
echo(lst);
echo(lst2);
echo(lst3);

In OpenSCAD the user is able to automatically generate lists with for, if and let. A couple of examples

lst4 = [for (i = [0:9]) i*i];

This generates a list of [0, 1, 4, 9, 16, 25, 36, 49, 64, 81], so for every i the results is i multiplied by i. OpenSCAD even allows nested loops

lst5 = [for (i = [0:2]) for (j =[0:2]) for (n=[0:2]) [i,j,n]];

This generates a list of a long list of vectors ECHO: [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 2, 0], [0, 2, 1], [0, 2, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1], [2, 2, 2]]

Manipulate a list

A list in OpenSCAD can be manipulated with a function. Manipulation is needed in order to make changes to the list. Since OpenSCAD is a Functional Language we can't just for example change value in the list. We need a function to do this. Lets assume we want to create a partial list from an existing list. We then create the following function:

function partial(list,start,end) = [for (i = [start:end]) list[i]];
echo(partial(lst,1,8));

In the Console of OpenSCAD the following is displayed ECHO: [2, 3, 9, 5, 6, 7, 8, 4]. The function has three parameters: a list, a start number and an end number. The function iterates through the list and then creates a new list with the items with indices 1 to 8. Note that the first item in the list with index 0 has been excluded from the new list. Another example.

echo(partial(lst,4,7));

This prompts ECHO: [5,6,7,8], a list with the 4th to the 7th item of lst. Remember that lst itself hasn't changed (you can check this yourself). Next we write a function to remove a number in a list.

function remove_item(list,position) = [for (i = [0:len(list)-1]) if (i != position) list[i]];
echo(remove_value(lst,2));

This prompt ECHO: [1,2,4,5,6,7,8,9], the third item in the list has been removed. The function, that has the parameters list and position, loops through the items of the list and if the index i is not equal to the parameter position it is added to the new list. In this example it means that the item with the index 2 is not part of the new list. The following function inserts a value instead of removing it.

function insert(list,value,position) = let (l1 = partial(list,0,position-1), l2 = partial(list,position,len(list)-1)) concat(add_value(l1,value),l2);
echo(insert(lst,10,4));

It cuts the list on the position 4 in two new lists, inserts a number of 10 between the two lists, using the function partial that was created above. The result in the console is: ECHO: [1, 2, 3, 4, 10, 5, 6, 7, 8, 9]. BTW: It's entirely possible that there's an easier way to do this.

The last and most complicated example is taken from the OpenSCAD User Manual and implements the quicksort algorithm. The quicksort function uses an unsorted list as input and produces a sorted list with a recursive method.

lst6 = [1,4,6,7,3,5,7,2]; //a list of numbers
function quicksort(list) = !(len(list)>0) ? [] : let(
    pivot   = list[floor(len(list)/2)],
    lesser  = [ for (i = list) if (i  < pivot) i ],
    equal   = [ for (i = list) if (i == pivot) i ],
    greater = [ for (i = list) if (i  > pivot) i ]
) concat(
    quicksort(lesser), equal, quicksort(greater)
);

echo(lst6);
echo(quicksort(lst6));

It produces the following output ECHO: [1,2,3,4,5,6,7,7]. The function starts with a base case !(len(list)>0) ? [] meaning if a the length of list is 0 return an empty list (or the boolean value false) else continue. Next a pivot is determined being the number in the middle of the list, in this case the number 3. Next all numbers in the list smaller than 3 are placed in a list lesser, all numbers equal to 3 are placed in a list equal and all numbers larger than 3 are placed in a list greater. These three list are then concatenated to a new list however, and now we get to the recursive parts, the lesser and greater lists are the new parameters for quicksort. This iteration continues until the base case, the length of the list is equal to zero or less, is reached.

Understanding lists and list manipulation is essential to advance in OpenSCAD. Without it would for instance be near impossible to work with the all important vectors in both 2D and 3D. But also in other areas, such as iterating through a row, lists are essential.

Friday, September 15, 2017

OpenSCAD Essentials: Functional Programming

Functional programming

OpenSCAD is a 3D CAD program where the 3D model is created with a script. Although the basics are very simple there is a point on the learning curve where the OpenSCAD programming language can become confusing. OpenSCAD is a Functional Programming Language and behaves differently than most people, used to the Imperative Programming Paradigm, expect. With Imperative Programming a value can be assigned to a variable and later another value can be assigned to same variable later in the program. This changes the state of the program. This approach will not work in OpenSCAD.

Sierpinski triangle in OpenSCAD. A program I made earlier that demonstrates recursion in OpenSCAD.

An example

The easiest way to explain this is with a simple example. In this example we want the program to add the numbers 1 to 10 (1+2+3+4+5+6+7+8+9+10).

total = 0;

module count(number) {
    for (i = [1:number]) {
        total=total+i;
    }
    echo(total);
}

count(10);

You might expect that the answer is 55 however to your horror you'll find in OpenSCAD that it actually is 0. What happened? Instead of assigning a new value to the variable total for every interation, total keeps it's initial value. The program written in OpenSCAD is a mathematical expression that is evaluated by pressing F5. OpenSCAD supports powerful functional constructs to support these expressions. In the case of the example above we write.

function sum(number) = (number == 0 ? 0 : number + sum(number-1));

echo(sum(10));

The result of this program is 55 as intended but how does it work. We define a function (hence the name Functional Language) sum with a parameter number. On the right side of the function there is an evaluation, in pseudocode: if n == 0 then 0 else number + sum(number-1). Notice that the function is recursive so for example for number is 3 the function evaluates as follows

sum(3) = 3 + sum(2) = 3 + 2 + sum(1) = 3 + 2 + 1 = 6

Iteration in OpenSCAD is usually accomplished via recursion. If you are not used to recursion it's takes effort and practice to understand but it's often simple and elegant. Now let's do a somewhat more complicated example, the greatest common devisor (gcd). When we look at gcd algorithms on wikipedia we find the recursive Euclidian algorithm which is described as follows:

gcd(a,0) = a
gcd(a,b) = gcd(b, a mod b)

Even if we would not understand the algorithm it's easy to translate it to OpenSCAD

function gcd(a,b) = b == 0 ? a : gcd(b,a%b);

Where a%b means a modulo b (BTW: the syntax used in the functions above is similar to the programming language C). It's worthwhile as a training to find recursive algorithms and try to implement them in OpenSCAD.

Further reading

If you want to advance in OpenSCAD it is necessary to read the manual at some point. This discloses valuable information that is hard to find by just using the Cheatsheet or the watching YouTube videos. The user manual can be found here: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language

Tuesday, June 20, 2017

Line and Polyline modules in OpenSCAD

Polygon in OpenSCAD

The polygon function of OpenSCAD is very cool but for some applications it just doesn’t cut it. For instance when polygon is used to draw a Starpolygon, a self intersecting polygon, the space between the polygon lines is filled, an undesired effect that cannot be negated. In case of the Starpolygon we just want to see the lines.

Line and Polyline

Luckily we can create our own polygon module in OpenSCAD that meets our needs. However before we can create a polygon we need to be able to create a single line. Also a single line can be created in OpenSCAD, actually in several ways. In the YouTube video below I'll show one such approach.

A Vase created with line, polyline and rotate_extrude in OpenSCAD.

Furthermore I’ll show how to create a line module and a polygon module that fit our needs but it doesn’t stop there. With the line and polyline a complete 2D-library in OpenSCAD can be created. Also, in combination with linear_extrude and rotate_extrude 3D objects can be created that are impossible to create with CSG alone.



In a next blogpost I’ll show you how to create a Bezier Spline with line and polyline. This Bezier Spline can then be used to create a smooth curve needed in a 3d printable vase for example.

I want to mention Justin Lin here. He has a great website www.openhome.cc where he, not only shares his OpenSCAD work, but also explains it in great detail. I think it’s a very useful resource for OpenSCAD.

The file of this video can be downloaded with the following link: https://drive.google.com/open?id=0Bwg0RBbuN0fMVkJISXdDQV9sekE

OpenSCAD is open source (GPLv2 license) and is well maintained by Marius Kintel et al. Besides the stable releases for Windows, OSX and Linux, development snapshots are available. I recommend using these development snapshots since they have all the latest features. 

Friday, June 2, 2017

Cubic Bezier Spline tool in Solvespace

Cubic Bezier Spline tool 

The Cubic Bezier Spline tool in Solvespace can be used to create shapes that are hard or impossible to accomplish with other tools such as straight lines. A Cubic Bezier Spline is a line segment that can be controlled with four points. By changing the position of these points the curve can be manipulated or smoothened.

By clicking with the left mouse button in the graphics window the new control points can be added to the Cubic Bezier Spline tool to a maximum of 12. This is essentially a Composite Bezier Curve or polybezier. The problem with these curves is that it is hard to keep the curve smooth.

Polybezier with eight control points fully constrained approximating a circle


a classic example of shapes that benefit from Cubic Bezier Splines are Vases. Vases also appear to be popular with 3d printers. In the video below I'll demonstrate how to create a Vase in Solvespace using the Cubic Bezier Spline tool.

At the end of the Vase video I’ll demonstrate two often overlooked functions in Solvespace, the Length Ratio constraint and the Length Difference constraint I’ll also show how to apply the Length Ratio constraint to two circles.


The Solvespace Vase file from this tutorial can be downloaded here.

For this tutorial I used Solvespace 2.3 on OSX.

Solvespace is open source (GPLv3 license) and is available for Window, OSX and Linux. It is developed by Jonathan Westhues and maintained by Whitequark and others. It can be downloaded here: http://solvespace.com/download.pl

Tuesday, May 30, 2017

Spiral Phyllotaxis patterns in OpenSCAD

Spiral Phyllotaxis

In just uploaded a YouTube video about Spiral Phyllotaxis patterns in OpenSCAD. This time it’s a script that I made to demonstrate Spiral Phyllotaxis. Phyllotaxis is a term used for patterns that emerge during the growth of plants. Spiral Phyllotaxis is observed in the heads of sunflowers, in pine-cones and pineapples, and in a variety of other plants.

The script that I wrote uses a mathematical description of Spiral Phyllotaxis called Vogel’s formula. Vogel’s formula actually exists of two equations, one for an angle theta, and one for a radius, describing the a pattern of seeds in a sunflower head. I’ll put a link in the description if you want to know more about Vogel’s formula. These simple equations can generate beautiful patterns that have some interesting mathematical properties.

The number of spirals derived from Vogel’s formula has a close relationship with the Fibonacci sequence. Exactly 55 spirals go counterclockwise, 34 smaller spirals go clockwise and 21 even smaller spirals go counterclockwise and so on. These numbers of spirals are all integers in the Fibonacci sequence.

The Golden Angle or Fibonacci Angle of 137.5 degrees is key in these Spiral Patterns. This angle results in the best distribution of the seeds. A slightly smaller or larger angle leads to a less optimized distribution.

Not only can the Spiral Pattern be examined in OpenSCAD. A big bonus of the program is that the user can create an stl file that can be printed. The physical model can then be studies further.

Tuesday, May 16, 2017

A Solvespace tutorial, the Fidget Spinner

Another Solvespace tutorial. 

In this tutorial I'm going to create a Fidget Spinner. For those who don’t know, a Fidget Spinner is a stress-relieving toy. A basic Fidget Spinner consists of a bearing in the center of a design made from any of a variety of materials. I got this idea from Paul Randall’s YouTube channel. Paul has a great channel with an increasing number of excellent OpenSCAD and FreeCAD tutorials. Last week Paul uploaded two video tutorials where he creates a Fidget Spinner, one in OpenSCAD and one in FreeCAD. I thought it was a good idea to add a Solvespace tutorial to this and leave it for the user to judge which of these open source 3D CAD programs is best for these kind of models.

The Fidget Spinner that we create in this tutorial can easily be 3D printed. However it may require some adjustments of the dimensions before it can be succesfully assembled into a working Fidget. When this is finished insert a bearing and three nuts and the Fidget is ready for use.

Sunday, May 7, 2017

Video on 2D Supershapes created in OpenSCAD

2D Supershapes

I just uploaded a video on 2D Supershapes created in OpenSCAD, the open source 3D CAD program. 2D Supershapes are based on an equation, the Superformula, proposed by John Gielis around 2000. Gielis suggested that the formula can be used to describe many complex shapes and curves that are found in nature. The possibilities with the Superformula seem endless. OpenSCAD not only let you recreate these Supershapes but also enables the you to 3D print the shapes.

Wednesday, April 12, 2017

TIE fighter in OpenSCAD

Introduction

OpenSCAD is an excellent 3D CAD tool to create space craft because of their symmetrical, non-organic shape. This video of a space ship is a good example. However I couldn't find much Star Wars models made in OpenSCAD. So I decided to do it myself and start with a simple TIE fighter.

TIE fighter made in OpenSCAD.

 

Design

When I create a model like this I start with simple primitives and get the position right. In this case a sphere that represents the command pod, two cones that act as pylons and two hexagons as solar arrays. Once I have a basic TIE fighter I start shaping the different parts. Since all these parts are modules this doesn't interfere with the positioning.

Most basic shape of a TIE-fighter consisting of a sphere, two cones and two hexagons. Hexagons still need a 30 degrees rotation around the x-axis.

I use a couple of global constants that mainly determine the positioning of the different parts of the TIE fighter. The're seperate modules for the command pod, solar array and the wing pylon. Also a seperate module exists for the solar panels that are part of the solar array.

Most of the code is pretty standard OpenSCAD maybe with the exception of the solar array. The solar panel is created with a polygon which is a trapezoid. The trapezoid needs to fit between the inner en outer hexagon therefore the points of the trapezoid are depending on these hexagons of the solar array. The angle of the trapezoid is 120 degrees enabling me to calculate the all points of the trapezoid solar panel with basic trigonometry. The variable delta in the solar_panel module enables us to create and edge on the solar_array.

//Modules
module solar_array (outer_radius, inner_radius) {
    difference() {
        union() {
            cylinder(r=outer_radius,h=2,$fn=6);
            cylinder(r=inner_radius,h=4,$fn=6);
        }
        for (i=[1:6]) {
            rotate([0,0,i*360/6]) translate([0,inner_radius,0]) translate([0,0,1]) solar_panel(outer_radius,inner_radius);
            rotate([0,0,i*360/6]) translate([0,inner_radius,0]) translate([0,0,-0.3]) solar_panel(outer_radius,inner_radius);
        }
    }
}

module solar_panel(outer_radius, inner_radius) {
    //delta determines the size of the edge of the solar array.
    delta = 3;
    //x and y determines outer side of the solar panel trapezoid
    x = inner_radius/2 + sin(30) * (outer_radius-inner_radius-delta);
    y = cos(30) * (outer_radius-inner_radius-delta);
    echo(x,y);
    list = [[-inner_radius/2,0],[inner_radius/2,0],[x,y],[-x,y]];
    linear_extrude(1)
    polygon(list);
}

The TIE fighter model is largely parametric meaning that the most of the design of the model can easily can be changed by changing the parameters (constants). This model of the TIE fighter can is still rather basic but it can be expanded by modifiying the different modules.

3D printing

Until now I didn't feel the need for 3D printing the model (my extruder is in repair anyway) but with a few modifications printing shouldn't be a problem. I would print the command pod first and attach the solar array with wing pylon later.

The OpenSCAD file of the TIE fighter can be found here.

OpenSCAD is open source (GPLv2 license) and is well maintained by Marius Kintel et al. Besides the stable releases for Windows, OSX and Linux, development snapshots are available. I recommend using these development snapshots since they have all the latest features.



Wednesday, March 29, 2017

Creating interactive 3D models in your browser with Solvespace

Interactive 3D model

It may be convenient to view a interactive model made in Solvespace using a webbrowser. For instance if you want to share the model with someone who hasn't Solvespace installed. Luckily Solvespace has an option just for this under File -> Export Triangle Mesh. Now in the dialog window select Three.js-compatible mesh with viewer (html). Save the file. An html file is now available that can be viewed in the browser (I only had succes with Firefox, Chrome wouldn't show me the model). The html file created by Solvespace consist for a large part on Javascript and relying on the Three.js Javascript library. All the points, edges and faces of the 3D model are included in this file.

Screenshot of the html file created by Solvespace and opened in the Firefox browser.

When the html file is opened the 3D model can be rotated (left mouse button), moved (right mouse button) and zoomed (scroll wheel). The options are activated by a mouse click in the frame. Clicking on the scroll wheel deactivates these options.

One step further

This can be taken one step further. The model can be integrated in a website. The simplest way is to use the <iframe> tag in html. Below is a simple example where cube.html is the file that has been generated by Solvespace.

<!DOCTYPE html>
<html>
    <head>
    <title>
    This is a cube
    </title>
    </head>
    <body>
        <iframe src="cube.html", height="600", width="800"></iframe>
    </body>
</html>

That's it, the interactive model will show up in the webpage which is a pretty cool Solvespace feature. BTW: I didn't bother demonstrating it in Blogger because I think it's to much of a hassle editing the template.

For this tutorial I used Solvespace 2.3 on OSX.

Solvespace is open source (GPLv3 license) and is available for Window, OSX and Linux. It is developed by Jonathan Westhues and maintained by Whitequark and others. It can be downloaded here: http://solvespace.com/download.pl.

Friday, March 17, 2017

Creating a mathematical rose in OpenSCAD

Introduction

In my previous blog post I explained how to create complex 2D shapes in OpenSCAD. Once a mathematical expression for a shape is known it's possible to translate it to OpenSCAD script. The Carthesian coordinates of mathematical rose, a rose shaped sinusoid, can be expressed by x = cos(kθ)cos(θ) and y = cos(kθ)sin(θ). If k is an integer a the shape will be relatively simple but is k is a fracture more complex shapes are created.

One of the shapes that can be created with the rose_points function (linear_extrude is used to create a 3D shape).

Writing the script

All the points needed to create the rose will be generated in the function rose_points. Rose
_points returns these points in a list. The function will have the form:

function rose_points(k,n,radius) = [...]

The parameters k and n will determine the shape of the rose. If n = 1 the curve will a simple rose shape but if n > 1 more complex shapes are drawn. Here is a link to all the possible shapes when varying k and n. The syntax of OpenSCAD for lists allows us to use if and for elements to construct a list. In the case of our function we can use these elements.

step = 1;
function rose_points(k, n , radius) = k%2 == 0 && n%2 ==1 ? [for (theta = [0 : step : 360 * n]) [radius * cos(k/n*theta) *sin(theta), radius * cos(k/n*theta) * cos(theta)]] : [for (theta = [0 : step : 180 * n]) [radius * cos(k/n*theta) * sin(theta), radius * cos(k/n*theta) * cos(theta)]];

a=rose_points(5,7,100);
color("red") polygon(a);

The function looks intimidating at first due to the list comprehensions.  The key is to just break it apart. The two parts between square brackets contain lists of points (generated by a for loop). The rest is an if, then, else statement: if k is even and n is uneven then [] else []. More information on the syntax for a list (list comprehensions) can be found here.

The function isn't perfect. With some combination of k and n (e.g. 6 and 2) nothing is displayed on the screen. The reason is that with this combination all points are repeated prompting the polygon function of OpenSCAD to draw nothing. In this cases it helps to change the range of theta.

Caveat: List comprehensions as shown in the rose_points function are only possible with OpenSCAD v2015.03 and above.

OpenSCAD is open source (GPLv2 license) and is well maintained by Marius Kintel et al. Besides the stable releases for Windows, OSX and Linux, development snapshots are available. I recommend using these development snapshots since they have all the latest features. 

Shape created with k = 2 and n = 1.

Shape created with k =8 and n = 7.


Saturday, March 4, 2017

Getting creative with OpenSCAD

Introduction

OpenSCAD is software to create solid 3D CAD Models but other than most 3D CAD programs a model can be created with a programming language. Although OpenSCAD is often used to create models for 3D printing it also very capable as a tool for creative coding. Creative coding is more about being expressive than being functional.

Sierpinski triangle made in OpenSCAD (recursive algorithm).


Creative coding

I've been using OpenSCAD for over a year now for my 3D printing projects but as of late I'm exploring the creative possibilities of this programming language. It all started when I was watching another episode of The Coding Train, a great and often hilarious YouTube channel from Daniel Schiffman. In this show Daniel Schiffman takes on coding challenges. These coding challenges can be a physics simulation, data visualization or computer vision. While watching the show I was wondering which tool would be suitable to take on these challenges myself. Schiffman is mainly using Processing and P5.js which aren't in my skill set. I have a basic understanding of Python but not enough to start coding these challenges. OpenSCAD has become the programming tool that I'm most familiar with so I figured to give it a try.

OpenSCAD is pretty well equipped for creative coding. No need to import additional modules or libraries to draw onto the screen. It also comes with ready to use 2D and 3D primitives, geometric transformations and boolean operations for 2D and 3D primitives. OpenSCAD is a functional programming language as opposed to most common programming languages such as Python, C and Java which are imperative languages. In OpenSCAD variable keeps one value so i  = i + 1 won't work and f(x) will always produce the same result for a given x (as in mathematics). Once you get your head around that working with OpenSCAD becomes easy.

OpenSCAD doesn't disappoint for creative coding. Although some challenges didn't seem possible with OpenSCAD, because of the limited animation features of the program (or my lack of understanding of these features, others could be easily achieved with it. Below are examples of challenges that I did with OpenSCAD.


Mathematical rose pattern made in OpenSCAD.

Phyllotaxis pattern made in OpenSCAD.

Openhome.cc

Along the way I discovered that I'm not the only one using OpenSCAD for creative programming. I like to mention the website openhome.cc which has an excellent OpenSCAD section. This section not only explains the underlying fundamentals of OpenSCAD but also has creative chapters about spirals, turtle graphics and maze.

OpenSCAD is open source (GPLv2 license) and is well maintained by Marius Kintel et al. Besides the stable releases for Windows, OSX and Linux, development snapshots are available. I recommend using these development snapshots since they have all the latest features.

Monday, January 9, 2017

Peddle wheel boat (3D printed)

Important

This blog post has been reposted and updated on my current blog: https://homehack.nl/peddle-wheel-boat-3d-printed/. The files are also available on Printables here: https://www.printables.com/model/286241-peddle-wheel-boat

Introduction

At the moment I'm making 3D design and 3D printing lessons for schools. A good idea that I'm exploring is the Paddle Wheel Boat. I found an example on Thingiverse, a rubber band powered boat with two peddle wheels, but it has two problems. First of all the author only provides .stl files and second the design is a bit flawed. I therefore decided to design the boat from the ground up with OpenSCAD. With OpenSCAD I'm not only able to edit my models quickly, I'm also able to share the OpenSCAD script allowing other to use and change it.

Assembled Paddle Wheel Boat.

Paddle Wheel Boat

The Paddle Wheel Boat that I created consists of four parts: the boat, the shaft and two peddles. The main change of the boat that I designed is the position of the shaft. It's been shifted to the middle of the boat providing more balance. I also enforced the attachment point of the rubber band to the boat making it impossible to break it.

The redesigned Paddle Wheel Boat with shifted positon of the shaft and enforced attachment point for the rubber band.

I also increased the size of the paddles enabling the boat to move faster. The shape of the paddles are rounded instead of square improving the dynamics of the paddles through the water. A problem with the old design is that the rubber band has to be fixed to the shaft with some tape. Not a very elegant solution. I added a square hole to the design of the shaft. The rubber band can be inserted through the hole and fixed to the shaft. No tape needed.

Simple square hole in the shaft. The rubber band fits right through the hole making it easy to fix it to the shaft.
Changes to the models are easily made. The OpenSCAD script is simple and the result of a change can be reviewed immediatly by pressing F5. E.g to move the shaft to the back of the boat can be achieved by just one simple change in the script.

Peddle wheel loaded in Cura 2.3.1.

Just four parts, the boat, shaft and two peddles, are needed to make the boat. If you don't want to make changes to the design just download the provided .stl files and open them in your favorite slicer. After printing the Peddle wheel boat can be assembled and tested. Have fun.

All printed parts plus the rubber band.


Wednesday, November 9, 2016

The BQ Hephestos2 (3D printer), nine months later

Introduction

It's been nine months since I received and assembled my BQ Hephestos 2 printer and I think it's time to share some of the experiences that I had with it. For those who don't know the Hephesthos 2 it's a 3D-printer that is based on the Prusa i3 design with a thick steel frame and almost all metal parts. It's not cheap but it's a well designed, high quality 3D-printer with a large printbed. It does have it's shortcomings but more of that later.

The Hephestos 2 printer just finished a job. Laying around the printer are Pritt adhesive, a brass brush, cleaning fluid.


Printing and printing problems

Over these nine months I've printed a large variety of objects for different projects mostly without problem. I used both PLA and Filaflex and both materials printed fine. The Hephestos 2 doesn't come with a heated printbed, one of it's shortcomings, and I still struggle with the occasional lack of adhesion to the printbed. I ended up using both BuildTak and Pritt and this solves the adhesion problem most of the time however as I found out this is not a guarantee for good results. First of all the printbed must be clean from fingerprints and other contamination. I used to clean the bed rubbing it with warm water on a cloth which is a bad idea because water doesn't remove oily residue very well. Now I clean the printbed with isopropylalcohol (IPA) making sure that all residue has been removed.

To avoid problems with printing the distance from the nozzle to the printbed is also important. When this distance is too large the first layer becomes messy and adhesion problems occur. I use a piece of paper and place it between the printbed and the nozzle. I consider the distance correct when a piece paper can barely be moved underneath the nozzle.

The z-axis of the Hephestos 2 is not the best possible design. It uses M6 threaded rods (EDIT: actually it's M5) which can produce an effect called z-wobble. This effect is noticeable in the z direction in my prints from time to time. It would have been better if a z-rod with a higher pitch had been used (such as the Original Prusa i3 Mk2).

A variety of objects printed with the Hephestos 2.
Messy first layer and lack of adhesion when the distance between the nozzle and the printbed is too large.
Warping. Adhesion problems can have many causes. In this case I the printbed was not leveled properly.

Using Filaflex

As mentioned above Filaflex prints fine on the Hephestos 2 but there was a problem with the spool holder. The inner diameter of the Filaflex spool is smaller than the PLA spool therefore it doesn't fit on the spool holder that came with the printer. When I contacted the supplier about this problem he immediatly designed a spool holder for filaflex which I was able to print and use. An excellent service of the supplier.

Printed spool holder for Filaflex.

Maintenance

The Hephestos 2 as any other 3D-printer does require maintenance. I use oil to grease all the axis from time to time. On top of this I use grease for the threaded rods of the z-axis. I also check the tension on the belts from time to time. The nozzle is cleaned regularly with a brass brush after increasing the temperature to 200 degrees Celcius. The Hephestos came with two long needles that can be used to clean the hotend just by inserting the needle through the nozzle en pushing it all the way through the extruder. Lastly the PTFE tube in the hotend can be replaced with a spare one that came with the printer. Just make sure that the somewhat larger opening of the tube is pointing upwards after it is inserted in the hotend (see also hotends problems below). A maintenance video of the BQ Witbox 2, the enclosed ready to use brother of the Hephestos 2, is available. Unfortunately it is only in Spanish.

It is advisable to check the Allen screws from time to time. Due to the vibration some screws may come loose. Recently one of the threaded rods of the z-axis came loose because of this. Besides a misprint I had to deassemble and realign the z-axis and level the printbed again.

 

Hotend problems

One months ago after changing a filament spool the new filament the extruder made a clicking sound and no filament was extruded from the hotend. The supplier adviced to change the PTFE tube that's inserted into the hotend. Unfortunately the problem remained but I did notice that a piece of the old PTFE tube was missing. I therefore concluded that pieces of PTFE were stuck in the hotend. I tried to clean the hotend without succes so finally I decided to exchange the hotend with a new one and presto problem solved. The problem was probably caused while changing filament. While removing the filament I pulled it from the extruder which is a bad idea because the PTFE tube can be lifted and damaged in the extruder.

NOTE: Exchanging the PTFE tube is relatively straight forward but make sure that the tube is inserted in such a way that the hotend is positioned correctly in the coldend of the extruder. I damaged my BuildTak layer because the hotend was positioned too low. See the bottom two images for this.

Hotend of the BQ Hephestos 2 with the PTFE tube sticking out.

Damaged PTFE tube with a piece missing. This pieces end up in my hotend preventing any filament to be extruded.

The hotend not fully inserted into the coldend resulting in a damaged printbed.
The new hotend fully inserted into the coldend.

Conclusion

After nine months I can say that I'm still satisfied with the BQ Hephestos 2 printer. I've printed numerous models without problems. It doesn't come with a heated printbed which I believe is a shortcoming. The problems that I had with the printer were mostly solved thanks to the support from the (Dutch) supplier and the Google+ 3D printing community. As a beginner in 3D printing I can't stress how important good support is. At some point problems will arise and without support chances are that you can't solve them and possibly ending a beautiful hobby.

3D printing is a hobby that by nature is very DIY requiring lots of time and the readiness to experiment. This begins with the design of a 3D model in 3D CAD, slicer software to create gcode and working with the 3D printer itself. If you're willing to do that the BQ Hephestos 2 is a good choice although it's price can be prohibitive to some.

Thursday, September 29, 2016

Switching from FreeCAD to Solvespace?

Introduction

For my current project, a laser engraver, I initially choose FreeCAD as my 3D CAD program. I had some excellent experiences with it so it was the obvious choice for me. However contrary to previous work this project required a lot of CAD assembly. This is where I became frustrated with FreeCAD. Assembly in the current version (0.16) just isn't well implemented unnecessarily extending my time spent with FreeCAD. The next version of FreeCAD (0.17) will have a separate assembly workbench but I wasn't willing to wait for it's final release.

When reading the Hackaday website I came across Solvespace. Given the problem that I have with FreeCAD I was immediately interested. Solvespace is a parametric modeler just like FreeCAD. The interface looks archaic which put me off a little at first but I found it surprisingly easy to work with. The last month I worked intensely with Solvespace v2.1 and I want to share the experience that I had with the program.

The Solvespace GUI looks archaic but is easy to work with.

Friday, July 8, 2016

Make a Photography Light Box of cheap material (part 1: design and 3d print).

Introduction

My wife has a lot of stuff she wants to sell online and asked me to create a sturdy but cheap Photography Light Box. The dimensions of the different objects vary so I wanted to be flexible with the dimensions of the light box. We came up with a simple idea to create a three way connector that connects curtain rods. The frame will be covered with white bed sheet kept together with velcro. At the local hardware store I found plastified steel curtain rods. These were the cheapest I could find but are still very strong.

Photography Lightbox Frame modelled in OpenSCAD. The connectors are 3d printed while the rods are steel curtain rods

Creating the three way connector

I used OpenSCAD to create the three way connector and a 3d model of the light box frame. OpenSCAD is an excellent (and free) program for these symmetrical shapes. Creating the connector in OpenSCAD is therefore easy as can be seen in the timelapse video below. Creating a good 3d printed model is more difficult. The connector that I originally designed had overhang and several changes had to be made to compensate for this. Also I needed a connector that fitted firmly on the rod but could also be diassembled with ease. I therefore experimented with the connector by adding or removing part of the cylindrical shape of the connector.

Timelapse video of the first attempt to create a three way connector. Although it looked ok I had to make several changes afterwards to optimize for 3d printing and to get a better connection with the rod.

First I added a very small cylinder on either side of each larger cylinder. If the side cylinders are small enough the connector still fits into the rod but some force is needed to pull it out again. Another variant is a somewhat larger cylinder with on each side a smaller cylinder cut out (see image). Both solutions work fine I'll settle for the cut out cylinder since it looks nicer :D.

Two cadidate connectors that hopefully give a better fit into the rod. The connector in the front has is somewhat larger radius of the cylinder but two smaller cylinders are cut out. The connector in the back has a very small cylinder on either side of the larger cylinder.
Five iteration of the three way connector with the two latest in the front.

Next I'll print all connectors, cut the curtain rods to the desired size and assemble the frame. I'll leave it to my wife to finish the Photography Light Box with velcro and diffuser fabric. Want to 3D-print this yourself? All files for this project can be downloaded here.