Skip to main content
WARNING! From February 2022, these pages are no longer maintained.
Please see the current Duet3D documentation at https://docs.duet3d.com/
Help

Revision to Using servos and controlling unused IO pins

Ian A-S

The Gcodes [[Gcode#Section_M42_Switch_I_O_pin|M42 Switch I/O pin]] and [[Gcode#Section_M280_Set_servo_position|M280 set servo position]] allow direct control of some pins, or re-purposing of those pins to control PWM hobby servos.
-== Important note on connecting servos ==
+== CAUTION! ==
-When a servo stops moving, it can pump a large amount of energy into the +5v rail due to regenerative braking. If unchecked, this may increase the voltage of the +5V rail above the safe limit. So when using servos with them it is advisable to add your own 220uF capacitor between the +5V and ground servo wires. This applies whether the servo is connected directly to the Duet or to an attached DueX expansion board or expansion breakout board. If using a large servo then we suggest you power it from a separate 5V power supply.
+=== Important considerations when connecting servos! ===
+
+'Hobby' servos can be connected and controlled by the Duet range of boards. However, there are limitations on the size of servo that can be powered directly, due to the current draw of the servo (particularly when it stalls, i.e. 'stall current'), and the current the servo can generate when it stops or is forced to turn ('regenerative braking'). Both of these can have a damaging effect on the Duet and/or connected peripherals, eg PanelDue.
+
+=== Stall current ===
+
+Stall current is the maximum current drawn when the motor is applying its maximum torque, either because it is being prevented from moving entirely or because it can no longer accelerate given the load it is under. This is 'under normal conditions', i.e. the motor isn't being asked go from max speed in one direction to max speed in the other, which can generate even higher currents.
+
+Your servo's stall current should not exceed the Duet's available current (see [[Using_servos_and_controlling_unused_IO_pins#Section_Duet_board_5V_current_limit|Duet board 5V current limit]] below), and it's advisable to have some spare current capacity, so don't specify a servo that uses up all the remaining current. The effect of a servo drawing too much current will be to drop the voltage on the 5V rail, most likely leading to a Duet board reset, but may damage the 5V regulator.
+
+Servos that are commanded beyond their movement limits usually stall. This heats up both the servo and the Duet. The servo is likely to burn out if held in this state. So:
+
+* Ensure that the Duet can supply the stall current.
+* Either be very careful not to command the servo beyond its working range, or else command the servo to move, hold it for a short time, then use M280 P# S0 to stop commanding the servo.
+
+=== Regenerative braking ===
+
+When a servo stops moving, it can pump a large amount of current into the +5v rail due to regenerative braking (the servo motor effectively becomes a generator). If unchecked, this may increase the voltage of the +5V rail above the safe limit. This applies whether the servo is connected directly to the Duet or to an attached expansion board or expansion breakout board. See 'Recommendations' below.
+
+Very generally, there is a correlation between stall current and the amount of current a servo produces in regenerative braking. However, a servo that has a stall current close to the available 5V current from the Duet might still pump enough current into the 5V rail to be a problem.
+
+=== Recommendations ===
+
+In all cases, problems can be avoided by, either:
+
+* connecting a Schottky diode between Duet +5V output and the servo +5V power input, and a 220uF capacitor between servo +5V and servo ground; or
+* powering the servo from a separate +5 supply.
+
+==== Duet board 5V current limit ====
+
+Current limit is the total for 5V and 3.3v. Subtract any current draw, including the internal current consumption (usually around 200-300mA), any PanelDue or other display, connected and powered SBC and peripherals, and any endstops/Z probes that draw significant power, to find the available current for a connected servo.
+
+{table
+|
+| 5V current limit
+|--
+| Duet 2 WiFi / Ethernet / Maestro
+| 2.0 A
+|--
+| Duet 3 Mainboard 6HC
+| 3.0 A
+|--
+| Duet 3 Mini 5+
+| 1.0 A
+}
+
+==== Hobby servo specification examples ====
+
+There are many different types of hobby servos, and we do not recommend any particular one. Check the specification of any servo you connect to your Duet, in particular the idle, running and stall current. Generally, so-called '9g' servos ''should'' be okay to connect directly (but please check your servo's specs! And see note below about Duet 3 MB6HC), but larger servos should have additional protection, or be powered independently of the Duet (see [[Using_servos_and_controlling_unused_IO_pins#Section_Recommendations|Recommendations]]).
+
+Servos of similar specification to this should be fine to connect to a Duet without extra circuitry:
+
+{table
+| [https://opencircuit.shop/Product/TowerPro-SG90-9G-micro-servo-motor-180|TowerPro SG90 9G micro servo]
+|--
+| Description
+| 9g micro-servo
+|--
+| Idle current
+| 6 ± 10 mA
+|--
+| Running current
+| 220 ± 50 mA
+|--
+| Stall current
+| 650 ± 80 mA
+}
+
+This motor would require extra circuitry (see [[Using_servos_and_controlling_unused_IO_pins#Section_Recommendations|Recommendations]]) or risk damage to the Duet and/or connected peripherals, particularly due to Regenerative Braking.
+
+{table
+| [https://www.towerpro.com.tw/product/mg995/|TowerPro MG995]
+|--
+| Description
+| 55g X-large servo
+|--
+| Current draw at idle
+| 10 mA
+|--
+| No load operating current draw
+| 170 mA
+|--
+| Stall current draw
+| 1200 mA
+}
+
+=== Notes on specific Duet boards ===
+
+==== Duet 2 WiFi / Ethernet / Maestro ====
+
+On the Duet 2 WiFi / Ethernet / Maestro, if a servo feeds power back (regenerative braking) then the internal 5V rail voltage will increase. This could damage other devices connected to +5V (e.g. PanelDue), also if the rise is high enough it could blow the mosfet drivers (rated at 7V) and the 3.3V regulator (rated at 6.5V). If the 3.3V regulator goes, it may take out other components on the board too.
+
+==== Duet 3 Mainboard 6HC ====
+
+On Duet 3 MB6HC, the internal and external 5V are separated, but the built-in 5V regulator regulates the external +5V rail (this was to provide consistent power for an attached RPi). This means that if a servo pumps power into external +5V, the internal 5V power will drop out for a short time, causing the board to reset. Again, any other devices connected to external +5V e.g. PanelDue may be damaged. Even small '9g' servos may be able to do this.
+
+==== Duet 3 Mini 5+ ====
+
+On Duet 3 Mini 5+, the internal and external 5V rails are separated, however the built-in 5V regulator regulates the internal 5V power. So a servo pumping power into external 5V won't damage the Duet or cause it to reset, however it could damage other devices powered from external +5V e.g. PanelDue or 12864 display.
== RepRapFirmware 3.x and later ==

To undo the changes made by this version, click 'Revert Changes.' This will automatically restore the previous version of this guide.

Revert Changes