M42
Back to the Gcode Dictionary
M42: Switch I/O pin
Parameters
- Pnnn GPIO port number (RRF 3.x, set by M950), Logical pin number (RRF 2.x and earlier),
- Snnn Pin value
- Fnnn PWM frequency (optional). (Not supported in RRF 3.x, use M950)
- Innn Invert PWM (optional). I0 (no inversion) is default, I1 inverts. (Not supported in RRF 3.x, use M950)
Example
- M42 P7 S255
M42 switches a general purpose I/O pin. Use M42 Px Sy to set pin x to value y. The S field may be in the range 0..1 or 0..255.
Example - RRF2 code:
M42 P3 I1 S0.5 F500 ; set Heater 3 pin to 50% PWM at 500Hz
RRF3 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
Notes
In RRF 3.x, before you can use M42 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.x, 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.
In RRF 2.x, the 'P' pin number reference is an internal firmware reference named "digital pin" which It maps on different connector pins depending the hardware. See Using servos and controlling unused IO pins for all the unused pin mappings in RRF 2.x.
For Duet 0.8.5 and 0.6, along with pre 1.16 versions of RepRapFirmware see: http://reprap.org/wiki/G-code#M42:_Switc...
See also
M280, M950
0 Comments