mushroom glue
Posts: 14
Joined: Sun Oct 14, 2012 8:24 am

CNC

Thu Sep 12, 2013 8:52 am

Is it possible to arrange a raspberry pi to drive a set of stepper controllers directly, to form part of a CNC machine, and run the G-code interpreter etc. and something like octoprint on the raspberry pi? There seems to be CNC-related projects like octoprint, but all of them seem to use external CNC controllers, and simply take the place of a desktop. Seeing as the Pi's got a bunch of GPIO pins, shouldn't it be possible to use these to directly control the stepper drivers, cutting out the microcontrollers etc.
Is this doable, or are the GPIO pins not capable?


mushroom glue
Posts: 14
Joined: Sun Oct 14, 2012 8:24 am

Re: CNC

Thu Sep 12, 2013 1:48 pm

Hi
I'd had a bit of a look, but hadn't spotted anything that gave a decently clear answer.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: CNC

Thu Sep 12, 2013 2:16 pm

In theory the raspi's GPIO pins can drive the stepper controllers, if you are capable of generating all the steps for each motion, simultaneously, smoothly. But not a good idea if you're just getting into steppers.

Some people have posted about this here, but I don't remember how far any of them have got. (I've only dipped in and out occasionally.)

Maybe you could start by having a look at the various 3D printers out there (which often use Arduino) and see what's involved mechanically/electronically.

There are also some open CNC forums out there, again these are not raspi based.

flyinghappy
Posts: 115
Joined: Mon Nov 05, 2012 5:31 pm

Re: CNC

Thu Sep 12, 2013 5:00 pm

I am planning on doing something like this by slowing buying the stuff I need. I think the arduino is the way to go for it for sure
Pi with ArchLinux running a minidlna/samba home server

User avatar
jbeale
Posts: 3494
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: CNC

Thu Sep 12, 2013 5:29 pm

You probably realize that the GPIO pins do not have enough current to directly drive the stepper coils, so they have to be used as signal inputs to a higher current output device, such as a H-Bridge or stepper driver chip. The other problem is that standard Linux by itself is not designed for "hard real-time" tasks meaning driving a signal with precisely specified timing. Latency due to other processing may cause the drive waveforms to have pauses, which can cause the stepper motor to slip.

That said, it has been done: Using RPi.GPIO to drive stepper motors http://www.raspberrypi.org/phpBB3/viewt ... 32&t=10483
and http://www.raspberrypi-spy.co.uk/2012/0 ... in-python/

You can also improve things with a real-time scheduler: Machinoid hard real-time distribution optimized for machines http://www.raspberrypi.org/phpBB3/viewt ... 04#p386159 and http://www.machinoid.com/?cat=2

mushroom glue
Posts: 14
Joined: Sun Oct 14, 2012 8:24 am

Re: CNC

Fri Sep 13, 2013 8:31 am

Thanks for the replies I'd realised that the Pi can't drive the steppers directly, due to lack of power, back EMF etc. I know the pi isn't as good at realtime processing, but I was just wondering if that was absolutely neccecary for this. I think that as of yet I'm not up to the task of sorting it out to run directly. I might have a shot a designing a Pi shield (are they called shields?) with an AVR running GBRL on it and some stepper drivers. On that note; what does anyone think is the best CNC controller board I could replicate on a shield? I'd just need basic G-code interpretation without any extras, but gbrl is limited to 3 axis (as far as I know) and I'd like to have the option to go up to 5/6.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: CNC

Fri Sep 13, 2013 9:02 am

Well one of the things that has been said by one of the CNC experts here is: speed (or rather, smooth motion) matters when machining metal. If the bit is stopping and starting all the time you'll get a bad surface finish, which is more than just a cosmetic matter. So you need to interpolate a movement in all axes, and send the steps (or more likely micro steps) in a timely manner.

I suppose this is why computerised CNC can get to be such a specialist subject...

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: CNC

Fri Sep 13, 2013 1:13 pm

mushroom glue wrote:Thanks for the replies I'd realised that the Pi can't drive the steppers directly, due to lack of power, back EMF etc. I know the pi isn't as good at realtime processing, but I was just wondering if that was absolutely neccecary for this. I think that as of yet I'm not up to the task of sorting it out to run directly. I might have a shot a designing a Pi shield (are they called shields?) with an AVR running GBRL on it and some stepper drivers. On that note; what does anyone think is the best CNC controller board I could replicate on a shield? I'd just need basic G-code interpretation without any extras, but gbrl is limited to 3 axis (as far as I know) and I'd like to have the option to go up to 5/6.
Currently, RPi cannot control a CNC properly without help from an external processor.

Take a look here: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=33809, it is a 4 axis PIC32 based controller that can be easily modified to handle 6 axis.

Cheers!
42

mung
Posts: 506
Joined: Fri Nov 18, 2011 10:49 am

Re: CNC

Tue Sep 24, 2013 7:33 pm

kinsa wrote: Currently, RPi cannot control a CNC properly without help from an external processor.

Take a look here: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=33809, it is a 4 axis PIC32 based controller that can be easily modified to handle 6 axis.

Cheers!
I am not sure you are correct there kinsa?

I do prefer the idea of your pic32 external controller in many ways, but it probably adds a fair amount of extra cost (probably as much as the rpi itself). I think linuxcnc runs fairly fast and smooth direct from the GPIO pins using the dma processor, I don't really have the equipment to test it fully and the project has been shelved for the last few months as I have other stuff to do. I have been doing a little more research over the last few days as I am picking up development again and saw this thread so thought I should post a reply.

I sort of would like to combine effort as it should save both of us some time if we can get a combined distro with possibly multiple RT kernels available (I actually have a ubuntu 12 development VMWARE image with linux3.2.27 RT_PREEMPT, linux3.8.13 RT_PREEMPT, and linux 3.8.13xenomai, kernel cross compiled and they all seem to boot on the rpi though not done any latency tests)

Don't take my word for it (I am not a cnc expert and only hack on things as a spare time hobby), give the linuxcnc rpi RT_PREEMPT image a try and send some bug reports, unless other people try it and give feedback I am not going to bother fixing things. I should say I have not even tried running it multiple axis but I think someone posted a link to a youtube video of it running on the linuxcnc forum.

I am guessing that I may make some more update within a month depending upon available free time, if you check the linuxcnc forum I will probably be posting updates soon and it is the best place to send feedback on the system.

I don't want anyone to expect too much as I am terribly unreliable, and the road is paved with good intentions, but I will definitely be putting a few more hours into linuxcnc on the rpi for at least a few weeks, and at the very least should post the dma driver code.

DanielChai
Posts: 15
Joined: Mon Jan 21, 2013 5:29 pm

Re: CNC

Sun Oct 20, 2013 8:31 pm

That's not entirely true. An external processor would reduce your work but it is definitely possible to use RPi and run python directly to control CNC.

I have made a simple 2D laser engraver by writing my own G code interpreter python code. And the machine works very well. All I need are two $2 L9110 cheap H bridges bought from eBay.

I am still working on finishing my poster but you can find an unfinished one here
http://funofdiy.blogspot.com/2013/10/a- ... r.html?m=1
kinsa wrote:
mushroom glue wrote:Thanks for the replies I'd realised that the Pi can't drive the steppers directly, due to lack of power, back EMF etc. I know the pi isn't as good at realtime processing, but I was just wondering if that was absolutely neccecary for this. I think that as of yet I'm not up to the task of sorting it out to run directly. I might have a shot a designing a Pi shield (are they called shields?) with an AVR running GBRL on it and some stepper drivers. On that note; what does anyone think is the best CNC controller board I could replicate on a shield? I'd just need basic G-code interpretation without any extras, but gbrl is limited to 3 axis (as far as I know) and I'd like to have the option to go up to 5/6.
Currently, RPi cannot control a CNC properly without help from an external processor.

Take a look here: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=33809, it is a 4 axis PIC32 based controller that can be easily modified to handle 6 axis.

Cheers!

kinsa
Posts: 457
Joined: Sat Dec 01, 2012 10:16 pm

Re: CNC

Mon Oct 21, 2013 12:03 am

Let me rephrase my statement:
kinsa wrote: Currently, RPi cannot control a CNC using LinuxCNC properly at the moment without help from an external processor.
Cheers!
42

DanielChai
Posts: 15
Joined: Mon Jan 21, 2013 5:29 pm

Re: CNC

Wed Oct 23, 2013 4:54 pm

Hi,

Yes it is possible. But you need some programming if you don't buy external stepper controller. I managed to use my RPi to control two 4 wire 2 phase stepper motors simultaneously through two dual H bridges directly. The project is a 2 axis CNC laser engraver.

Compared to controlling one stepper motor, the key to control more motors simultaneously is to find the least common multiple (LCM) of the steps of different motors. For example, if you want to spin motor A 12 steps and B 15 steps at the same time. you need to find the LCM of 12 and 15, which is 60. 60/12=5, 60/15=4. So you spin motor A one step every 5 loops and spin motor B one step every 4 loops. After 60 loops you are done.

The idea can be easily extended to multi-axes. For example, spin motor A 8 steps, B 5 steps, C 24 steps and D 0 steps. Ignore the 0s. The LCM of ABC is 120. 120/8=15. 120/5=24. 120/24=5. So set a loop of 120 and step A every 15 loops, B every 24 loops and C every 5 loops.

I wrote my own 2D G code interpreter using python. It would be more difficult to control more axes but I think it is definitely doable. I am trying to finish my blog and shaping my python code more readable. An unfinished description can be found here
http://funofdiy.blogspot.com/2013/10/a- ... laser.html

mushroom glue wrote:Is it possible to arrange a raspberry pi to drive a set of stepper controllers directly, to form part of a CNC machine, and run the G-code interpreter etc. and something like octoprint on the raspberry pi? There seems to be CNC-related projects like octoprint, but all of them seem to use external CNC controllers, and simply take the place of a desktop. Seeing as the Pi's got a bunch of GPIO pins, shouldn't it be possible to use these to directly control the stepper drivers, cutting out the microcontrollers etc.
Is this doable, or are the GPIO pins not capable?

dcarothers
Posts: 3
Joined: Tue Jun 14, 2016 8:46 am

Re: CNC

Tue Jun 14, 2016 8:51 am

You can not drive a stepper motor from directly from the Rpi GPIO pins, but you can use a relay to drive the motor. And it is not that hard, once you get handle on python and the methodology to hook up several stepper motors.

The only problem I have found is finding a CAM program to run steppers off of the GPIO pins, starting with a 3D model to generate tool paths. Has anyone had any success with this?

dcarothers
Posts: 3
Joined: Tue Jun 14, 2016 8:46 am

Re: CNC

Wed Jun 15, 2016 4:12 am

Running a CNC from python is not bad if you are running in straight lines, but you really need a g-code interpreter to send synchronized signals from the GPIO pins if you plan on cutting curves out.

Also, it looks like LinuxCNC is actually a OS, instead of a third party program which can be installed within rasbian... can anyone confirm this?

Return to “Automation, sensing and robotics”