Adapting Marlin firmware, M108 vs M42

General discussion topics
Post Reply
ketil
Posts: 45
Joined: Wed Apr 09, 2014 9:58 pm

Adapting Marlin firmware, M108 vs M42

Post by ketil » Sun May 09, 2021 4:21 pm

I'm busy adapting the Marlin firmware v2 to my M2 from 2012. The original Marlin firmware adapted to the M2 had the custom command "M108" to set the speed of the system fans (electronics and hotend).

Unfortunately, M108 is now already in use by Marlin. Also, hacking in a new command wasn't quite as simple as it used to be. Earlier a command simply executed an analogWrite(), now it's all delegated to a planner object and a thermalManager object.

While poking around, I came across Marlin's M42 command. Basically, it lets you specify a pin number, and write a value to that pin. So this command:

Code: Select all

M42 P6 S155
appears to do exactly the same as the MakerGear specific command:

Code: Select all

M108 S155
I'm just going to use M42, because attempting to keep compatibility with the old firmwares' M108 now introduces the tradeoff of breaking compatibility with stock Marlin. So my start gcode will use:

Code: Select all

M42 P6 S155 ; instead of M108 S155
and my end.gcode will use:

Code: Select all

M42 P6 S0 ; instead if M108 S0
This seems to be the best solution, IMO. It works across Marlin v1 and Marlin v2. I haven't tested with the standard firmware distributed by MakerGear, however. Anyone? It's easy to test, just send this manually to start the fan:

Code: Select all

M42 P6 S155
and send this to stop the fan:

Code: Select all

M42 P6 S0

ketil
Posts: 45
Joined: Wed Apr 09, 2014 9:58 pm

Re: Adapting Marlin firmware, M108 vs M42

Post by ketil » Mon May 10, 2021 9:25 pm

Update:

After actually upgrading to Marlin V2.0.8, the M42 command didn't work. When I first tested, I got:

Code: Select all

M42 P6 S155
Unknown command: "M42 P6 S155"
I looked at the code again, and found out that I had to enable Marlin's DIRECT_PIN_CONTROL in Configuration_adv.h. So I did that, and uploaded the new firmware. Then I tried again, and got:

Code: Select all

M42 P6 S155
Error:Protected Pin
Reading the docs once more, I see there's an I<bool> option, which ignores said protection. So finally, I found the command that works with the latest firmware.

Code: Select all

M42 I1 P6 S155
I'm not going to downgrade my firmware to Marlin v1 to actually verify that the I1 is backwards compatible, but looking at the code I think perhaps the old version will simply ignore that bit.

Post Reply