Image from wikipedia
This page deals with connecting hobby servos, DC motors and spindles to Duet mainboards.
RepRapFirmware allows you to connect other devices to unused outputs. Expansion boards also provide additional inputs and outputs. The following Gcodes allow re-purposing of some pins, and direct control of those pins for peripherals such as PWM hobby servos, DC motors, pumps, spindles and General Purpose Inputs/Outputs (GPIO).
There are a number of options for extra control:
Within the firmware, there are limits to the number of spindles, servos and GPIO ports that can be configured. Servos and DC motors are counted as General Purpose (GP) Outputs. Spindles are separate.
|Spindles||GP Outputs||GP Inputs|
|Duet 3 Mainboard 6HC||4||32||16|
|Duet 3 Mini 5+||4||32||16|
|Duet 2 WiFi/Ethernet||4||20||20|
|Duet 2 Maestro||2||10||10|
Connect servo +5V and GND either to the Duet, or power the servo from a separate +5 supply. If you need to add the 220uf capacitor (see Recommendations, below), you can:
Connect the PWM wire to an appropriate PWM pin on the Duet. Most 5V servos seem to work fine with the 3.3V signalling most Duet I/O pins supply.
It is possible to use an OUT (Duet 3) or heater/fan (Duet 2, on-board headers) port instead. As this is a PWM-to-GND pin, you would need to use a pullup resistor to the servo power voltage (typically 5V) and specify inverted output in the M950 command.
'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 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 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:
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.
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.
|5V current limit|
|Duet 3 Mainboard 6HC||3.0 A|
|Duet 3 Mini 5+||1.0 A|
|Duet 2 WiFi / Ethernet / Maestro||2.0 A|
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.
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.
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.
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 Recommendations).
Servos of similar specification to this should be fine to connect to a Duet without extra circuitry:
|TowerPro SG90 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 Recommendations) or risk damage to the Duet and/or connected peripherals, particularly due to Regenerative Braking.
|Description||55g X-large servo|
|Current draw at idle||10 mA|
|No load operating current draw||170 mA|
|Stall current draw||1200 mA|
With the hobby servo connected to appropriate outputs on the Duet, configure the servo as follows:
Duet 3 MB6HC example
;configuration M950 S1 C"out9" ; assign GPIO port 1 to out9 (Servo header), servo mode ;move servo with M280 P1 S80
Duet 2 example
;configuration M950 S0 C"exp.heater3" ; assign GPIO port 0 to heater3 on expansion connector, servo mode ;move servo with M280 P0 S80 ; set 80deg servo position on GPIO port 0
Note that in RRF 2.x, Duet 2 supports 10 GPIO ports, numbers 0 to 9.
;configuration M307 H3 A-1 C-1 D-1 ; disable heater 3 ;move servo with M280 P3 I1 S80 ; set Heater 3 pin to 80deg servo position, inverted
See the input/output section for your Duet board to determine pin name (RRF 3.x) or logical pin number (RRF 2.x), and pin capability. See the wiring diagram on the same page for the physical location of the pin:
With the DC motor connected to appropriate pins on the Duet, configure the firmware as follows:
In RRF 3.x and later, pins are undefined at startup and no GPIO ports are allocated by default. Define the heater or fan connector as a GPIO port using M950. Control the port using M42, where the P parameter is the GPIO port number.
M950 P0 C"out4" Q100 ; allocate GPIO port 0 to OUT_4 (fan output), 100Hz ... M42 P0 S0.5 ; set 50% PWM on GPIO port 0
M950 P0 C"fan0" Q100 ; allocate GPIO port 0 to FAN 0, 100Hz ... M42 P0 S0.5 ; set 50% PWM on GPIO port 0
Starting with RepRapFirmware version 1.16, pin numbers in the M42 command are logical pin numbers, not Arduino-like pin numbers.
Note that these logical pin numbers are not the physical pin numbers on the expansion header, or the internal pin numbering within the firmware.
For a list of logical pin numbers, see the
Free up the pin for use as a general purpose I/O pin that can be controlled using M42:
M307 H# A-1 C-1 D-1to make the pin available, where # is the heater number, and make sure that no tool is configured to use that heater.
M106 P# I-1to make the pin available, where # is the fan number.
Then use M42 to control the pin, with P, S, F and I parameters.
M307 H2 A-1 C-1 D-1 ; Disable Heater 2 (e1heat) ... M42 P2 I1 S0.5 F100 ; set Heater 2 pin to 50% PWM at 100Hz, inverted