This post describes the implementation of dual limit switches on the Openflexure microscope. This particular setup involved the Delta stage, but the actuator designs for both the Delta and the regular stage are very similar, so the information applies to both. In a previous post I described the general idea; to use a small magnet and a magnetic switch IC to make a compact switch which could be retrofitted to the microscope.
I designed a small PCB to hold the three components needed; the chip, a decoupling capacitor and a pullup resistor. The chip comes in an SOT32 package, and I used 0603 size surface mount passives. This is the smallest size I can hand-solder. The design was done using Kicad, and the PCBs were made in a few days by PCBway. I chose 0.5mm thick board, to minimize the depth of the cutouts needed. The boards as supplied were rafted 6 to a board (figure 1). They are easily broken off, but the best way to proceed is to assemble the components while the boards are still in one piece, since it is much easier to hold and work on. The individual boards are 4mm x 9mm, which is actually quite hard to work with. Figure 2 shows an assembled board, together with a micro-SD card for comparison. The Kicad files are on GitHub (GitHub - dpsiddons/limit_switch).
I still haven’t figured out how to modify the main stage SCAD file to accommodate the upper switch, so I hacked on the one I have to cut out a suitable cavity (figure 3). It fits nicely on the inside of the actuator housing, and as I’ll show, the lower one also works nicely facing inwards. That means all of the wiring is out of the way.
I had to think for a while before I came up with a simple procedure for installing the small magnets. They are exceedingly fiddly by themselves, so some kind of holder is needed to glue them to the actuator through the cutout. I eventually settled on the following. First, we need to discover which side of the magnet must face the sensor, since the sensor will only accept one polarity. To do that, I found a large magnet, such as is used to hold things onto refrigerator doors, and brought the sensor board near it, with the sensor facing the magnet, and the sensor powered up. I had rigged it up so it lit an LED when actuated. When the switch is actuated, you have the correct magnet face. Simply drop the small magnet onto this face and it will land right-side up. I then marked the small magnet with a Sharpie dot.
The magnet needs to be attached to the upper end of the actuator arm such that it aligns with the sensor on the PCB. It is easiest to do this with the arm raised to its upper limit, by pushing on the bottom. The arm translates when this is done without the actuator screw. Inserting the screw (without the nut) kept the actuator in the right place, but my screw was quite magnetic, so the small magnet preferred that to the actuator plastic! I replaced the screw with a matchstick and all was good. I guess one should print a suitable tool which would be a better fit than the matchstick, but……
To insert the small magnet onto the actuator, I put it onto a non-magnetic surface, good side up, took a matchstick and smeared the end with the thinnest layer of Vaseline. The magnet will stick to that quite readily (see figure 4). Next I prepared a small amount of Epoxy, and dipped the exposed face of the magnet into it, trying to avoid getting epoxy on the matchstick.
With your hand raising the actuator to its upper limit, insert the matchstick into the opening and press it into contact with the actuator head. The surface tension of the epoxy is greater than the adhesive strength of the vaseline joint so the magnet will stay behind when you remove the matchstick. Figure 5 shows the magnet installed.
Next, the PCB should be glued to the actuator housing, as in figure 6.
I initially just held it in place with my finger, and operated the actuator by hand to be sure the switch would be activated before the end of mechanical motion. Once sure of that, I glued it in place. Since this is still a prototype, I used Duco to hold it rather than epoxy, in case I had to remove it and readjust things.
The lower switch was made simpler by the fact that the foot was a simple (!) SCAD file, and I understood enough to make additional space below the endstop. I was then able to convert the foot STL file into a solid model using FreeCAD, and could then manipulate it using software I knew I made a cutout to hold the PCB and bring the magnet and switch to about a 2mm gap near the end of travel. I knew this was the magic distance from previous experiments. I put in the endstop at the original height so we don’t break hinges if things go wrong. The modified foot (from the Delta stage, so it doesn’t have a tilted geometry) is shown in figure 7.
Next, glue the PCB into the cutout (figure 8). Again, I used Duco in case I needed to change things. The small magnet can be glued to the bottom of the foot in roughly the right place, in a similar manner to that used for the top limit. Ideally there should be a shallow cavity to properly locate it, both here and in the top of the actuator.
The axis can now be assembled with it’s ‘O’ ring as per the microscope instructions, and you’re ready to go (figure 9).
The next question is where to connect the 6 limit switch outputs. My motor setup at the moment is the simple one with separate drivers and a regular Arduino, so the analog inputs A0-A5 are available, and that is what the software expects us to use. None of the Sangaboards has connections for them. Modifying the Sangaboard .v2 to add a connector would be easy. Looking online, I see that the v2 was designed in Eagle CAD, which I don’t use, so I designed a simple board in KiCAD to hold an Arduino Nano, the two driver chips, and a connector for the switches, plus LEDs to tell when the switches are active. I haven’t made it yet, but will do so soon. I didn’t make any attempt to make it fit inside the microscope; maybe I’ll do so later.!
I then made some measurements of the repeatability of the end position. I ran the motor to the endstop, then backed away by a distance at which the switch turns off. The sensor has a significant hysteresis; about 5000 steps on the microscope, so I backed of 6000 steps, then moved forward by 10000 steps, ensuring that I would hit the limit. All of this was done using the serial monitor on the Arduino application, typing in commands. The results are shown below.
Upper switch:
Lower switch: