Why am I not seeing an effect from an M42 command on Marlin?

  • I'm trying to use one of the RAMPS GPIOs to control an external device that requires a 5V low-current logic level signal from Marlin. In order to do this programmatically, my host software (Octoprint) is sending an M42 command. I am using the following syntax:

    M42 P4 S255

    according to the pinout in the following image:

    enter image description here

    However, the pin appears to not be driven to a logic HIGH level. Is there firmware-level configuration I need to do as well, or is my syntax/pin number incorrect?

    Post your firmware settings. Also verify your source for the board. If it is a cheap knockoff board...

    @StarWind I'll follow up with the printer vendor regarding board source. There are no configuration elements specific to pins or GPIOs that I see in `Configuration.h` or `Configuration_adv.h`.

    I'd try M42 P4 S0 just in case it's somehow inverted. If so, then and only then I'd worry about why.

    Did Mark's answer help at all. If so, please could you mark it as accepted. If it didn;t and you have resolved your issue, could you post an answer and accept that, please. As a beta site we need to keep our unanswered question list to a minimum. Thanks

    @Greenonline Unfortunately, the printer is no longer in my possession (I no longer work in that lab and am in a different city hours away altogether), and the issue was worked around by somebody else in a manner unknown to me. Mark's answer does seem sensible but I can't confirm that it works--shall I select it regardless?

    Maybe not then, in that case. Thanks for the update. I'm not sure what to do in this situation... it seems like it will be forever uncertain whether it worked or not. Not to worry :-)

  • I looked at the current Marlin code and the P24 command should work as you expect it unless the pin you are trying to use in listed as the "SENSITIVE_PINS" list:

    #define SENSITIVE_PINS { 0, 1, \
    _H0_PINS _H1_PINS _H2_PINS _H3_PINS _H4_PINS \
    _X2_PINS _Y2_PINS _Z2_PINS \

    These pins are printer specific; so, without access to your Marlin build, I can't see if pin 4 corresponds to one of these. If this is the problem, the command should be returning an error. If there is no error, I would look closely at the hardware.

  • Might be because servo pins are not connected to 5V. use Jumper as shown

    enter image description here

    Does this affect the ability to drive the GPIO? I don't need a 5V power supply, just a TTL signal.

    I cannot say for sure. Tomorrow I will check on my board. If you want to check the working of `M42` using marlin, send 'M42 S255` since no pin number is given, by default `LED_PIN`(pin number 13, RAMPS LED is attached to this pin.) pin will turn ON. You can send `M42 P20 S255` and get gpio output from 20th pin (In your image I2C section pin 20 or 21). I have checked this. it works.

    It's not a strong concern regardless; I haven't had access to the printer in question for a number of years now (since I graduated/moved), but I suspect that because the atmega2560 drives the pins from its internal supply, setting that jumper would power the fixed 5V pin but not affect the IO/signal pin.

    May be that pin is already used by firmware for some other purpose like servos are enabled

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM

Tags used