Assigning pins in Marlin firmware for controlling vacuum pumps and top and bottom lights

1,513 views
Skip to first unread message

Hrishikesh

unread,
Jul 23, 2020, 12:33:42 PM7/23/20
to OpenPnP
I’m finally done with the mechanical build and I’m starting to put together the electronics for my machine. I had planned on using the re-arm with ramps for my setup. However I think I may have accidentally damaged the Re-arm. So I’m back to using the Mega+RAMPS combination for now. 

I know I can control the solenoids and the pump through the hotend, heatbed and fan outputs. Would I use the M104, M106 and M140 codes for this? I’ve set the thermistors to 998 in the firmware which always displays the temp values at 25 deg C.

My camera lights are controlled via TTL levels signals. I can use one of the free pins to do this but how do I assign a custom M code for this in marlin?

Any help would be appreciated! Thanks. 

Bill Ruckman

unread,
Jul 23, 2020, 12:49:56 PM7/23/20
to ope...@googlegroups.com
You can use the M42 command to set the pins.  https://marlinfw.org/docs/gcode/M042.html

More information is here:
 

--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openpnp/3e26bae8-e322-440d-aeac-a621fede47fcn%40googlegroups.com.

Hrishikesh

unread,
Jul 24, 2020, 2:58:20 AM7/24/20
to OpenPnP
Thank you! This is helpful.

Josh DeWitt

unread,
Jul 24, 2020, 11:53:00 PM7/24/20
to OpenPnP
One other option is to hook up a pressure sensor to a thermistor input, and then you could use the built in PID (M104/M140) functions to drive your vacuum to a certain pressure and keep it there, but that would also require a vacuum resevoir, and depending on the cfm of your pump, might not be necessary or worth it for the added complexity.

Hrishikesh

unread,
Jul 27, 2020, 2:26:55 AM7/27/20
to OpenPnP
How would that work? I mean, how would I be able to switch on and off the vacuum and solenoids using the hotend and heatbed outputs? I tried 'M42 P8 S255' but that did not work. Neither did 'M140 S25' (since I've used the 998 dummy thermistor values that always show the temp as 25 deg C)

Josh DeWitt

unread,
Jul 27, 2020, 4:19:43 AM7/27/20
to OpenPnP
I don't think you can get it to work off a dummy thermistor value with the target set as the current temp, since both work off error values (hot end is PID, and I think the bed's default Bang-bang algorithm is only triggered if there is a change in the temp reading outside the hysteresis limit).  I haven't tested it myself, but if you Thermistor 998 and set the temp with something like M104 S50, it should give you an output, but one that should trigger thermal runaway protection if you have that enabled.  For me, I had to add the "I" flag to mess with the heater pin from M42 since it's protected by the firmware.  I had to play around a bit to get the right pin number since I'm running a 32 bit controller that labels in terms of ports, but maybe test the M42 with some other pins to make sure you're selecting the right one?

I think the target temp needs to be different enough for the algorithm to start running, but from there you should be able to run a PID tune with the whole system set up that should help a bit.  If you are just turning the things on or off, I think M42 is your best bet, although maybe alter the sensitive_pins.h file, but I think that might be a bit too much instead of just the "I" overrride flag.

Hrishikesh

unread,
Jul 27, 2020, 5:46:12 AM7/27/20
to OpenPnP
Got it. Thank you. I believe you can also disable PID and enable bang-bang where a value of 255 is essentially full current. I'll try that too. 

I also just got an SKR 1.4 board and I will try with that as well. You are right about the pin numbering with a 32-bit board. With your board are you using the pin numbers listed in the .h files in the M42 command (for example, "P2_05") or something like "P2.05"? 

Josh DeWitt

unread,
Jul 27, 2020, 7:42:15 PM7/27/20
to OpenPnP
I'm actually using the SKR mini!  I had port A as 1-16 and B as 17-33 and so on.  I think M42 is 1 indexing, while board pin numbers are not.  Just confirm how many pins you have per port, and it should be just addition.  I don't think the Gcode interface on Marlin supports more advanced pin indexing, although it sure would be nice.

Hrishikesh

unread,
Jul 28, 2020, 9:18:15 AM7/28/20
to OpenPnP
Got it! Thank you. I think the LPC1768 on which the SKR 1.4 is based has 32 pins per port.

Kenny Truong

unread,
Aug 4, 2020, 1:38:38 PM8/4/20
to OpenPnP
Hi, I'm trying to do a similar thing and run my vacuum pump off the heated bed connection of my SKR 1.4 turbo board.

Could you elaborate on how you used the M42 command to do this?

Hrishikesh

unread,
Aug 4, 2020, 1:48:35 PM8/4/20
to OpenPnP
Use the port number without the decimal. For example on the SKR 1.4 the heatbed is on 2.05. The command would then be M42 P205 I1 S255 to turn on that MOSFET. The hotend, heatbed and fan ports are protected pins and without the I1 you would get an error. However, as stated in the earlier posts in this thread some SKR boards follow a base 1 numbering. So essentially all pins on port 0 would be 1 to X. Then pin 1 on port 1 would be X+1.

Richard Klingler

unread,
Aug 4, 2020, 2:16:49 PM8/4/20
to ope...@googlegroups.com
I‘m just using the extruder cooling fan output on my skr v1.4...so I can switch on/off it with M106/M107 easily....you could even sort of control the vacuum pump power ;-)
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openpnp/c8c94a56-ae66-49cc-ac0e-bb57dac4e4d2n%40googlegroups.com.

Josh DeWitt

unread,
Aug 4, 2020, 10:50:07 PM8/4/20
to OpenPnP
I was just looking through config.h, and if you enable `PID_OPENLOOP`, M104/M140 can directly set the power from 0 to PID_MAX, so that might be a cleaner way to access the hotend pins without needing to use the override.  But it does disable PID if you wanted to use a pressure sensor to regulate vacuum.
To unsubscribe from this group and stop receiving emails from it, send an email to ope...@googlegroups.com.

Hrishikesh

unread,
Aug 5, 2020, 5:56:48 AM8/5/20
to OpenPnP
This would certainly simplify things considering that BTT responses to Qs about the boards are extremely slow and sometimes downright incorrect. I had asked them the pin numbering scheme and they asked me to put the pin number as P2_05 whereas the correct way is P205.

Kenny Truong

unread,
Aug 5, 2020, 11:19:02 AM8/5/20
to OpenPnP
Thanks for the help, I'm able to get the pump working now off of the bed heater connection.
I've attached the ACTUATE_BOOLEAN_COMMAND below for anyone else.
{True:M42 P205 I1 S127}{False:M42 P205 I1 S0}

I wonder which would be more robust, running the pump off the bed heater or the extruder fan?

Hrishikesh

unread,
Aug 5, 2020, 11:32:49 AM8/5/20
to OpenPnP
I measured the current draw of the pump to be about 350mA while those of the solenoids to be about 230mA. Both are powered by a 24V supply. Any of those outputs would work well with these small current draws. 
Reply all
Reply to author
Forward
0 new messages