Looks normal and I see no real reason it should not work inside it. It is implemented in Commands.com near line 1754
case 42: //M42 -Change pin status via gcode
if (com->hasP()) {
int pin_number = com->P;
for(uint8_t i = 0; i < (uint8_t)sizeof(sensitive_pins); i++) {
if (pgm_read_byte(&sensitive_pins[i]) == pin_number) {
pin_number = -1;
break;
}
}
if (pin_number > -1) {
if(com->hasS()) {
if(com->S >= 0 && com->S <= 255) {
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, com->S);
analogWrite(pin_number, com->S);
Com::printF(Com::tSetOutputSpace, pin_number);
Com::printFLN(Com::tSpaceToSpace, (int)com->S);
} else
Com::printErrorFLN(PSTR("Illegal S value for M42"));
} else {
pinMode(pin_number, INPUT_PULLUP);
Com::printF(Com::tSpaceToSpace, pin_number);
Com::printFLN(Com::tSpaceIsSpace, digitalRead(pin_number));
}
} else {
Com::printErrorFLN(PSTR("Pin can not be set by M42, is in sensitive pins! "));
}
}
break;What you can try is remove all Com:: parts which write data to output. Also I do not know why that would be the only thing I can think of that could make a problem. It would look then like this
case 42: //M42 -Change pin status via gcode
if (com->hasP()) {
int pin_number = com->P;
for(uint8_t i = 0; i < (uint8_t)sizeof(sensitive_pins); i++) {
if (pgm_read_byte(&sensitive_pins[i]) == pin_number) {
pin_number = -1;
break;
}
}
if (pin_number > -1) {
if(com->hasS()) {
if(com->S >= 0 && com->S <= 255) {
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, com->S);
analogWrite(pin_number, com->S);
}
} else {
pinMode(pin_number, INPUT_PULLUP);
}
}
}
break;Just a test and if it helps please report so I can investigate why this is an issue.