3D printer and first case for Gyro’clock

The 3D printer arrived a week ago and I have been using it pretty much every day since. The Prusa I3 DIY printer kit I ordered from Amazon came from a company called Shenzhen Anet Technology. They provided instructional videos of how to assemble it, and it took me about a full day to put it all together. Assembling the printer was quite fun and it’s great to know what every nut and bolt in it does. The printer also came with two spools of PLA filament.

Here’s the completely assembled 3D printer:

Fully assembled 3D printer

Fully assembled 3D printer

So for my first test I decided to print the Gyro’clock case I designed previously. The 3D printer firmware understands G-code. To convert the 3D design made in FreeCAD to G-code it must be given to a slicer software. The 3D printer manual recommended to use Cura for slicing, so I decided to use it. The slicer program literally slices the 3D model into many layers for the 3D printer to print one by one.

After exporting the design in FreeCAD as a .stl (stereo-lithography) file I opened it up in Cura. When you first start up Cura, you have to give it information about your 3D printer such as print size, nozzle and filament type etc. After loading the .stl file, Cura also gives options to scale, rotate and mirror the object, which is handy. After converting the image to G-code I saved it in an SD card, which can be inserted into a slot in the printer.

It took about an hour and a half to print the bottom part of the case, and this is how it turned out:

Bottom piece of the Gyro'clock case with the Gyro'clock PCB

Bottom piece of the Gyro’clock case with the Gyro’clock PCB

The top piece took only 30 minutes or so since it was smaller in size, and this is how it turned out:

Top piece of the Gyro'clock board

Top piece of the Gyro’clock case

During this first run of the printer I noted a few problems with my design and a few issues with the printer:

  1. The walls were too thin. I designed the walls to be 0.8 mm wide. This made the case too flimsy and it was too flexible. My attempt to remove the pieces from the printer bed caused them to bend slightly.
  2. The holes were too small. The screw holes I made to attach the board to the case and the top piece to the bottom piece were non-existent in the print.
  3. Printer does not wait for minimum time interval before moving to the next layer. There is a setting in Cura for selecting the minimum time spent on a layer. I set this value to 5 s. But I noticed when the top piece was printing the printer does not wait the minimum interval between the layers. This caused the snap on part of the top piece to deform. Could be a firmware bug.
  4. I forgot to create a window for the switch and the charger LED. There is no excuse for such carelessness!
  5. The printer has trouble making small overhanging features at 90°. This is understandable because there is no support underneath to hold the thin strands of melted plastic. So the first few layers of an overhanging section (or a bridge) does not hold well. But if the overhang is thicker and the bridge is not that wide then later layers will build up properly.
  6. Masking tape on the heated bed lifts causing the print to bend. This printer has a heated bed. Masking tape is put on the metal bed so the print job will not stick to it. On repeated use this masking tape looses its adhesiveness and lifts from the bed causing the printed object to bend. The solution for this is to replace the masking tape for each print.
  7. Formation of snags causes the printer head to jump. It was good that I noticed this problem before it became an issue. When the printer head moves across a gap following the same route multiple times, excess plastic can cause snags to form. The next time the printer head comes around the same path the snag could block it. This could cause the printer to misalign. Fortunately I saw the printer jolt a few times on a snag and cut off the snag before it got too large. A good reason not to leave a print job unattended for too long.

After cleaning up the two pieces of the case to remove snags and excess plastic I put the two pieces together. There was no need to attach the board to the case with screws since it fitted snugly. I also cut off the deformed snap on piece of the top part.

And here’s the resulting case:

First 3D printed Gyro'clock case

First 3D printed Gyro’clock case

This was a good learning experience about 3D printing. Now I know what to do for the second version of the case. It’s coming soon!

 

Making a case for Gyro’clock

I officially finished all my school work since last week and finally had some time to think about my projects. There are two projects I started a while ago that I would like to finish off first. They are the Smart Turn project and the Gyro’clock project.

The only big thing left to do for the Gyro’clock is to make a case for it.  This means that I am finally getting around to the 3D print scene. This is exciting because I am going to be learning a new trick that has lots of potential. But first I have to learn about making 3D models.

There are many software programs out there for making 3D designs. After some search I decided to go with FreeCAD mainly because it is fairly sophisticated. After spending some time playing around with it and watching some tutorials I am able to find my way around it.

My approach for designing a case was to import the board layout that I have already created in KiCad and then build a simple case around it. Importing a 3D model of a PCB designed in KiCad to FreeCAD is quite simple. But the problem is I didn’t have 3D models for all the components in my Gyro’clock PCB. Importing 3D models from FreeCAD to KiCad is not that straight forward since KiCad only accepts a certain kind of .wrl files only.

After doing a bit of search online I found a nice tutorial that explains step by step how to create 3D models for PCB components. The steps I followed to make 3D models for components in KiCad are

  1. Design the 3D model in FreeCAD
  2. Export the 3D model as a .stl (stereolithography) file
  3. Import the .stl file to Wings3D
  4. Add colour to the model
  5. Export the model as WRML 2.0 (.wrl) file
  6. Import the .wrl file to KiCad
  7. Scale and position as necessary

Here’s the complete 3D model of the Gyro’clock board:

Capture4

3D model of Gyro’clock board

After completing the 3D model of the board I imported it to FreeCAD. The case has two pieces. The bottom piece wraps around the board and holds the rechargeable Li-poly battery. The top piece is just a cover and snaps on to the bottom piece.

Capture5

Bottom piece of the Gyro’clock case holding the PCB and the Li-poly battery

Capture2

The top piece snaps on to the bottom piece

Designing the case in FreeCAD is just a matter of knowing the proper dimensions. Since I had a life size model of a fully assembled Gyro’clock PCB it was really easy. Of course I don’t know how well it will come out of the 3D printer yet. Since this is going to be my first 3D experiment I am not going to go super fancy.

Speaking of 3D printers I have already ordered one and waiting for it to arrive. It is a Reprap Prusa I3 3D printer kit and I found it on Amazon.ca for $420 (CAD). It is a DIY kit so it comes with more fun.

First Gyro’clock board assembled!

Since I have finished building my home made reflow oven, now I can use it to assemble parts in the Gyro’clock boards.

The first step is to ensure that I have all the parts for the board. Since ideally you would only want to reflow the board once. I organized this in my project book as shown below. This makes it easier to find all the parts when it is time to place them on the board. Also the parts will not get mixed up! (The 0.1 uF, 22 pF and 4.7 uF caps all look the same!)

IMG102

Making sure all the surface mount parts I need for the board are there before starting

Then I realized that I am missing a key component: 3.3 V Zener diode. Ordering just a single part from Digikey is quite expensive and I will have to postpone the board assembly yet again. Luckily I had a through hole 3.3 V Zener in my parts inventory. So I made a choice to do the reflow without the Zener, and then afterwards solder in the through hole Zener to the surface mount pads.

The next step is to put solder paste on the pads. I am using Chip Quick no clean lead free solder paste (SMD291SNL-ND). The solder paste came with a syringe and a nozzle. Ideally to put solder paste on a board you have to make a stencil first. Getting a professionally made stencil for a board can be quite expensive. So I decided to do it the hard way by putting solder paste manually on the pads using the syringe.

I had no idea how difficult it is to put solder paste onto a pad with a syringe. The paste didn’t really stick at all. You have to make sure not to put too much solder paste on a pad. If you do then you run the risk of making solder bridges. Too little solder paste and it won’t make a good connection. Having never done this before, I had a high risk of making one of or both of those two errors. Solder bridges on pins can easily be corrected later so I wasn’t too worried except for two components: The ADXL345 accelerometer and the HSMF-C165 bi-color LED. All the pads of these chips are located underneath the component. I only had one chance to get it right with these two.

With care and patience I put solder paste on all of the surface mount pads.

IMG108

Solder paste applied to surface mount pads on the board

Once solder paste is applied to the pads it is time to place the components on the board. I must say this part is quite fun. Specially putting the resistors and capacitors. Once placed on the pads the solder paste holds the component in its place. The ATmega328p took a little aligning and the ADXL needed quite a bit of nudging to get it in place. Once all the components are placed on the correct pads (also in their correct orientations; watch out for those polarized caps!)

IMG112

Once all the components are placed on the pads the board is ready for the reflow oven

Once all the components are placed in the pads I put the board carefully in the reflow oven and ran a previously prepared custom reflow profile. After about 10 minutes the board was ready to be taken out of the oven.

assembledBoard

Gyro’clock board out of the reflow oven

Initial inspection showed that there were no solder bridges! All the resistors and capacitors showed solid connections with their pads. The only issue was the 3PDT switch, and this could have been totally avoided. The heat caused the plastic parts of the switch to melt. The switch was unusable.

So I removed the switch and manually soldered in another one in its place. After that I soldered in the Zener diode, the seven square LEDs that go on the edge, and the 150 mAh liPo battery. And then the moment of truth; Did the accelerometer and the bi-color LED make it? Did all the parts survived the heat inside the reflow oven?

They did! I was able to upload the bootloader to the ATmega328p and program it. The bi-color LED was working, which also meant that the LiPo battery charge circuit was also working.

IMG133

A fully assembled Gyro’clock board (left) next to a bear Gyro’clock board (right)

I am very happy that the first try on my home made reflow oven was a success. The next step for the Gyro’clock project is to make a case for it. That is another completely new avenue for me to explore. Until next time!

New Gyro’Clock boards!

Here are the new Gyro’clock boards! They arrived a couple of weeks ago but I haven’t had time to write about it until now. They look fantastic! I can’t wait to put parts on to them and see how they work.

Gyro'clock boards fabricated by OSH Park.

Gyro’clock boards fabricated by OSH Park.

The boards are 6cm X 3cm

The boards are 6cm X 3cm and have two copper layers.

I am very happy to have found OSH Park, a community PCB manufacturing service that makes this possible. So hobbyists like me don’t have to spend a fortune to get a professionally made PCB.

The next step is building a reflow oven, so I can assemble the components on to these boards. While waiting for these boards to arrive, I had begun construction of the reflow oven. I will put up a series of posts about how it is made next. Stay tuned!

Manufacturing PCB layouts made in KiCad

Up to this point I have made all my printed circuit boards at home, which is great fun and comes with a great sense of satisfaction when your circuit finally works. But it also takes a lot of time, expensive, and you have to deal with messy corrosive chemicals. But if you really like to print your circuit layout at home, check out how I did it here.

But now I am ready to outsource the manufacturing of my PCB layouts. One of my colleagues told me about this awesome community PCB manufacturing site called OSH Park, where you can get your layout printed at a very reasonable price. And they don’t require you to order a massive number of boards.

I finally finished laying out the component footprints and traces for my new and improved Gyro’clock circuit. Before doing this I ordered all the parts so that I can check them for reference while I am creating some of the custom footprints, and also I don’t run the risk of using obsolete parts after I have manufactured the boards. Here is what my finished design (all layers) looks like in KiCad

New and improved Gyro'clock layout in KiCad

New and improved Gyro’clock layout in KiCad

The 2-layer board is 6.2 cm by 2.9 cm. Not the ideal size I wanted, but I like how everything fits nicely. I chose the following design rules before doing the layout as per specifications on the OSH Park website:

  • minimum trace width: 0.1524 mm (6 mil)
  • minimum via diameter: 0.6858 mm (27 mil)

My default net class values used for all the connections are the following:

  • trace width: 0.2032 mm (8 mil)
  • trace clearance: 0.2540 mm (10 mil)
  • via diameter: 0.6858 mm (27 mil)
  • via drill: 0.3302 mm (13 mil)

I placed all the component on the top plane and made the bottom side into a ground plane, but had to route some traces through the ground plane. Altogether there are 41 vias on the board. A high number of vias, but most of them are ground connections.

In my 2-layer board there are seven layers that are important for getting the board manufactured:

  • top copper layer – contains component pads and traces on the top layer
  • top solder mask – contains regions in the top layer that will be exposed for soldering components
  • top silk screen – contains component references and texts on the top layer
  • bottom copper layer – contains component pads and traces on the bottom layer
  • bottom solder mask – contains regions in the bottom layer that will be exposed for soldering components
  • bottom silk screen – contains component references and texts on the bottom layer
  • PCB edges layer – contains the outline of the PCB board

To manufacture the PCB, OSH Park requires Gerber files for all the layers above plus a drill file. The following steps will explain how to create Gerber files in KiCad for OSH Park. I got these information from this blog, but changed a few options to suit my design.

Step 1: Verify DRC (Design Rules Check) with OSH Park specifications.

  • select DRC from the Tools menu or click the ladybug icon in the top bar. Fix any errors in the DRC before proceeding to next step

Step 2: Open the plot dialog box by selecting plot in the File menu or by clicking the printer with a P icon

Step 3: Select the following options in the plot dialog box

Plot dialog box options in KiCad

Plot dialog box options in KiCad

I used the ‘Subtract soldermask from silkscreen’ option to remove the silkscreen from areas where the holes in the solder mask will be. However, even if you didn’t do that OSH Park and most PCB manufacturers will remove the overlapping areas of the silkscreen. But it is better to check for yourself which parts of the silkscreen will be removed.

Step 4: Click the Plot button in the plot dialog box to generate the Gerber files.

Step 5: To open the drill file option box click Generate Drill File from the plot dialog box

Step 6: Select the following drill file options

Generate Drill File dialog box and options in KiCad

Generate Drill File dialog box and options in KiCad

Here, OSH Park requires you to ‘Keep zeros’, use ‘2:4 precision’ and use a ‘Minimal header’.

Step 7: After selecting the correct options in Step 6, click the OK button to generate the drill file which will be in Excellon format.

Step 8: Finally examine each Gerber file and the drill file for errors using the GerbView tool in KiCad.

Here are what my top and bottom side Gerber files look like in GerbView:

Top side copper, solder mask, and silkscreen Gerbers

Top side copper (green), solder mask (blue), silkscreen (white) Gerbers and the drills (purple)

The bottom side copper (green), solder mask (blue) and silkscreen (white) Gerbers

That’s it! I have submitted my board for fabrication to OSH Park, and it cost me $14.35 for three copies. I will add another post when the boards arrive. Meanwhile I have started work on my other spin-off project, which is to create a reflow oven to assemble the surface mount components into the Gyro’clock boards.

New and Improved Gyro’clock circuit

Since now I have working prototypes of the Gyro’clock, my next step is to make it more practical and usable. The prototypes are bulky and fragile, not something I can carry around with me in my pocket. So I have been working to make it smaller and more reliable.

I decided to find replacements for all the through hole components on the prototype board with their surface mount counterparts. For resistors and capacitor I decided to go with the 0603 package. I could have gone for a smaller size still, but looking ahead since I would have to place them on the board by hand, 0603 is a safer choice.

Next I had to find replacements for the two breakout boards I used in my prototype. The breakout boards got to go because they are expensive and take up too much space. The easiest of the two breakout boards to deal with is the ADXL345 breakout from Sparkfun. The only components on this breakout board are the ADXL345 accelerometer, two 0.1uF capacitors and one 10uF capacitor. All of them could be bought at a much cheaper price individually.

The other breakout board is the USB charger for the Li-Po battery from Adafruit. This breakout board includes a JST connector for the Li-Po battery, a micro USB connector, two status indicator LEDs, MCP7383 Li-Po charge management controller IC from Microchip and several resistors and capacitors. I decided to include the MCP7383 on my board with a single bicolor status indicator LED, a micro USB connector along with three resistors and a capacitor. Instead of using a JST connector for the Li-Po I am going to solder the Li-Po wires directly to the board.

The last thing was to choose the right LED for the job. I liked the water clear 3 mm red LEDs I used in my prototype. But to increase the viewing angle I had to sand the LED caps. I was searching for LEDs with a large viewing angle and ran into square shaped LEDs from SunLED. This LED has a viewing angle of 110° and are already diffused.

The figures below show the schematic for the new and improved Gyro’clock circuit

Schematic of the new and improved Gyro'clock circuit showing the Li-Po charging circuit and the accelerometer connections

Schematic of the new and improved Gyro’clock circuit showing the Li-Po charging circuit and the accelerometer connections

Gyro'clock schematic showing the ATmega328p and the LED connections

Gyro’clock schematic showing the ATmega328p and the LED connections

In addition to all the components I also added test points to certain locations to help with troubleshooting the board later on. One other very important consideration is how to program the ATmega328p microcontroller while it is attached to the board. In the prototypes I removed the microcontroller from the dip socket and transferred it to a breadboard setup for uploading the program. But now with the SMD version this is no longer possible. So I added a program header to the schematic and also added jump points in the traces so I could disconnect the necessary pins from the rest of the circuit when programming.

And here is a list of all the parts in the new Gyro’clock circuit:

PartsList

List of parts used for the new and improved Gyro’clock circuit

The next step is laying out the components and traces, which I will cover in my next post. Stay tuned!

Gyro’Clock Firmware 3

Welcome to the final episode of the Gyro’clock firmware. In Gyro’clock Firmware 1 we talked about the trigger detection module, and how it figures out when to trigger the time display. In Gyro’clock Firmware 2, we talked about the real time clock module, and how it accurately keeps track of time using the asynchronous timer of the ATmega328p microcontroller. In this episode we are going to learn how to display the time like this with just a row of 7 LEDs:

When someone asks you what time it is, this is how you show it off

When someone asks you what time it is, this is how you show it off

Okay let’s break this down; We have a row of 7 LEDs moving in a circle. The LEDs are pointing radially so the movement is always perpendicular to the row. Let’s divide that display into radial segments. Each segment is seven pixels in size. Each pixel is represented by a single LED. So at each time step we decide to either turn on or off each LED. Then we display the LEDs for a bit, and then again change the status of the LEDs. If we do this fast enough and move the row of LEDs while we are doing it, then we can see the whole image at once. I am not going to get into why we see things that way, since that is not the focus of this post. Some call it “persistence of vision”. But I will tell you a neat way to implement this.

The on/off state of the LEDs can be expressed as either a 1 (on) or a 0 (off). So at a particular time step the LED sequence might look like: 1001110, where LEDs 2,3,4 and 7 are on, while LEDs 1,5 and 6 are off. If we add one more bit to the end of those 7 bits and set it to be always 0, then we have 8 bits (a byte!) representing our LED sequence. And we can have a group of those bytes in an array and display them one after the other, which forms our image.

The LED sequence for each digit is stored as an array of bytes

The LED sequence for each digit is stored as an array of bytes

Now for the Gyro’clock this image is changing every second, since we are displaying time. So we would have to keep constantly adjusting our array sequence. But since our display is fairly simple we can store the sequences for each digit, and then choose which digits to display. Each digit is 5 bytes in size and they are placed in an array like this: [[digit0], [digit1], [digit2]… [digit9] ]. Then let’s say we want to choose digit 6, the start index of the sequence for digit 6 is at 5×6 = 30, and the end is at (5×(6+1))-1 = 34.

So how do you figure out how long to display each sequence? Well, I did this by trying a few values and see which one works best considering the range of speeds the Gyro’clock is typically moving at. If the display time is too long, the pixels will get stretched horizontally as you increase the speed. Display time too short, then the pixels will merge together and the display will get squished as you move slower. I found that for the Gyro’clock it wasn’t necessary to do speed correction. In fact trying to correct for the speed introduced too many rounding errors, which caused the display to change in size unpredictably. At the end I settled for a display time of 0.5 ms for each sequence.

When setting the status of each LED for a particular sequence, you can take either the long and hard way or the short and easy way. The long and hard way would be to change the LED states one by one using the Arduino digitalWrite(pin, state) function. By doing it this way the LEDs don’t change state all at once. Although it still happens pretty quickly with a 8 MHz clock speed, it is too much unnecessary work for the processor.

The quick and easy way is to manipulate the ports directly. It would help if you can connect all the LEDs to pins of the same port (port B let’s say). However, because of the external crystal we used for the real time clock module I wasn’t able to put all the LEDs on pins of the same port. So I put LEDs 1-6 on port pins B0-B5 and the seventh LED on port pin C0. With this setup it is easy to update the ports directly as follows:

//num is a byte representing the state of the LEDs 1-7
PORTC |= (num>>6);
PORTB = num;

First by calling PORTC |= (num>>6) we shift our byte 6 units to the right so that the only bit that is left is the 7th bit (and we don’t care about the 8th bit since its always zero and doesn’t represent a LED). Then we change the PORTB values all at the same time. From two quick and direct steps we have changed the state of all 7 LEDs.

That covers the clock display module, which is actually the simplest part of Gyro’clock to implement. And that wraps up the three part series explanation of how the Gyro’clock firmware works. This however, is not the end of the Gyro’clock project. I liked working on this project so much that I actually want to take this to the next step and build a completely practical store-made-quality product. I will tell you more details about this as I work through it. In my next post I will release the firmware for this version of Gyro’clock. Thanks for reading!