Adding a 3D printed optical encoder as well

Now that I’ve been successfully using this actuator and wanting to take it further, I hate that I’m running blind on lost steps. If we could control the power to the stepper motor, meaning decrease it to a very weak power, and watch when it loses steps, we’d have edge detection on objects. This would let you push the arm up against stuff, wait until a lost step, and then know you’re touching it.

The challenge has been how to some kind of encoder. There’s magnetic ones, but they all seem to only apply to the shaft. I think we need to measure the reduced output instead. I’ve explored how calipers do it and think that’s a possibility still, but perhaps a 3D printed optical encoder does it?

Here’s a new design I’m trying. I don’t know if it will work. I added 92 slots around the top of the actuator.

The bottom of the actuator has a new slot to receive the top slots. There’s room for two 0805 SMD LED’s. One generates light, while the other receives the light. The receiver LED should generate enough voltage to be detected by the ESP32 when the slot is pass-through, and a lower voltage when the solid plastic is blocking the light path.

Bottom of actuator with slot

I went with 92 slots based on this math. The stepper motor has a 7.5 degree angle, thus 48 steps per rotation. The planetary gear is a 38.4:1 reduction, so 48 * 38.4 = 1843.2 steps for full rotation. Divide by 20 = 92.16. So, each optical high/low represents 20 full steps. I’m running these actuators at 4 microsteps, so 80 microsteps = 1 optical high/low. That means I’d have to lose 20 full steps (or 80 microsteps) before I can really detect slippage, but I think that’s workable.

With the 0.16 shift each rotation I also end up with an error shift the more full rotations that occur, but in practice, I presume I won’t be rotating more than 360 degrees on an ongoing basis, so that error may not matter in practice.

Here’s the mini PCB with the LED. I may not need the resistor if I run this using the LEDC hardware on ESP32 where you get to control the brightness of the LED via freq/duty. For the input LED I’ll try to feed into the pulse counter hardware on ESP32 so I have barely any load on the CPU.

The PCB’s slide into the bottom of the bottom like in this shot.

Doing the 3D prints today and the mini PCB’s. Let’s see how it goes.

2 Likes

Printing a new bottom of actuator with slots for LEDs.

Milling the LED PCB’s to fit inside the slots. One needs a resistor, the other one doesn’t.

How the LED PCB’s fit into the slots.

Getting about a 2mV delta between light passing through hole and light being blocked.

Now, what is the best way to translate the 2mV to a TTL signal to ESP32? Opamp? Transistor? I’ve never built a circuit like that before, so this is new territory. I don’t think the ADC on the ESP32 will be able to cleanly detect such a low voltage change.

1 Like

Well, opamp is what comes to my mind. Do you have room on the board?

Can’t find an 0805 photodiode to match?

Yeah, now that you say that, I should look at whether just a basic 0805 photo diode works better. I don’t have any in that size, but I’ll order some. Maybe that makes the voltage detection way easier.

Photo interrupters can be pretty temperamental.
The key is to get a sharp edge transitions which usually dictates a schmidt trigger somewhere in the circuit with clean aperture edges.

image
I wonder if the 3D printed slot will be noisy do to perturbations at the edges?

I assume that none of these interrupters are small enough to fit in the ring? Would be nice if you could as they have all of the electronics on board and the plastic is filtered etc etc. I know that they make some pretty small ones that go into disk drives.

https://www.digikey.com/products/en/sensors-transducers/optical-sensors-photointerrupters-slot-type-logic-output/547

I would start out with an IR led and IR phototransistor rigged up just like an opto interrupter.
This is a 5V logic circuit but shows the concept.

image

1 Like

Awesome write up. I looked further at photo interrupters and found this compelling one https://datasheet.lcsc.com/szlcsc/1909251104_Sharp-Microelectronics-GP1S196HCZ0F_C394682.pdf

It’s about the size I need, albeit the slot is 1.1mm and I made the slots on the actuator be 1.5mm thick, so will have to squeeze that down. I’d still need to assemble the opamp and look at adding a schmitt trigger.


I had some photo interrupter boards lying around and they seem to only have the opamp on them without a schmitt and they’re not seemingly noisy with the actuator slots when i test run them based on how the LED blinks, so perhaps it’s not necessary. I was just holding it in my hand so it wasn’t a very good test. I did have to add black sharpie marker to inside/outside of slots to get the LED to blink on the detector though, so that was interesting.

You should be able to get a “digital one” one with the Schmidt trigger built in and an open collector output.
In this case a pull-up resistor from the collector of the photo-transistor to your VCC (3.3V) and you should be good to go.

If not try a pull-up on the photo-transistor collector to VCC and then input that to a logic Schmidt trigger [74HC14].
With this schema you can connect the photo-tranisistors collector and ground remote to a breakout board with the 74HC14 on it.

You need strong contrast between open and closed apertures. If you have a problem with that you could try painting a reflective paint on the surface. Careful that the sensor does not look through the plastic, IR can sometimes penetrate the plastic.

I doubt if you could see the effect of no Schmidt trigger without a dynamic test, then again you may not need it ;).
I would put the output of the sensor on a scope with stepper running and look at the dc offset, pulse width and the edge transitions.
Its not a bad idea from a noise immunity perspective to have a Schmidt trigger device on the processors input from sensors anyway.

2 Likes

Ok, cool idea. I took a look at different photo interrupters and there are not many choices that will run at 3.3v that include the schmidt trigger and are the small size I’m after. There are some without the schmidt. The ESP32 does have a pulse counter that also includes a filter where the signal has to stay low or high for a set period of time before it registers as a pulse and then you can get a callback to your code, so it sort of does signal smoothing for you without extra hardware. So, I think I’ll try a few different options out and see what comes of it. I’m really looking for about a 1.5mm slot width and a beam that’s less than 0.6mm. That does give a smaller subset of options out there, but not too bad.

1 Like

Hi John, hello everyone,

First, please let me give you all my congratulations for this great iterative design you’ve made on this rotative modular actuator. It’s honestly a really nice work, and a great sharing to the community.

I see that you now try to improve the last version with some close loop control, and i was just wondering if you evaluated the technical solution of using something similar to the SERVO42 / nano_stepper / smart stepper open source initiatives: Instead of controlling the output of the flexible gear reduction, it directly controls the motor rotation.

just wondering :wink:

Hmm, I had not heard of those projects, so thank you for sharing them. They look pretty cool. Some of the problems I see are:

  1. Trying to base this on ESP32 so you have high processor speed, dual CPU, touch sensors, pulse counters, WiFi, Bluetooth, deep sleep, etc with super cheap cost. Those projects aren’t built for that hardware.
  2. Trying to make extending this super easy by using Lua code as the way everything is built.
  3. Can’t use the magnetic rotary position encoders due to the design of the actuator. There’s no good way to be on a center axis with a magnet unless you have a dual shaft stepper motor, which are near impossible to find on small steppers.

It may be possible to do item 3 still by gluing a magnet to the tiny bit of the bottom of the shaft sticking out of some of the steppers, but alternate approaches like optical encoders may do the trick. Not totally sure yet. I do like the idea of absolute position rather than relative position, and have not found a good way to achieve that yet.

You’re absolutely right on those 3 points. I though it was a good idea to let you know that solution existed.
Regarding the relative vs absolute, both solutions (including the optical encoder) are also measuring a relative position.
Those project were made for high speed control with no reduction in order not to lose any steps, and apparently works quite well. A lower speed and resolution (as there is a strong reduction after the motor stage in the case of your actuator) would not need such big cpu needs.
Maybe a magnet on the output rotating stage would be a good way to go too. Just thinking out loud :wink: