A little detail many CNC or 3D printer devices minimize is the endstop – what the device does when it runs out to its maximum travel.
For the Audrey Braille device, I’ve been working with a photo sensor which detects when its infrared light beam is interrupted. As I mentioned recently, the device can be wired together using two resistors and three wires (power/ground/signal).
Of course, the endstops for the Braille device are different than for a CNC device; for example, the latter requires three or six identical endstop switches, one for each axis of motion, and ideally two per axis (why two? I’ll get to that momentarily).
In the Braille device, I’m using 1 or 2 switches for the left/right travel, but two others for forward/backward travel – because of the space constraints, these are very small mouse button switches I got off eBay and use to detect when the device has moved the pin too far. They work by holding a lever in place that the bottom of the rod moves against when pulled too far. This lever presses against the mouse button, signalling a ‘hit’. At this point, the motor must reverse and send the rod in the other direction. This end of the rod detection is used at device powerup to confirm the position of each rod – just move each one forward until the switch engages, then move back to a known valid position.
Likewise, the sensors for left/right need to cope with initialization. We need to make sure the left/right position of the head is a at a known position, the ‘home’ position, which is just past the left sensor. From there, the device can figure out how to move.
As the device powers up, the signal sent by these switches can be in either of two states: end detected, or not (which means the main gear is somewhere in the middle of travel. To get to a known good position, do the following:
- If the left (start) end switch has been turned on (we’ve ‘hit’ the left side), move to the right until the switch just turns off.
- If the right end has been reached, or we are in the middle (left switch off), keep moving left until the left switch activates; then back off right until it just turns off (the previous step in this list).
As you can see, the coding is very easy when there is both a left and a right endstop switch (or for a CNC, two switches per direction/axis). The problem for me is that I’ve been hoping to get by on one combined sensor for left/right, which makes the coding far more complicated:
- If no sensor is active, move left until that sensor is reached/activated; then back off right until it turns off again (so far, so good).
- If the sensor IS active, it could be the left or right side has been reached. One way to solve this is to move a little bit left, then a little more right, then a little more left, and increasing the distance slowly until the sensor turns off. If it happened when traveling left, then we know we were against the right side, so we can now move to the far left, and position properly. If it was while traveling right, then we’re at the far left, and can stop, since we’re positioned just past the left sensor.
The code is more complicated with a single sensor. Also, the chance of damage is higher, since if you’re flush left, for example, you might bang against the side of the compartment several times before the right motion gets you out into the ‘safe’ part of the travel.
The result? Two sensors makes for easier programming, and reduced wear. And while I’m still a fan of opto sensors, I may move to microswitches for this design. After all, they are reliable, cheap on eBay (I can get micro switches with levers online for 30-50 cents in bulk), and require less wiring. Unlike the three wires needed for the optos, a switch needs only the a +5v line and the signal line – the pulldown resistor for the switch can stay close to the Arduino side of things, with only two wires actually running out (for an explanation of switching, see this Arduino switch tutorial).
Is this the ultimate solution? Not necessarily. After all, you can still get by with one switch in any travel direction if you’re prepared to monitor your position carefully. For example, if I initialize my left/right by ONLY moving left on startup (that is, until the left switch is depressed), then I can safely leave off the right switch. But if for any reason my device loses its place and travels too far right, there will be no way for it to understand the problem and stop – it will just try to keep traveling, possibly damaging components. To avoid this, I could make sure I reset my left position frequently, ideally as the head returns after each line of text is displayed; since this happens frequently, it might be the way I’ll go. However, on the forward/backward travel this is a little more complicated – if I only use one sensor (say, forward) then I risk going too far backward if my code loses its place, potentially damaging the rods. With two switches, I trade safety for code complexity, a tradeoff I like in this case.
And for CNC devices, you can see the benefit of 2 switches per axis: imagine a router getting confused and going too far – would you rather the blade tries to ‘escape’ the CNC boundaries (and maybe carving up part of the frame in the process), or the extra safety switch catching the mistake? So extra switches protect against errant glitches, with less damage if the software isn’t perfect – not that that could ever happen!