Sunday, May 11, 2014

Building a Headerless Programmer

In my previous post, I talked about a circuit board that uses force-sensitive resistors as end stop detectors. This board has an Atmel ATTiny861 microcontroller that needs to be programmed. For the first few boards that I made, I soldered headers in place. This works just fine, but I wanted to see if I could use pogo pins that I purchased form Sparkfun to create a programmer that doesn’t require the header pins.

For this project I needed six pogo pins, one 2x3 pin header, and some ribbon cable that I pulled apart so I could have six wires, each with a different color. I 3D printed parts to build the jig, which are shown below using “clear” PLA filament.

First I soldered the wires to the 2x3 pin header, and then pushed it into place. Next I soldered the wires to the bottom of the pogo pins, after I’d inserted the pogo pins into the 1.6mm holes in the jig:

OLYMPUS DIGITAL CAMERA

I was concerned about the possibility of shorts, so I added short pieces of heat-shrink tubing to the very end. Since building this, I read somewhere that these pogo pins will fit directly into a female header—that would have been a lot easier.

Here is what the jig looks like when finished. You can see the six pogo pins sticking out the top, and the programmer cable hooked up to the 3x2 pin header:

OLYMPUS DIGITAL CAMERA

Finally, this is what it looks like in use. I hold the board in place (there are two alignment pins) while I click the button the upload the program to the board.

OLYMPUS DIGITAL CAMERA

While this works very well, it was more work to build than I would have liked. As I mentioned, using a 3x2 pin female header would have been al lot easier, and I’ll use that approach if I build another programmer.

Sunday, May 4, 2014

Auto Adjust FSR End Stop Detector

I really like using FSRs (force-sensitive resistors) for detecting when the nozzle of the 3D printer touches the print bed. They can be very sensitive, and therefore very precise. What I didn’t like was how difficult it was to get them just right. Wouldn’t it be great if you could plug them into a tiny circuit board and just have them work?

I decided to see if I could build a circuit board that would make it really easy and reliable to use FSRs. Here are the goals I set:

  • Automatically adjust to the weight of the print bed without requiring any configuration or adjustment—they should just work
  • Have an LED for each FSR to show when that FSR “triggers”
  • Connect directly to the end stop pins on most 3D printer boards
  • Be self powered from the end stop
  • Make it open source: https://github.com/JohnSL/FSR_Endstop

Designing the Circuit Board

With the help of my friend Stephen, we designed a circuit board in CadSoft Eagle (that means we designed the circuit together, and then I watched and ask questions as he designed the circuit board in Eagle). It took him about an hour to design the following circuit board:

Rev 1

We then created a set of Gerber files and sent them off to OSH Park to have some actual PCBs made. I ordered 12 PCBs and the total charge was about $26, including shipping. That’s a really great deal. The lead time to get these was about two weeks. By the way, there’s a small design flaw in this circuit board if you want to see if you can find it (click on the image to enlarge it). I’ll describe the flaw later.

This circuit board uses an Atmel ATTiny461 microcontroller, which is in the same family as most Arduino boards. What that meant is I could use a standard Arduino to write some firmware to test out my ideas while I waited for the circuit boards arrived. This is where being a software developer by day really helps. It didn’t take me very long to write and test some code. I only tested a single FSR because, at this point, I’d sold my 3DR “Simple” Delta printer to a person at work, and I haven’t finished designing my next delta. I have two other 3D printers, so I wasn’t really using my delta anyway.

Soldering Parts in Place

Two weeks later, I got the circuit boards in the mail, and they’re really nice! The next step was to learn how to solder the tiny SMD (surface mound device) components onto the board. Many of the components are what’s know as 0603s, which means they’re 0.06 inches by 0.03 inches (or 1/16 by 1/32). That’s really tiny, and smaller than I can see well without some magnification. I have a microscope that I first got to inspect the injection molds that I was milling, so I decided to use that for soldering the parts on.

Hand soldering SMDs turned out to be a lot easier than I expected. The key to success it to use flux (I used liquid flux) and a small soldering iron tip. My tip is nothing special, being about 0.05” in diameter at the end.

After applying the flux, I would add just a dab of solder to the very end of the tip, and then touch it briefly to the end of the part to be soldered while holding the part down with the tip of some tweezers. Here is what my hand-soldered board looked like when I was almost finished:

OLYMPUS DIGITAL CAMERA

On the right side, near the bottom, I have two black diodes soldered in place. These diodes form a bridge rectifier, which allows me to provide power to the entire board from the two pins below labeled +/- that come from the end stop connector on the printer board. Most printer boards have three wires: signal, 5V and ground. However there is no standard for the order of 5V and ground, so using a bridge rectifier allows using either polarity of connection, at the slight loss of some voltage. In other words, this means everything runs at about 4V instead of the input 5V, which is no problem for this microcontroller, as it can operate down to about 1.8V.

The diodes, however, drove me crazy. Most of the SMDs have metal pads on the bottom that warp around to the ends, making them easy to solder. These diodes, on the other hand, only have metal pads on the bottom. I somehow managed to solder two in place. However there wasn’t enough clearance for me to solder the other two in place. Fortunately, the Garage at work has a hot air solder rework station, so I was able to use it, along with some solder paste, to solder the other two diodes in place. For those of you familiar with circuits, you’re probably wondering why we didn’t use a bridge rectifier chip, which would have been much easier to solder in place. The answer is that my friend Stephen had all these components on hand, so we used what he had. I’ve since changed the design to use a single chip instead of four diodes, but I haven’t ordered test boards yet.

Programming and Testing the Circuit Board

After I finished the first circuit board, it was time to program and test the circuit board. Programming turned out to be a little more difficult than I expected because I ran into an issue with uploading the firmware. But first, I’ll describe the setup. Stephen included a programming header in the design (at the bottom left in the photo above) so I could hook this board up to a USB programmer. I used the Pocket AVR Programmer from Sparkfun because this was my first experience programming the chip on a custom circuit board, and this programmer looked good.

WP_20140504_10_14_37_Pro_600

I chose to write my code using Arduino, so I needed to a way to target the ATTiny861 microcontroller. Fortunately, someone already figured out how to do this, so I used the ATTinyCore on GitHub to setup my environment so I could write code for this chip. then I could just upload the code and be done, or at least so I thought.

I kept getting validation errors. Sometimes uploading would succeed, but only rarely. After trying lots of things, and searching the web, I downloaded WinAVR because something I read gave me the ide it might be helpful. This download include a newer copy of a program called avrdude that is used by Arduino to upload firmware. I turned out verbose reporting in Arduino, found the call to avrdude and then tried this with the newer version of avrdude—it worked perfectly every time. Copying this newer version of avrdude on top of the old version in the Arduino folder fixed the problem. Now I can successfully upload changes every single time. I have no idea why I had problems with the older version, but I found something that work. If anyone knows more, please send me a note.

Now it was time to test on a printer, rather than at my workbench. I asked one of my fellow Garage members if I could try it on his printer. So Dave brought his printer in last Thursday and we gave it a try using my very first circuit board. And it work really well. Here is a video of my very first test:

Very first test of the FSR Endstop Detector circuit board on a Kossel Mini

When you watch the video, notice that the number of FSRs being triggered varies from one to three, depending on where the nozzle touches the surface. Also, you can’t see it in the video, but there is a fourth LED that is green and is on most of the time. I had originally planned to have five LEDs: three for the FSR triggers, one for the combined trigger, and one for power on. But I forgot to include the power on LED. Part way through writing the firmware, I suddenly realized I could change the output LED to be on most of the time, and turn off only when triggered. So now I don’t need that extra LED.

Making more Boards

After my experience trying to solder the first circuit board by hand, I decided to try another approach. In a moment of weakness, I purchased a very cheap ($200) reflow oven from eBay. This oven was less than half the cost of a good one, and after I clicked the buy button I did some research and found lots of negative reviews. Woops. In any event, it was on the way, so I decided to give it a try.

For my first attempt, I used the syringe needle that came with the tube of solder paste to dab solder onto the pads. The syringe was a lot bigger than the pads, so I had problems getting just the right amount of solder paste to stick. Once I had all the parts placed, I put the board in the oven and set it to profile 1. After about 8 minutes, I pulled the board out and much of the solder had not melted. Hmmm, not what I expected. I then checked the solder paste I was using carefully and noticed it was lead-free solder, which melts at a higher temperature. I changed to profile 3 and tried again—this time it came out perfect.

WP_20140427_19_33_11_600

WP_20140427_19_33_23_Cropped

The main problem I have with this reflow oven is the smell. From what I’ve read, they use a lot of masking tape inside, and this gets hot enough during use to off gas quite badly. I’m either going to build a hood and exhaust the fumes to the outside, or do what one blogger suggested and replace the masking tape with Kapton tape.

Using a Solder Stencil

I had read about using solder paste with a stencil and it sounded a lot easier than using the syringe to apply paste, so I thought I’d give it a try. Eagle already had all the for a solder stencil, and you can output this as an EPS file (Encapsulated PostScript), which is a file format that Corel Draw can easily read. I opened the file in Corel and then changed the pads so they would have a hairline black outline and no fill. Then I cut a stencil from some 5mil Mylar, and I also cut a jig for holding the circuit board in place:

OLYMPUS DIGITAL CAMERA

The jig is made from 1/16” thick museum board, which is basically poster board. I scored a line on the left side to show where the edge of the Mylar stencil should be attach, and I’ve taped the stencil to the museum board.

I spread some solder paste onto the left side and then used a palette knife to scrape the paste through the holes. Here is the result:

OLYMPUS DIGITAL CAMERA

Or zoomed into a small part of this board:

OLYMPUS DIGITAL CAMERA

In this picture you can see the small “mounds” of solder paste that were applied with this method. I’m really amazed at how well this worked. It’s much easier and faster than applying paste by hand, and the results are a lot more consistent. Next, here is the same area with parts place, ready to put into the oven:

OLYMPUS DIGITAL CAMERA

And after about 10 minutes in the oven, everything is soldered in place:

OLYMPUS DIGITAL CAMERA

The Design Flaw

Here is nearly finished circuit board:

OLYMPUS DIGITAL CAMERA

Isn’t that beautiful! All that’s left is to solder header in place for the three FSRs, for the end stop, and for programming. And, fix the design flaw.

So what is the design flaw? You can see it here:

OLYMPUS DIGITAL CAMERA

In the very middle of this photo, there is a trace missing. LED4 and R4 are supposed to be connected, but they’re not. Fortunately, this is very easy to fix by adding a blob of solder to bridge the two devices.

Availability and Future Plans

I’ve made the design files and source code open source, and you can find them on Github: https://github.com/JohnSL/FSR_Endstop

As I mentioned above, I changed the design to replace the four diodes with a single bridge rectifier chip, which makes hand-soldering much easier. I will be ordering some of these boards soon for testing. Once I’ve verified that everything works well, I’ll upload the Gerber files, which you can then use to order circuit boards directly from OSH Park or anywhere else you choose.

FSR Bed Leveling Trials and Tribulations

I read Johann’s post about using force-sensitive resisters (FSR) for automatic bed leveling, and it seemed like just what I was looking for. Very simple, and not that expensive. So I ordered a set of three FSR sensors. Here are some places where you can order them:

https://www.sparkfun.com/products/9375
http://www.phidgets.com/products.php?product_id=3104

And this is what one looks like out of the bag:

I connected three of these in parallel into a single end stop input on the Printrboard and gave it a try. Well, it wasn’t as easy as I thought. It turns out the setup was very fussy. Sometimes it took too much pressure to trigger. And at other times it stayed triggered. After a number of attempts, I read the data sheet and discovered that the resistance changes greatly. In the “useful” range of the sensor, the resistance goes from 30 k Ohms at 20 grams to just above 1 k Ohm at 1 Kg. That’s a pretty wide range, and it turns out the weight of the glass bed is enough to change the resistance noticeably. After a lot of experimentation, here is what I ended up with:

WP_20140327_20_17_17_Pro_600

The small squares on each FSR are thin pieces of paper. Without these squares, it took too much force to trigger the endstop. The FSR have a border around the outside that is ever so slightly thicker than the sensor itself, so you need either some spongy tape that can deform, or something like these pads. With the pads, however, I still had issues with it being hard to get just right. My solution was to add a 10K potentiometer into the circuit, as shown here:

WP_20140327_20_18_26_Pro_Cropped

In this photo, the end stop connector is in the center top (it’s the black connector next to the row of white connectors). With this change I was able to get things to work reasonably well, but it still felt too fussy to me.

As it turns out, I was also becoming interested in learning how to make circuit boards and decided to see if I could make a custom circuit board that would make this a whole lot easier. I’ll cover this journey in a future blog post.