Friday, March 17, 2017

Creating a mathematical rose in OpenSCAD


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)]];

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.

Friday, March 10, 2017

Creating complex 2D-shapes in OpenSCAD

Polygon and polyhedron

OpenSCAD allows the user to create complex shapes with the polygon function for 2D and polyhedron for 3D. Polygon and polyhedron both accept a list of 2D and 3D coordinates (points) respectively as parameters. A functions can generate a list of points eliminating the need to manually created these lists. This property can be used to create shapes that are impossible with the 2D and 3D shapes that are build-in in OpenSCAD. In this blog post I'll show how to create functions for some simple 2D shapes and explain how to manipulate the functions make more complex shapes with them.

Shapes created with functions and polygon in OpenSCAD.

Creating a 2D shape

To create a circle with a radius of 20 in OpenSCAD we just have to type


However OpenSCAD doesn't allow us to reshape this build-in function to for instance an ellipse. Alternatively we can write a function that generates a list of points needed for a circle and then use polygon with the points as parameter to draw the circle. The function uses the trigonometric formulas, x = r cos φ and y = sin φ, to convert polar coordinates to Cartesian coordinates.

function circle(radius) = [for (phi = [1 : 1 : 360]) [radius * cos(phi), radius * sin(phi)]];

When F5 is pressed a circle is drawn however the x,y coordinates of this circle are available to us. By adding echo(circle(20)); to our script the list of points is printed in the console. The circle function can easily be altered thus gaining a new shape. An example is shown below.

function circle(radius) = [for (phi = [0 : 1 : 720]) [radius * cos(phi/2), radius * sin(phi)]];
color("red") polygon(circle(20));

Shape create with x = r cos(φ/2) and y = r sin(φ)

Now let's take a look at the syntax of the function. Every function generates a value and in this case it is a list of points. In OpenSCAD a list of points in a two-dimensional space is represented by [[x1,y1],[x2,y2],[x3,y3],...] where all x's and y's are numbers. In this case of the circle function the point are generated in a for loop. The loop begin at 0 and ends at 720 with a step of 1. The radius * cos(phi/2) and radius * sin(phi) calculate each x,y coordinate for every given phi.

The ellipse, a generalisation of the circle, can now easily be created by slightly changing our function.

function ellipse(r1, r2) = [for (theta = [0 : 1 : 360]) [r1 * cos(theta), r2 * sin(theta) ]];
color("cyan") polygon(ellipse(120,80));

Ellipse created with the code above.

a second parameter is added. r1 is the radius in the x-direction and r2 is the radius in the y-direction. If r1 is equal to r2 a circle is drawn.


OpenSCAD allows the user to create complex 2D shapes using functions that generate lists of points This list is used as the argument in the polygon function of OpenSCAD. Every shape can be generated as long as the mathematical expressions are known and can be translated to OpenSCAD script. This opens up a world of possibilities.  The same is true for 3D shapes but instead of polygon the polyhedron function of OpenSCAD should be used. This however is a topic for a future blog entry.

Caveat: List comprehensions as shown in the functions of this  article 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. 

A special thanks to Xavier Faraudo who explained the advantages of functions in OpenSCAD to me.

Saturday, March 4, 2017

Getting creative with OpenSCAD


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.

Along the way I discovered that I'm not the only one using OpenSCAD for creative programming. I like to mention the website 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.

Saturday, January 28, 2017

DIY Hangboard (for climbers)


My youngest son is an avid climber and boulderer and he wanted a hangboard in his room to strengthen is arm, hands and fingers etc. I had a lot of wood left from previous projects so I used some of it to build the hangboard. After searching the internet and seeing a lot of examples we came up with the drawing below.

My son using his newly acquired hangboard for training.

Simple hangboard design.
The backplate and frontplate are made of 12 mm (1/2") plywood while the beams and support beams are made of 30mm (1 1/4") scaffolding wood. The rails are of pine wood of various thickness, 1 1/4" being the thickest and 18mm (3/4") the thinnest. The support beams strengthen the construction considerably.

Parts list

Here are the parts that are needed for this build.
1 x backplate 90 x 61 cm (3' x 2') plywood (12mm or 1/2")
1 x frontplate 90 x 31 cm (3' x 1') plywood (12mm or 1/2")
2 x beam 30 x 19 cm (12"x 7.5") scaffolding wood (30mm or 1 1/4")
2 x support beam 41.5 x 6.2 cm (14" x 2") scaffolding wood (30mm or 1 1/4")
2 x rails 90 x 5 cm (3' x 2") pinewood of various thickness
8 x carriage bolts 6mm (1/2")
8 x wingnut 6mm (1/2")
4 x lag screws 7 x 60mm (5/16" x 2.5")
4 x wall plug fisher 10 mm (3/8")
18 x twinfast screw 4.5 x 40mm (3/16" x 1 1/2")

Building the board

Building the board is straight forward. First I'd cut the plywood to the plates with the size indicated above. Next I'd cut the scaffolding wood for the beams. I used a simple Dremel DSM20 for this but any circular saw will do. Lastly I'd cut the pinewood beams. I used a router to make a radius on one side of the beams. This radius ensures that the beams are easier on the hands.

With all the pieces cut, I drilled the holes in the backplate, frontplate and rails. Next I assembled all the parts. Starting with the backplate and the beams. I used a 3mm drill before fastening the beams and the plywood with the twinfast screws. This avoids that the wood splits open. The beam and supportbeam were fastened with a single twinfast screw. Next I fastened the frontplate to the beams again using twinfast screws. To finish the hangboard I fastened the beams to the frontplate using the carriage bolts and wingnuts. Lastly I applied a transparent oil to the hangboard to provide protection It's more pleasing to look at too.

Fastening the hangboard to the wall may differ from situation to situation but since we have concrete walls I used four large wall plugs (Fisher brand). The board was then attached to the wall using the lag screws with washers to protect the wood.

Assembling the hangboard. Clamps of various size are very useful in situations like this.

The finished hangboard attached to concrete wall with four large wall plugs, lag screws and washers.

Inside view of the hangboard. By removing four wingnuts the beams can be exchanged for smaller of wider ones.
Detailed view of the lag screw and washer on the plywood backplate.


The hangboard proves to be strong enough for my son (he weights approximately 65kg). I tried it myself (I'm 90kg) but my fingers just aren't strong enough to keep my weight. Nevertheless I'm confident that the construction is more than enough to keep a weight well over 65kg. As for esthetics the board looks pretty good (for a hangboard that is).

Monday, January 9, 2017

Peddle wheel boat (3D printed)


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. Links to the downloadable files can be found here:

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.

Tuesday, November 22, 2016

Things you can do with PocketCHIP (other than gaming)


As a backer of the PocketCHIP Kickstarter I received the PocketCHIP a couple of months ago. For those who don't know, PocketCHIP is a very portable Linux computer.  It comes in a case complete with keyboard and screen. After receiving it I played with it but it soon ended up in the drawer. PocketCHIP is very nice and all but I just couldn't think of a killer app for it. Recently however I saw a YouTube video of SuperHouseTV who used PocketCHIP to reprogram Arduino's on remote places. This inspired me to get my PocketCHIP out of the drawer and do something useful with it. In this blog post I describe three different purposes that the PocketCHIP can be used for.

PocketCHIP, Arduino and breadboard peacefully together on my workbench.

Radiostreams and music

The PocketCHIP can be a very basic mp3-player. I first tried mpd with mpc as client but it was too much of a hassle. Next I installed mplayer and it worked flawlessly.

apt-get install mplayer

Now I can listen to mp3's and radio streams. For example to listen to a radio stream of  Dutch Public Broadcasting type:


or to run an mp3 or ogg file

mplayer <filename>

I noticed that the audio stream was interrupted when I did other things on the PocketCHIP (running CHIP 4.3) diminishing the usability. Hopefully this will change when the CHIP software will be optimized in the future. NOTE: The mplayer software is more than an audio player in fact it's a very capable media player.

Camera surveillance

Earlier I installed a Raspberry Pi based camera system to keep an eye on our backyard. I wanted the PocketCHIP to connect with the Pi not only for maintenance but also to check the backyard from. This proved to be surprisingly easy. First login from the PocketCHIP to the Pi using SSH:

ssh pi@ (change the ip address to your own)
your password

Next I use simple surf webbrowser to stream the video from the Pi to the screen of my PocketCHIP.


and presto a video stream of my back yard is shown on the PocketCHIP display.

Keeping an eye on my backyard with the PocketCHIP.

Programming an Arduino with PocketCHIP

as mentioned above the PocketCHIP can be connected to an Arduino to (re)program it. But I took it a step further. On the top floor of our house I have a hobby space. The Linux laptop (Puppy Linux) in the hobby space is very old and I'm unable to install the Arduino IDE on it. So I have the PocketCHIP with Arduino software installed connected with a USB cable to my Arduino UNO. With SSH I remotely connect my Linux laptop to the PocketCHIP and program the Arduino making use of the keyboard and screen of the laptop. This works great.

To install the Arduino software on PocketCHIP follow the instructions of SuperHouse. In addition to his instruction make sure to install the GNU make utility on PocketCHIP:

sudo apt-get install make

Now Arduino sketches can be written or changed on PocketCHIP and uploaded to the Arduino. Now to remotely connect to PocketCHIP I open the terminal program of the Linux laptop and type:

ssh -X chip@
your password

substitute the ip address of my PocketCHIP with the one of your own. The default password of PocketCHIP is chip. The -X option enables the X11 forwarding which is needed for the following step. Type in the terminal:


and after a few moments the Arduino IDE becomes visible on the laptop monitor enabling me to write, save, compile, build  and upload sketches from the PocketCHIP to the Arduino, remotely controlled by the laptop. Type:

make upload

To compile and upload the sketch from the PocketCHIP to the Arduino. Call me crazy but I really love this.

Working with the Arduino IDE on my laptop but running on the PocketCHIP.

Overview of my workbench with the Linux laptop on the left and PocketCHIP and Arduino side by side on the right.


These three purposes of the PocketCHIP reignited my interest in the platform.  The PocketCHIP has gotten a permanent place on my workbench which is much better than lying around in a drawer. I'm use it almost on a daily basis to program my Arduino. In the next months I hope to give some more tips on PocketCHIP and the things you can do with it (other than gaming).

Wednesday, November 9, 2016

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


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.


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.


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.