Adapting Marlin firmware, M108 vs M42
Posted: 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:
appears to do exactly the same as the MakerGear specific command:
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:
and my end.gcode will use:
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:
and send this to stop the fan:
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
Code: Select all
M108 S155
Code: Select all
M42 P6 S155 ; instead of M108 S155
Code: Select all
M42 P6 S0 ; instead if M108 S0
Code: Select all
M42 P6 S155
Code: Select all
M42 P6 S0