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

== Introduction ==
-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
+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 ==
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.
-== Logical pin numbers ==
+== RepRapFirmware 3.x and later ==
+
+In RRF 3.x and later, pins are undefined at startup. Before you can use M42 or M280, you must create a GPIO port using M950. Then in the M42 command, the P parameter is the GPIO port number, not the logical pin number. Duet 2 supports up to 10 GPIO ports, numbered 0 to 9. No GPIO ports are allocated by default.
+
+In RRF_3, the F and I parameters are no longer supported in M42. Instead, use the F and I parameters in M950 when you create the GPIO port.
+
+Example - RRF_2 code:
+
+[code]M42 P3 I1 S0.5 F500 ; set Heater 3 pin to 50% PWM at 500Hz[/code]
+
+RRF_3 code:
+
+[code]
+M950 P0 C"exp.heater3" Q500 ; allocate GPIO port 0 to heater3 on expansion connector, 500Hz
+...
+M42 P0 S0.5 ; set 50% PWM on GPIO port 0
+[/code]
+
+For a list of pin names, see [[RepRapFirmware 3 overview#Section_Pin_names|RRF3 Pin names]].
+
+== RepRapFirmware 2.x and earlier ==
+
+The rest of this page shows how to set up M42 and M280 in RRF 2.x.
+
+=== Logical pin numbers ===
Starting with firmware version 1.16, pin numbers in the [[Gcode#Section_M42_Switch_I_O_pin|M42 command]] are logical pin numbers as listed below, not Arduino-like pin numbers. The [[Gcode#Section_M280_Set_servo_position|M280 servo control command]] uses a subset of the same pin numbers.
}
-== Board dependencies ==
+=== Board dependencies ===
-=== Duet 2 WiFi and Duet 2 Ethernet ===
+==== Duet 2 WiFi and Duet 2 Ethernet ====
The miscellaneous pin numbers 60-63 correspond to the CS5-CS8 pins on the expansion connector. These were originally allocated for use as the E2-E6 endstop pins and are labelled as such on the expansion connector, but they are now used to address thermocouple and PT100 daughter boards on a Duex 2 or Duex 5 instead. Because most users don't need more than the four thermocouple and PT100 channels supported on the Duet 2, we make CS5-8 available as general purpose I/O if you do not have any daughter boards fitted to the Duex 2 or 5.
Logical pins 64 and 65 are supported in firmware 2.01 and later only. Note that the Z_PROB_MOD pin is driven automatically when some Z probe modes are selected.
-=== Duet 2 Maestro ===
+==== Duet 2 Maestro ====
It would be helpful to refer to the [[Duet 2 Maestro Wiring Diagram|wiring diagram for the Duet 2 Maestro]] to identify the pins.
}
-=== Duet 0.6 and 0.8.5 ===
+==== Duet 0.6 and 0.8.5 ====
The mapping between logical pin numbers for miscellaneous pins and the corresponding signal names on the expansion connector is as follows.

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

Revert Changes