Post Reply
User avatar
Posts: 62
Joined: Tue Sep 11, 2018 4:18 pm
Location: Cleveland, OH
Discord Handle: @Shep
Owned M3D Printers: Original Micro, Pro, ProMega, Crane


Post by Shep » Wed Nov 14, 2018 7:45 pm

This subject has not yet been vetted as of yet and may contain invalid, misleading, or downright incorrect information. It is provided as a VERY rough guide for how functionality may be employed, however it is by no means thorough, and effects of incorrect use of GPIO pins are still highly unknown.

Proceed with caution at your own risk!

GPIO pin information can be found on the Duet Wiki:
GPIO Pins.png
GPIO Pins.png (7.66 KiB) Viewed 457 times
GPIO Pins.png
GPIO Pins.png (7.66 KiB) Viewed 457 times
[ Source ]

For a wiring diagram of the Duet 2 Maestro, please refer to this pic:
Duet Wiring Diagram - 1500px.png

The first four are found on the Expansion port on the bottom-right, which is pictured here:
Expansion Port.png

Pins as per chart are 4, 5, 9, and 8, respectively. The last one, and the only one capable of PWM, is found on the Z Probe port, center pin found here:
Z Probe Port.png
Z Probe Port.png (12.97 KiB) Viewed 457 times
Z Probe Port.png
Z Probe Port.png (12.97 KiB) Viewed 457 times

The M42 command is used to control them, as per the Duet Gcode docs. Although wording is a bit confusing on that link, and it references a seemingly nonexistent M583 Gcode, it appears to be used in this manner:

S0 or S1 for the high/low pins.
S0-S255 for PWM

So, to use all the pins, from top to bottom, you would do this:

Code: Select all

; Turn all Expansion port GPIO off
M42 P60 S0 ; EXP0  - off
M42 P61 S0 ; EXP1  - off
M42 P62 S0 ; TWD0  - off
M42 P63 S0 ; TWCK0 - off

; Turn Z Probe port GPIO off
M42 P64 S0 ; Z_PROBE_MOD - off

; - - - - - - - - - -

; Turn all Expansion port GPIO on
M42 P60 S1 ; EXP0  - on
M42 P61 S1 ; EXP1  - on
M42 P62 S1 ; TWD0  - on
M42 P63 S1 ; TWCK0 - on

; Turn Z Probe port GPIO on
M42 P64 S255 ; Z_PROBE_MOD - on

; - - - - - - - - - -

; Turn Z Probe port GPIO on, duty cycle 25%
M42 P64 S63 ; Z_PROBE_MOD - on

; Turn Z Probe port GPIO on, duty cycle 50%
M42 P64 S127 ; Z_PROBE_MOD - on

; Turn Z Probe port GPIO on, duty cycle 75%
M42 P64 S191 ; Z_PROBE_MOD - on
For the 25% duty cycle number, start at 256, always. (256 / 4) = 64 -- us code monkeys get weird pedantic and start counting from zero, so you simply subtract one from that number to reach the actual result, (64 - 1) = 63. Simple, but weird I know. Duty cycle of 1/3 however, 85.333 repeating, best to truncate to 85 and use a value of S84 (remember, subtract one, counting starts at zero). 50% is 128/256, 75% is 192/256, subtracting one from each gives you S127 and S191 respectively.

Now the part of fair warnings, "don't say I didn't tell ya", etc. all that fun jazz (and the warning at the top of this post should indicate importance already, but just to further emphasize why it's critical to not rush out and do things, there are two VERY IMPORTANT PITFALLS with these GPIO's that I'm going to go over now. (#2 is just because the information is still being gathered and is still very much relatively new, as is some of the above uncertainty -- as time progresses this will be more clear and less "you're on your own" style obviously):

1) You can only drive a current of about 20 mA. This is the equivalent of ONE single red LED. Not the bright ones either. In other words, you MUST either use these solely for data transmission, OR use a transistor of some kind (MOSFET is highly recommended for simplicity and power capabilities) to do anything useful. NEVER DRIVE LED STRIPS DIRECTLY FROM GPIO!!! The effects of doing so are not known, and at worst could result in blowing the MCU of the Duet, frying it, voiding warranty, costing you $169 plus shipping in the process.

Unless you are using GPIO to communicate with another MCU (and if you don't know what any of that means, you're definitely not), always -- and I mean ALWAYS -- use a MOSFET, and source power from elsewhere. MOSFETS can handle 50 amps with nanosecond response times and do not affect PWM in any capacity whatsoever. If anything, they let you PWM bigger stuff like motors from puny GPIO so seriously use 'em. They are very cheap.

Extension to #1: best approach for LED strips powered by the ProMega directly is to take the 24v from the PSU, if needed place the appropriate step-down converter in the middle (12v would need a 12v stepdown, 5v a 5v stepdown, etc. -- avoid anything called a "regulator" btw), then pass the voltage OR ground through the MOSFET, and off to whatever you need to power. Depending on how #2 is determined, it still isn't clear if you'll need an NPN or a PNP variant MOSFET, and also if you need to switch the voltage or the ground, that will be determined soon.

2) It is still unclear if the GPIO pins send voltage out (and at what level they do given 3.3v and 5v exists on both headers that contain GPIO ports) and thus is connected to GND when not active OR is simply not connected (N/C), or if the GPIO pins act as floating/sunk grounds (which also exist on the same ports). A multimeter may be required to determine this, until further research is completed.

Post Reply