An Electronic Lead Screw controller using a Teensy 4.1

Yes, indeed. The devil is in those very details.

Had a working system for a while, then mucked it up. Why? Because I was ad hoc adding stuff, rather than having it thought out in the beginning. Before you know it, you box yourself in! So it was time to step back and think through the executive level stuff more fully. I have to pry some parts out and rearrange things, but it will get there...
Like most stuff, it usually takes a prototype to work out the issues, and a second pass to get it right. My personal approach is that you'll spend more time trying to design it correctly in abstraction than going through the ad-hoc/prototype iteration. We used to call the attempt to design it 100% right in abstraction "analysis paralysis".
 
With a full staff, it used to take 9-12 months to make a new automotive radar. It took me 9 months of software development starting from scratch to make my own fully functional and usable radar chronometer at home. That included 3 attempts at the analog front end and a whole lot of floundering learning how to use the ADC with DMA.

It wouldn't surprise me that it takes about 4-6 months to do this. I started in early May. Bought the Teensy on May 3rd. At that time, I had no idea what was involved. The design has matured since then. :) That's a fancy way of saying there has been some software prototyping happening. There's also been some scope creep. It is important to state (in a project) how it ought to work and what actions cause a transition. If you don't know that, then you won't know what to code. I need to write that sort of thing down so there are clear goal posts, else it morphs on me!

For me, coding isn't that hard, it is just a task to do, and I learn stuff if necessary. The hard bit is knowing what you should be doing and in what sequence. I call it the executive level thinking. So as simple as my description of the states was above, I will use the description to make sure that I implement my code correctly. If it proves unwieldy, I'll change it. It's just a tool, and it can be modified as required.
 
Made some progress today. Have the feeding and threading menus working 95% right. Have a couple of minor things left, but significant stuff got done. Had to put on some sound cancelling headphones so I wouldn't get distracted by anything. When floundering around, any distraction seems a lot more pleasurable than figuring out your own stupid coding issues! So I reduced the distractions, and got a lot further along. Was able to follow my own guidelines (above) and make my code conform to it. The floorplan (game plan) sure made it easier to get the code under control.

One silly thing that I got hung up on was displaying the feed. For imperial, we want to show the feed in inches, not TPI. For metric we want to show the pitch. Basically both are pitch. Which is different from threading, where the convention is TPI (1/pitch) for imperial and pitch in metric. So had to modify some functions to be "feed-aware". Another classic programming bug - which caused my Teensy to reset and otherwise misbehave, was addressing off the end of an array. That didn't work so well!

So enough progress to bump the revision! :cool:

Next I need to grey out some options until they are selectable. It's not necessary, but it makes the interface more intuitive.

After that, I am pretty much at the point of stopping coding for a bit. Then I have to figure out how the installation and figure out the real ratios. Currently don't have much of an idea of how to mount things and what gears or pulleys I need. Once I figure that out, I need to design up the mechanical elements and make them! Looking forward to that.
PXL_20220724_230339561.jpgPXL_20220724_230430471.jpg
 
Just started looking at my lathe and trying to figure out how to hook up my stuff. Think I will attempt to mount the stepper inside the base. I will check if it will fit - it looks like it could be cozy there! I will need to find or make a pulley that has some offset. The motor shaft is 20mm long, with a 15mm flat, but the lead screw sticks out 25mm from the casting. Have to work up some more detailed drawings - just to know what to look for.

The spindle has a M1.5 40T gear, followed by a 60T gear. One option is just a M1.5 40T. However, that is a little large. I would need to mount it 75mm away from the 60T gear. This shaft has also has a M1 gear mounted to it, which would make things easier, I think. Think I can find a 60/40 pair in M1. That should bring the shaft to encoder distance to 50mm, which might be easier to implement. It does require 2 gears, but I already have those gears in my gear set. I think that should get me back to a 1:1 with the spindle... Actually any gear could go on the shaft. It would be an idler? 40T 27T 40T? Not quite sure when changing module on the same shaft, need to think about this.
 
The harder part of the project - fitting it all into the lathe.

Looks like the Teensy 4.1's are in stock again. Were they always $31.50? Seems like they have gone up.

Ordered my first Pico W for $6.00 (the one that has Wifi). Don't plan to use wifi for my electronic leadscrew, but with today's market want to have it on hand for some future project.
 
Last edited:
The harder part of the project - fitting it all into the lathe.

Looks like the Teensy 4.1's are in stock again. Were they always $31.50? Seems like they have gone up.

Ordered my first Pico W for $6.00 (the one that has Wifi). Don't plan to use wifi for my electronic leadscrew, but with today's market want to have it on hand for some future project.
My first Teensy 4.1 was in the low $20's. Thanks to chip shortages they have gone way up. I have 3 of them, the latter ones were $31.50 or so.

Also have in my hands a couple of Pico's and a single Pico W. Have installed the Philhower core, but haven't programmed any yet. If I were starting over again, I'd use either a Pico W, or one of the ESP32's with dual core. Not that the Teensy isn't very capable, but, the Picos and ESP32's are pretty darned cheap.

It looks like the stepper will fit inside the hollow of the casting of the ways under the headstock. Was able to wiggle it in place without much trouble. There is a bit of what I'd call casting flash there. It won't be hard to file or grind away, although the physical access is awkward do to my shop arrangement. Need to increase the casting opening height by about 5-10mm. The width appears fine. Then I could mount the motor to a plate and bolt it on to the casting from the outside.

The timing pulley for the stepper needs to have about a 25mm boss on it to get it to align with the lead screw. I will have to search for something that will work. In a perfect world, it would have a 10mm bore. The lead screw timing pulley needs to have a 14mm bore, but it doesn't need a boss.

Still pondering the mount for the encoder. There I need to have a 5mm to 14mm shaft adapter, so I can attach the 40T gear. Also need to attach the assembly to the upper casting. Have to work that all out.
 
I just looked at prices on the Teensy 4.0's that I bought years ago, compared to now they have gone up about 15%, not too bad (from 20 to 23 dollars). I never bought any 4.1's so I don't have comparative numbers.

My first "Pico W" is in the mail, order limit 1 but they seem to be available. The non-W's are available in large quantity, I have a few of those. Dual cores plus the 8 PIO sub-processors give them a lot of potential.

I've done a little with ESP32's and the documentation on the Pico is better than what I was able to find on the ESP stuff, and the extreme cloning makes it worse. The Pico libraries are still very new. I hit what seem to be bugs in both the ESP32 and the Pico, but I have more hope the Pico stuff will get fixed. I'll wait a bit longer before I get back to it. I do have a new gear to replace the incorrect one on the lathe, perhaps then I can map out all the gear ratios. I stopped when I found the one tooth off gear error.

Mounting the motor and encoder is going to be a problem on my lathe. It has a 3 year warranty... So I may not be in a rush there at all.
 
Mounting the motor and encoder is going to be a problem on my lathe. It has a 3 year warranty... So I may not be in a rush there at all.
Seems like you have done a lot of work already, to sit on your hands. If it was me, I'd be modifying the lathe. But that's your call.

Since my lathe is second hand, I have no compunction about drilling holes in my cross slide to make it better. I made a new lathe compound clamp and it needed 4 more holes in my cross slide. So I drilled 4 holes and tapped them to M8. Voila, a vastly better compound clamp than stock was enabled. I machined a new compound clamp and bolted it to the cross slide. A few holes here and there, if done well, won't hurt the lathe one bit. In my opinion, adding an ELS will make it a lot better than it is now. Can't think of anything that I am doing that is irreversible, save for the tapped holes. Even those holes can be plugged and painted...
 
…A few holes here and there, if done well, won't hurt the lathe one bit. In my opinion, adding an ELS will make it a lot better than it is now. ...

I agree and look forward to your mechanical integration. :)
 
Back
Top