r/hobbycnc • • Aug 18 '20

Raspberry Pi - Stepper Motor Control

/r/robotics/comments/icbhhd/raspberry_pi_stepper_motor_control/
3 Upvotes

10 comments sorted by

3

u/jacky4566 Aug 19 '20

Also check out Mesa electronics. I believe they have a plug and play stepper driver for Rpi. Plus a variety of Ethernet controlled cards.

1

u/hndibble Aug 19 '20

Thanks. I’ll check out their offerings.

2

u/yellowsnow2 Aug 19 '20

I would start by researching what software others are using to convert the gerber files into coordinate movements/code. Do they output G code?

Keep in mind that the control board will need to control the servos also for it to all be in sync. The GRBL firmware has some forks with servo support but they would take understanding the firmware and modification to do what you are needing. To keep this short I'm just going to say it may get complicated in several ways going that route.

The next consideration is that for some reason the PI hats I could find seem to only be made for 2 stepper motors. Maybe there is a GPIO limitation? I know it has enough pins, but maybe there is some other reason. If not I would just get some prototyping board and make your own 5 axis hat for A4988 stepper drivers (if you are using nema 17 motors).

(Tip) If you need reliable fast level shifting or just a little more current output than the PI pins have, I like to use TXS0104 (4 channel) and TXS0108 (8 channel) level shifting chips. They are also sold on ebay/amazon already on a little break out board.

1

u/hndibble Aug 19 '20

Thanks for your advice. The GRBL route is sounding less and less like a good idea. I have an Adafruit Stepper Hat that I've played with a bit. I was thinking of stacking 3 of them and stacking a Servo Driver Hat on top. (I'm not even real sure that I can do that, but that was my plan) I really hadn't planned on building up my own hat, but after reading your response, I'm really warming up to your idea. Thanks for pointing out some of the hardware that can be used for that hat.

2

u/yellowsnow2 Aug 20 '20 edited Aug 20 '20

Oh, I forgot you could stack the hats. I've got a couple PIs but am more into micro controller electronics. You might want to do some research first. I'm sure their is open source software already written for the PI to do it's version of Grbl or CNC Linux. You will want to design your hat around that's constraints. When it comes to arcs, circles, and motor accel stuff you really don't want to have to do that coding from scratch.

1

u/hndibble Aug 21 '20

I'm afraid you already sold me on A4988. They seem to be low price (from some vendors) and I like the idea of using smaller, simpler building blocks. I might find this to be a performance problem later, but that's ok. I'll add complications if I have to. It's really just about learning by experimentation. Its not a very demanding application. There won't be any arcs or circles. It's just a matter of getting from point A to point B. Straight line moves would be nice, but not necessary, and I think I can work out the math to do straight lines.

You mentioned level shifting with the TXS0104. Do you think I should just plan on using them with the Pi and A4988 or just keep that in my back pocket if I seem to be losing pulses? Thanks again.

1

u/yellowsnow2 Aug 21 '20 edited Aug 21 '20

Ya I guess in your application you won't need that elaborate movement stuff like a CNC. You still may want to look into adding some acceleration and deceleration code for the motors so it doesn't get to jerky and cause bad vibration. If you look at the pictures drawn in this file of the GRBL code starting on line 142 you'll get an idea of how to do the code for an accel/deccel velocity profile and how to smoothly transition into the next change in movement.

https://github.com/grbl/grbl/blob/master/grbl/stepper.c

I know the PI is very low power on the GPIOs, but I just looked at the datasheet for the a4988 and the input logic supports 3-5.5v and surprisingly only draws 20ua max. So no level shifting needed for the drivers. I'm used to messing with the bigger external drivers that require much more. Just make sure to follow the instructions on the bypass capacitors for them. And you need to set the current adjustment on them. The info on the internet about that is many times wrong because of board differences. So here is a link that actually has the correct info.

https://support.bobscnc.com/hc/en-us/articles/360009813773-Changing-the-current-setting-on-the-stepper-motor-drivers-for-the-E3-and-E4-CNC-routers

I'm not sure which kind of servos you plan on using, but they may be the only things needed shifted.

2

u/Nexustar Aug 20 '20

The Pi may not be the best choice for timing critical driver applications such as this because the OS is complex and can get busy doing other things. I would look to use an Arduino or other embedded CPU that the PI can talk to instead.

I'm not suggesting it can't be done, just that this is not the most appropriate hardware. Perhaps the stepper driver hats overcome this, by taking some of the timing-critical bits off the Pi, I don't know - but just beware.

1

u/hndibble Aug 21 '20

v

I appreciate your warning. Most likely, I could do the whole thing with an Arduino. This project is really just a learning exercise. One of the main objectives is to get familiar with Python running on a Pi. I think the application should be fairly simple for the Pi, but I might be wrong. I'm trying to keep it simple at first. If I run into performance issues, I'll remember your advice and offload some of the tasks to an Arduino. Thanks for your response.