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.

9 comments:

  1. I hope you offer populated boards for sale at some point. I'd be interested in them!

    ReplyDelete
    Replies
    1. Thanks. I have no plans to offer boards myself. However I'm planning on going to MakerFaire this month, and I'm hoping I might find somewhere while I'm there who is interested in making the boards. I had a hobby business once before and learned my lesson. This is a hobby, and I want to keep it fun.

      Delete
  2. Awesome, John! I did mine with the ATtiny85 with wire wrapping, but I love your PCB design!

    ReplyDelete
  3. Very nice work!

    Any reason you can think of that I wouldn't be able to port this code to a Trinket? I would remove the individual LED flashing, of course, and just use the one onboard the Trinket. Just curious.

    ReplyDelete
  4. Excellent work and nice write-up!

    One point of caution: The bridge rectifier you're using keeps your device's logic ground one voltage drop above the ground of the system you attach the device to. On some devices this could lead to trouble detecting a low level reliably, as the low voltage is rather high. I just checked for my BeBoPr boards: The Schmitt-Trigger inputs have a negative going threshold of at least 1.0 Volt, so I don't expect a problem there. Make sure to verify this if you're using other hardware!

    It's not completely clear to me how you've made the stencil. If you can't or don't want to do this yourself, have a look here for cheap mylar stencils: http://www.oshstencils.com.

    -- Bas

    ReplyDelete
  5. Hi

    I downloaded and installed ATTinyCore as you have suggested.
    My arduino-0023 sees me only two Bord available:

    ATtiny861 @ 1 MHz (internal oscillator; BOD disabled)
    ATtiny861 @ 18.432 MHz (external oscillator; BOD disabled)

    Which is correct? 1 MHz?

    Regard
    Drake

    ReplyDelete
  6. John, I've been using the manufactured boards on my deltas (5 of them) and they are great. There is gathering interest in using FSRs on Cartesian printers. I have a Taz and am investigating how best to do this. Ideally, you'd want 3 points of contact (3 FSRs) as that defines a plane, but with a square or rectangular build plate, that leaves 2 corners "overhanging" with quite a lot of area. I have not tried it so this is theoretical but it seems that a touch on one of these corners would trigger 2 FSRs and lift the one opposite - not good. So maybe a 4 FSR setup with one at each corner is needed. Hence my post here! How difficult would it be to prototype a version of this that has inputs for 4 FSRs?

    cheers,
    Michael

    ReplyDelete
  7. Awesome...you can upload the gerbers to OSHStencils and get some rather awesome stencils made for cheap as well...

    ReplyDelete