a blog for those who code

Tuesday 12 February 2019

3D printing for IoT developers

3D printing has been quite a phenomenon lately, and many have adapted to it. 3D printers are being used to create many wonderful things. In a true mark of progress, it can also be used by IoT developers to develop and make things on a small scale in order to experiment, learn and grow. All this leads to making both nascent fields work well together and on a greater scale, as things only keep getting better and more advanced in both areas of technological development.


3D Printing


3D printing is the process by which three dimensional real world objects can be created by a digital computer file. The process is called an additive process because the object is created by laying down successive layers on top of each other horizontally till the final object is formed. 3D printing raised a lot of hope about global accessibility and the ability to create anything you want, anywhere in the world.

What is IoT?


IoT, or the Internet of Things is a wonderful concept that connects a multitude of devices to each other over a network, where each device has a UID, or a unique identifier. These devices are then able to transmit information without any human intervention or interaction whatsoever. Any of these devices can be assigned an IP address and will thus be capable of transmitting things over the internet. These devices will then be able to transmit data by connecting to an IoT gateway, where data can be stored, transmitted or even processed and analyzed.

Use Case


3D printers can be used for a variety of things, like a container to hold IoT devices, which are usually fragile and in environments where damage is likely to occur. A great example is the IBM TJBot, which combines 3D printing and IoT. It is an open source project that works with Raspberry Pi, and can also be custom 3D printed and laser cut. 3D printers are already in use in the healthcare industry to manufacture devices that are custom made for a particular patient, while saving time and resources, as the required custom fit devices can be created at a fraction of the cost. It can be used to display 3D data in solid form, for example physics or math simulations of formulae and graphs; hence, being used in academia as well.

Development and Process Description


There are websites like Thingverse and 3Dshare that have many designs that can be used by 3D printing enthusiasts to try and create real life objects on their own. Designers often keep their 3D print designs open source, so you can either use them as is or make your own modifications to pre- existing designs, if you are inclined to do so. If you know how to create designs on your own, or if you know how to write code, you may even be able to make your own designs. You can also go through the many Maker recipes available for the IBM TJBot, where you can use or modify the pre- existing ones, or create new ones. The recipes are designed based on a Raspberry PI, and youcn modify it as per your requirements.

If you are more comfortable writing code, you can try a platform called OpenJSCAD. It allows the code to be written in Javascript, and then it can be converted to an STL file, which is a file format that can be used for printing.

Process Flow


Basic shapes

The basic OpenJSCAD entity is the shape. The simplest possible program creates and returns a single 3D object, (for example, a rectangular prism).

function main () {

The cube function creates a cube or rectangular prism. The size parameter can be either a single number (for a cube, which has three equal sides) or an array of three numbers (for a rectangular prism, whose sides vary in length).

return cube({size: [10, 5, 1]});
}

Transforming and combining shapes


We can transform shapes in various ways. Shapes can be translated (moved), rotated, and scaled. You can also create a union of multiple shapes, calculate their intersection (the points they have in common) or find the difference between one shape and another (the points that are part of only the first shape). These combinations allow for more complex shapes.

For example, you can use this program to create a box for a NodeMCU development board. This program needs three configuration parameters: the size of the device (as documented here), the margin of space to let us put the NodeMCU device comfortably into our box, and the width of the box walls.

const devSize = [49, 24.5, 13];
const margin = 3;
const wallWidth = 10;
function main () {

In each dimension, the size of the hole for the device is the size of the physical device plus twice the margin.

const holeSize = devSize.map(l => l+2*margin);

On the other hand, the size of the overall box is different between dimentions. In the x and y dimensions, there are two walls, one to each size of the device. In the z dimension, there is only one: the floor. We need a hole to insert our device into.

const boxSize = [
      holeSize[0]+2*wallWidth,
      holeSize[1]+2*wallWidth,
      holeSize[2]+wallWidth, ];

When we use the cube function, we create a rectangular prism with a corner at (0,0,0). This is fine for the overall box; it could be anywhere. However, the hole’s corner needs to be one wall Width away from zero in each dimension. That way, the hole is centered and all the walls are the same width.

const box = cube({size: boxSize});
const hole = cube({size:holeSize}).
translate([wallWidth, wallWidth, wallWidth]);

The complete box is the overall box minus the hole that is left open for the device.

const completeBox = difference(box, hole);

OpenJSCAD is JavaScript with a few specialized libraries. It runs the main function and expects that function to return the shape created.

return completeBox; }

A more useful example


The box we created in the previous program is not very usable. It doesn’t have a hole for the microUSB connector that NodeMCU requires as a power supply.




According to Wikipedia, this microUSB connector is 6.8 x 1.8 mm. However, using that figure is problematic: Cheap 3d printers are not 100 percent accurate. To make sure the hole is big enough, it needs to be designed to be a bit bigger. MicroUSB connectors usually have plastic handles that are bigger than the actual connector. That handle also needs to fit inside the hole.

In makes more sense to make the hole 15mm wide. However, if we just do that, we have a different problem: It is hard to plug the micro-USB connector when the NodeMCU is already at the bottom (because it’s hard to get it in exactly the right spot). If we pass the cable through the hole, plug it in, and attempt to put the NodeMCU in place, we have a different problem because it doesn’t fit.



Depending on how much dust is in the environment, we could solve this problem by having the slot for the micro-USB connector go all the way to the top of the box, as in this program. Also, most NodeMCU IoT devices need access to the NodeMCU pins. The easiest way to do this is to flip the NodeMCU device so the pins point up.



Shape restrictions


3D printing works by building the object one layer at a time. In addition to being time consuming, this process puts limits on the shapes that can be printed. It is a problem to print layers that are unsupported, even if the entire object would support them when the print job is done. So shapes like the following one aren’t printable (at the current orientation, it is printable if rotated).


A related problem is near horizontal angles. When you attempt to print such an angle, at some point during the process, you’ll have a very thin layer supporting a relatively large weight of material. Angles of more than 45 degrees for vertical, such as this one, usually don’t work.


One exception to this general rule is bridges: short horizontal pieces that connect between two vertical pieces. Those work, if they are short enough, because they are supported from both sides while they are being printed.


Most 3D print programs also have the ability to add supports to an object to make an otherwise unprintable shape printable (see the following example from FlashForge’s FlashPrint). However, if you use those supports, you need to manually remove them afterwards. It is much better if you can design your shape so that it does not need supports in the first place.



Printing a NodeMCU box with a lid in 3D


Armed with this knowledge of what shapes are supported, we can design a better NodeMCU box, one that has a lid on top of it. Use this program. The lid has to be printed as a separate piece for two reasons: It is necessary to be able to open the lid to insert the NodeMCU.

The width of the lid has to be at least 24.5 mm (nearly an inch), the width of a NodeMCU. That is too long to bridge.

The lid has two slots for wires connected to the NodeMCU. Those wires have a female end to connect to a NodeMCU pin and a male end to connect to a breadboard.




Another feature is the matching indentations on the lid and the walls of the main box. These indentations allow the lid to be placed directly on top of the box, but they do not allow it to slide much. The indentations are triangular in shape because consumer grade 3D printers are not accurate. If a rectangular indentation does not match exactly, either the lid would have too much room to slide or it would not fit at all. With triangular indentations, an inaccurate match would still allow for the lid to be placed correctly, maybe with a bit of force.

There is a rectangular section missing from the lid indentation. Because it is rectangular, a bit of force is required to shove the lid in or to pry it out. But because it is so small, the force required is very small and it still helps keep the lid in place.


Here is how the program creates those indentations:



The first step is to create a rectangular prism and rotate it 45 degrees around the X axis. The Y and Z dimensions are slotSize/Math.sqrt(2), so that the diagonal will be exactly slotSize.

const slotPrecursor = cube({size: [boxSize[0], 
                    slotSize/Math.sqrt(2), 
                    slotSize/Math.sqrt(2)]}).
rotateX(45)

When OpenJSCAD scales a shape, it scales around the [0,0,0] coordinates. We want to increase the height, and the easiest way to do it is to first move the prism so it will be centered around the X axis.


translate([0,slotSize/2,-slotSize/2])



To make the angle at the top of the indentation smaller than 90 degrees, we scale it on the Z axis.

scale([1, 1, slotHeightFactor]);

To make a triangular indendation instead of a rectangular one, we create a cube that is only the space above the Z=0 plane and intersect with it. This removes the bottom half of the triangle.

const zAbove0 = cube({size: [200, 200, 200]}). translate([-100,-100,0]);



This slot is the right size and orientation for the side indentations.

const slot = intersection(slotPrecursor, zAbove0).translate([0, (wallWidth-slotSize)/2 ,0]);

The indentation on the back needs to be rotated by 90 degrees around the Z axis and scaled to the size of the box on the Y (instead of X) axis.

const backSlot = slot.rotateZ(90). translate([boxSize[0],0,0]). scale([1,boxSize[1]/boxSize[0],1]);

The front indentation is similar to the back one, but it needs a small bit taken out for the USBconnector.

const frontSlot = difference(backSlot.translate([-boxSize[0]+wallWidth,0,0]),
usbHole.translate([0,0,-20]));



With all the indentations available, the program uses the union function to put all the indentations together.

const slots = union(slot,
slot.translate([0, boxSize[1]-wallWidth, 0]),
backSlot, frontSlot);



Now that we have the indentations, we can add them to the box to get the complete box.

const completeBox = union(noSlotBox, slots.translate([0,0,boxSize[2]]));



And also subtract them from the lid (in addition to the slots for wires) to get the complete lid.

const top = cube({size: [boxSize[0], boxSize[1], wallWidth]});
const wireHole = cube({size: wireHoleSize}). translate([(boxSize[0]-wireHoleSize[0])/2,0,0]);

const wireHoles = union(wireHole.translate([0,wallWidth,0]), wireHole.translate([0,boxSize[1]-wallWidth-wireHoleSize[1],0]));

const completeTop = difference(top, slots.rotateY(180).translate([boxSize[0],0,wallWidth]), wireHoles);

Print size and glue


The 3D printing material (PLA in most cases) is liquid when extruded by the printhead, and as it cools down, it is a bit sticky. As it is deposited, it sticks to the layer below it or the printbed, in the case of the bottom layer. However, it also sticks to the printhead. If the item you are printing is too small, the bottom layer might stick to the printhead with more force than it sticks to the printbed and be dragged away from where it is supposed to be. To avoid this, you can use a weak glue on the printbed before you start the print job and use a butter knife to separate the printed object after it is done.

Conclusion


It’s difficult to learn the skills to use a 3D printer by reading about them, rather than creating your own objects. But hopefully, I made you curious enough to invest in an inexpensive 3D printer and provided you with enough information to get started.

For More Information : https://ibm.co/2EMHaKx

No comments:

Post a Comment