Arduino Uno and Electrical Basics

Hello. I am struggling with the electrical components of the MPCNC. I am hooking up a Arduino Uno and a CNC Shield, as I had them around the house. I do not want to fry the components, and I’m struggling wading through the documentation of these things. I’m hoping to draw upon this forum’s experience.

Providing Power:
Can I use a 12V, 2.5 Amp power supply to the Arduino? Is that just to run the Arduino? From what I understand, the arduino runs at 1 Amp, but has a fuse that prevents too much current, up to a point.

Setting Current Limits:
The stepper motors I ordered from the MPCNC website appear to have a “Rated Current/Phase” of 2.0 Amps. Is the “Rated Current Per Phase” the Current Limit I should shoot for?

Since I have the “Series” connection between my X and Y motors, I have to provide twice as much current for them, correct?

I have 4 “A4988” stepper motor drivers. I have found two conflicting equations:

Current Limit = Vref*2, and
Vref = Current Limit * 8 * Current Sensing Resistance.

Which do I use? Why?

Making Sure it’s hooked up right:
If I use an Arduino Mini CNC SHield, do I need to put Jumper Caps on the “M0, M1, M2” slots? What do those Jumper Caps do?

Providing Control:
What, then, are my options to provide Gcode instructions to the board? I’m using this as a CNC, and I have to hook this USB up to something. Buying an extra computer to run it seems excessive, so I was wondering if anyone had any alternatives.

Thank you so much.

I’ve not used a CNC shield before, but I’ve been around Arduino boards and well as prowled this forum, so I believe I can give you accurate answers to some of your questions.

Providing Power:
Can I use a 12V, 2.5 Amp power supply to the Arduino? Is that just to run the Arduino? From what I understand, the arduino runs at 1 Amp, but has a fuse that prevents too much current, up to a point.

The appears to be a voltage regulator on the CNC Shield that provided 5V power to the Arduino, so all you have to do is wire up power to the CNC shield. There is no separate power for the Arduino board. You should be looking for a 6A 12V to 24V power supply.

Setting Current Limits:
The stepper motors I ordered from the MPCNC website appear to have a “Rated Current/Phase” of 2.0 Amps. Is the “Rated Current Per Phase” the Current Limit I should shoot for?

Ryan ships the Rambo boards and firmware with the drivers set to 0.8A. Note you will likely overheat your steppers if you drive them at full rated current for any length of time.

I don’t believe this to be the case. I cannot tell you technically why, but in the two versions of the firmware for the Rambo boards (serial and dual), the drivers are set to the same 0.8A.

These jumpers control the stepping mode of the driver. The behavior is somewhat driver specific, but for the A4988 I believe you want to jumper all three (M0, M1 and M2), which will set the driver in 1/16 stepping mode.

Note you will almost certainly be using GRBL firmware for this board since, to the best of my knowledge, Marlin does not run on this hardware. Most MPCNC uses run Marlin firmware, and Ryan provides preconfigured firmware for several boards. Some users really like GRBL, but it is not the path of least resistance. If you are looking for an easier path, you can purchased a Ramps 1.4 setup including a display that will allow you to run g-code headless (without a computer), and that will run a preconfigured Marlin for under $40.00 USD.

Let’s see if I can expand those answers.

As stated, you probably only need to provide power to the CNC shield, and it will power the Arduino. you would need to power the Arduino if the shield has the Arduino power diode removed. Yours most likely does not have this problem. Try it with power to the shield. If it doesn’t boot then try to power the Arduino.

Rated current: Don’t max this out. Leave some headroom. Running lower current will run the motors cooler, which is a good thing. I aimed for 1.0A on my Primo, which is more than enough.

Series connection: DO NOT double the current. In series, the current goes through one motor, then through the other. This guarantees that both motors get the same amount of current. It does require higher source voltage, but the 12V that you’re feeding the drivers with is plenty enough for that.

The jumpers set microstepping. A4988 have a maximum of 1/16 (So 3200 pulses for a full revolution, assuming 1.8° steppers.DRV8825 drivers have a 1/32 max (6400 pulses for a full revolution) The pre-built firmware for the RAMPS boards assume 6400 pulses per revolution, on a 16 tooth pulley, and an 8mm lead T8 screw for the Z axis. If you’re setting up your own firmware, you’ll have to adjust that however you set it.

You can leave some of those jumpers off. Find the lookup tables for the drivers that you use. I recommend that you leave them all on, personally.

Using a RAMPS based board is definitely easier, but there is no reason why your CNC shield can’t do the job. Do note that if you are using the A4988 drivers on that RAMPS based board (I use an MKS Gen L) you will have to adjust the pre-configured firmware, since it comes assuming the DRV8825 drivers and 1/32 microstepping. It’s a simple matter though, find the steps/mm in the configuration file and divide the numbers by 2.

You want to tune driver current to match what your motors need. I believe the vRef*2 is for DRV8825-based boards. I used that rule of thumb on my A4988’s and it resulted in too high current, leading to hot motors and jerky performance. There are a number of manufacturers making boards based on the A4988, and they use different sense resistors, which means the vRef measured for a given current changes depending on those resistors. This page, especially the More Info link at the bottom, helped me get mine tuned correctly. I actually had different resistor values on boards I thought I’d gotten all from the same vendor, although in different batches, so I believe it’s worth looking closely.

You guys must have a different cnc shield to me…mine doesn’t have 5v regulators and don’t power the UNO…are you thinking about a RAMPS and MEGA2560?

The 5V regulator is on the Arduino. The shield should supply the 12V to the “Vin” pin, on the same side of the board as the power socket, the set close to the socket, pin furthest. Usually there’s a diode on the shield to prevent powering up the shield, if power is applied to the Arduino

I always have USB connected to my controller, so haven’t any clue if the arduino gets power from the motor V-in on my stack.

Before I posted, I looked up a wiring diagram for the CNC shield. It showed 5V going from the CNC shield to the 5V pin on the Arduino indicating there is a voltage regulator on the CNC shield that will supply 5V for an Arduino There are different versions of the CNC Shield, so I cannot guarantee that your specific board works this way, but at least for the specific one I was looking at, the CNC shield supplied 5V. The voltage regulator on most Arduino boards will handle 12V in, so Dan is right that you could power the Arduino off the same power you use for the CNC shield assuming that you run your your CNC shield at 12V. The shield will handle 36V.

Edit: Just found a reference that a 5V breakout pin was added in CNC Shield version 2.01.

Edit2: Tom is right. I don’t see this setup being run headless (without being USB tethered to a computer), so the Arduino will be powered from the PC. And is is possible that I had it backwards, and that the 5V breakout pin is powered from the Arduino/USB.

OK…well the 5v pin on the cncshield is to accept 5v from the arduino to feed the +5v pin near the step/dir breakout pins and the FAULT pins of the stepper drivers. It does NOT come from the 12-36V input connection to the shield. It does NOT power the Uno. There is NO 5V regulator on the cncshield.

I believe you will find that the Vin pin on the UNO is not connected to anything on the cncshield. There are no diodes on the cncshield…only a fuse for the stepper drivers supply. The shield is supposed to have the stepper motor power applied via its 12-36v connector only. C’mon guys…look at it…there is nothing on the cncshield board that looks even close to a regulator and nothing that requires power other than the stepper drivers.

You power the arduino either by USB or +12V on the barrel connector, and as USB specs call for a max I at 500mA that is all you need to power the arduino.

All these things you are stating apply to a RAMPS board…not a cncshield.

Yes, that will be fine

Nope… that for each stepper motor, you need to multiply that for each stepper motor you expect will be operating at any time.

Nope…series connection has the current flowing both both motors, you need twice the voltage to push that current through the series connected motors, but that is usually available as the stepper drive voltage is ~4V and the power supply supplies 12V (normally)

Stepper drivers can come with sensing resistors of differing values, some are 0.1ohm and some are 0.5ohm (IIRC). So unless the specs of the driver quote the formula current limit = Vref2 to you you can work out the correct current using a multimeter and the formula Vref=currentlimit8*resistance.

they set the microstepping. Most folk want the highest microstepping to get the highest resolution …fit all 3 jumpers for 1/16th microstepping on your A4988’s

got an old laptop? you should be able to pick one up dirt cheap…absolutely anything will do the job.
You can go the Raspberry Pi route. I use an orange pi zero and repetier server to run my 3 3D printers off my lan, but an old laptop would be easier!

1 Like

@jeffeb3 has prepared a V1Pi image that makes getting cncjs and Octoprint running on a Raspberry Pi as close to effortless as I think is possible.

1 Like

Looking at it and of course… I don’t have anything to run that stack headless, so of course the Arduino is always connected to USB. :crazy_face: I don’t think I’ve ever powered on the PSU on that without first having the PC powered on.

I’m just using that setup with a cheap Chinese 3018 thing, and I haven’t actually used it in a year or so because the spindle mount cracked. My Primo uses a RAMPS-alike board with Marlin.

I was running an UNO with a cnc shield on GRBL. I powered the UNO through the USB (from my laptop) and the 12v PS to the shield. Worked great! I used CNCjs to send the gcode to the UNO. Here is the site specific to the shield I have, but it should work for you.

I don’t really expect anyone to trace out this rats nest of wiring but I promised some pictures so here they come. Note that the partitions in this enclosure are molded in place, so I did my best to work within the existing spaces.

Pretty side of the enclosure - the outside.

Power and USB come in the right side. AC plugs across the top run accessories (more on those below) and DC comes in the bottom left corner. Not visible on the sides are a fan on the left which pulls air through the enclosure from inlet holes on the right. The LCD shows commanded and actual spindle RPM. A DPDT switch allows RPM control to be driven by the CNC controller or manually with a 10k potentiometer. The 4 gray cables coming out of the left side are shielded 6 conductor cables. One each for X,Y, and Z axis motor and single end stops, and the fourth carries the PWM sensor power and signal wires and supports a probe connection (independent of the end stops). The e-stop button is inline with the AC power and cuts energy to everything when tripped. The 3 lit up buttons are for Cycle Start, Cycle Pause and Cycle Cancel which are connections provided on the CNC shield.

And the less pretty inside. Note that I did power off the mains when opening the case. All the visible leds are powered through the arduino usb connection.

The top 2/3rds or so is power management. Mains power feeds in top right and runs to the e-stop switch but those wires run under the plywood that the visible control boards are mounted to. Along the top are outlets for A/C accessories. The spindle (left-most outlet) is controlled by the V1Engineering triac board which you can see on the left and the Arduino nano buried beneath the multicolored wiring just south of the relay board. The nano provides the PWM signal to the triac board and also drives the lcd display for spindle rpm. Two center outlets are controlled by 2 of the 4 relays which are wired to the flood and mist coolant pins. Right-most outlet is always on (as long as main switch is on and e-stop hasn’t been triggered) and is where the 19 V DC power supply that runs the steppers and the button lights is plugged in. Finally you can see a buck converter that lowers the 19 v down to 12 for the cooling fan. Originally I planned to use some 12 v leds down by the tool but decided those wires for Z end stop and a separate probe connection.

The bottom left side has a cooling fan which pulls air through the enclosure and the DC power inlet for the steppers. The other wires are AC to the e-stop and light & signal wires for the Start, Stop, and Cancel buttons.

Finally in the bottom right corner is the Arduino Uno, CNC Shield (v 3.00) and A4988 drivers.

This post feels long enough already so I’ll do separate follow-ups for connections to the control board and grbl settings.

Thanks for your attention.


Here’s the output upon connection from cncjs, which includes my grbl $$ settings. Note that these are specific to my build, particularly things like homing directions and axis travel.

CNCjs 1.9.20 [Grbl]
Connected to /dev/ttyUSB0 with a baud rate of 115200
Grbl 1.1h ['$' for help]
client> $$
[MSG:'$H'|'$X' to unlock]
$0=10 (Step pulse time, microseconds)
$1=255 (Step idle delay, milliseconds)
$2=0 (Step pulse invert, mask)
$3=0 (Step direction invert, mask)
$4=0 (Invert step enable pin, boolean)
$5=0 (Invert limit pins, boolean)
$6=0 (Invert probe pin, boolean)
$10=2 (Status report options, mask)
$11=0.010 (Junction deviation, millimeters)
$12=0.002 (Arc tolerance, millimeters)
$13=0 (Report in inches, boolean)
$20=1 (Soft limits enable, boolean)
$21=1 (Hard limits enable, boolean)
$22=1 (Homing cycle enable, boolean)
$23=3 (Homing direction invert, mask)
$24=200.000 (Homing locate feed rate, mm/min)
$25=1800.000 (Homing search seek rate, mm/min)
$26=25 (Homing switch debounce delay, milliseconds)
$27=1.000 (Homing switch pull-off distance, millimeters)
$30=27001 (Maximum spindle speed, RPM)
$31=0 (Minimum spindle speed, RPM)
$32=0 (Laser-mode enable, boolean)
$100=100.000 (X-axis travel resolution, step/mm)
$101=100.000 (Y-axis travel resolution, step/mm)
$102=400.000 (Z-axis travel resolution, step/mm)
$110=8000.000 (X-axis maximum rate, mm/min)
$111=8000.000 (Y-axis maximum rate, mm/min)
$112=360.000 (Z-axis maximum rate, mm/min)
$120=2000.000 (X-axis acceleration, mm/sec^2)
$121=2000.000 (Y-axis acceleration, mm/sec^2)
$122=1500.000 (Z-axis acceleration, mm/sec^2)
$130=345.500 (X-axis maximum travel, millimeters)
$131=510.500 (Y-axis maximum travel, millimeters)
$132=68.800 (Z-axis maximum travel, millimeters)
1 Like

Since the wiring in my pictures makes it hard to see what’s going on, I grabbed a clean photo of the CNC shield from here.


Note that this is a photo of version 3.00 of the CNC shield, which is the version I’m using (although mine does not have the glass fuse the photo shows). Due to changes made to grbl after this board was designed, specifically around PWM for spindle RPM/laser intensity control, not all the silkscreen legends labeling the pins are accurate. I have PWM control working, so will describe the connections I’m using to achieve that. If you have a later version of the shield make sure you find documentation appropriate to your version.

This photo doesn’t include the stepper driver boards. For my A4988’s I’m using 1/16 micro-stepping, so I’ve got jumpers installed on all 3 pairs of M0/M1/M2 pins under the drivers. I’m only using X, Y, and Z, so I only have drivers on the yellow headers.

With the exception of DC 19 V for the steppers, which comes in to the 2 screw terminals on the lower left corner of the photo, and the stepper motor connections themselves next to the driver headers, all my connections are made to the pins along the right edge of the board. I’ll list the pins that I’ve connected to and the purpose it serves. The white headers are the signal pins, all the black headers along the edge are ground connections. Also, the End Stops connections for each axis are in parallel - although they are marked + and - (for Max and Min) they are electronically identical.

SCL = probe connection (104 capacitor to ground for noise control)
SDA = M7 coolant relay signal. Switches 120 V AC on accessory outlet. I plan to use this for a vacuum hold down or other accessory.
5 V & GND = logic power to Arduino Nano VCC and GND and from there to relay board VCC and GND
RST = not used

Z+ = Spindle PWM connected to Arduino Nano PWM in, which controls PWM signal to triac board which in turn outputs variable AC voltage to spindle outlet. Originally the shield used this PWM-capable pin for the Z end stops as printed on the board. grbl versions .9 and later have swapped this pin’s mapping with SpnEn to allow spindle speed and laser intensity control via PWM. Some online documentation states this version of the shield is incompatible with later versions of grbl, but if you understand the pin change it works just fine. If you don’t have variable speed controllers this pin can easily be used for simple relay on/off via the M3/M5 commands.

Z- = second Spindle PWM - unused
Y+/Y- = Y end stop connection(s) (104 capacitor to ground for noise control)
X+/X- = X end stop connection(s) (104 capacitor to ground for noise control)
SpnEn = Z end stop connection
SpnDir = Normally used to control spindle direction but since my AC spindle isn’t reversible I’ve made a change as documented in the grbl firmware config.h file comments to use this as a separate Spindle Enable pin. This allows turning the spindle on and off without changing the RPM setting in the gcode command. May not be needed, but made sense to me as I was reading through the firmware comments and is working as expected.
CoolEn = M8 coolant relay. Switches 120V AC on accessory outlet, mostly for future possibilities since the relay pins were already mapped to gcode commands. Originally I was thinking to use this for an air blast for machining plastics or aluminum but I am now considering using “shop air” and a 12v air valve since I’ve installed a compressor and distribution lines in my shop. If I make this adjustment, I’ll just connect the signal to one of the currently unused relays on the board.
Abort = grbl Cycle Cancel button (mine’s red)
Hold = grbl Cycle Pause button (mine’s orange)
Resume = grbl Cycle Start button (mine’s green)
E-Stop = Unused in my configuration. This pin can be used to reset the Arduino board. I’ve chosen to wire my e-stop in the AC supply line so it kills all power to all elements of the system rather than just resetting the microprocessor.

You’ll note the phrase “104 capacitor to ground for noise control” used several times above. Since my end stop and probe lines run inside shielded cables right next to the motor wires, initially the end stops were unreliable as noise on their lines was interpreted as the switches being tripped. Adding small capacitors between the signal and ground lines for the end stops and probe connection completely solved this problem for me.

When wiring up the connections for all of these pins, I worried about getting connectors on the wrong pins while assembling or troubleshooting. Rather than having a whole bunch of 2-pin connectors to wrestle with in the tight space, I used 2x4 and 2x6 pin connector blocks that came in the header assortment I purchased a while back on Amazon similar to this. Now there are just 3 plugs to deal with, and I don’t worry about getting the connections out of order.

Let me know if you’re interested in more detail on the PWM control. It’s the one @vicious1 sells in the shop and is discussed in detail on a couple of other topics on the forums.