# Specific 3D Printers, Scanners, & Hardware > RepRap Format Printer Forum > Firmware Enhancements to Marlin >  Solenoid for Z probing

## Fri

I am trying to use a solenoid instead of a proximity sensor to probe the bed, since the proximity sensor is heat sensitive and gives different results based on temp. The solenoid is connected to Pin5 and 2 on the PWM above the Mega chip.
I chanded the FW and when I send a M402 i only read 4.77v. Since my solenoid is 5v it is not enough to trigger it and I thought I should have 12v on that pin 5 anyway.  Any ideas?

----------


## Roxy

Can you post some pictures of the probe engaged and retracted?   Did you do anything to handle the inductive kick when the power cycles off to the solenoid?   And...  If it is a solenoid, why do you need to use the PWM mode of the output pins?  Wouldn't just on or off make sense?

----------


## Fri

> Can you post some pictures of the probe engaged and retracted?   Did you do anything to handle the inductive kick when the power cycles off to the solenoid?   And...  If it is a solenoid, why do you need to use the PWM mode of the output pins?  Wouldn't just on or off make sense?


http://cdn.sparkfun.com/datasheets/R...s/ZHO-420S.pdf
This is the solenoid, yes on/off would be good enough, thought that is what I am doing. Got only e1 out left. That is why I thought about pin 5


Can't upload pics, it's not working

----------


## Roxy

OK... Do you understand why I was questioning if PWM (Pulse Width Modulation) made sense?   That kind of feels like a bad thing to do with a solenoid.

----------


## Fri

Good, thanks, where could I attache that solenoid right now I am working on a ramps board, which out would you use to turn it on when z probing?

----------


## Roxy

Well...   I don't know off the top of my head.   I would have to have schematics and more details from you.   But here is what I can tell you off the top of my head.   Most (if not all???) of the GPIO (General Purpose Input Output) pins can be configured as input or output.   The pins that can do PWM are most likely not GPIO pins.  They are even more flexible than GPIO pins.  My guess is they can be configured to be just plain, stupid, simple Input or Output.   If so... You can just use the same pin in a crippled mode.

But otherwise, you should be able to connect to some other GPIO pin and say it is output, and just set it high or low as needed.

----------


## Fri

Okay, some other people have done this and refer to the output as ramps digital output and assign pin 63.

----------


## Roxy

Do you have a reverse biased diode across the solenoid?  If this question doesn't make sense to you, please say so!   It is very possible to fry your electronics doing this kind of stuff if you don't account for the inductive kick.

----------


## Fri

No right now I am just trying to find a 12v out that will react to the M401 with pin64 for z probe, the solenoid is not connected, but also, no this doesn't make sense to me. I am just trying to follow this http://community.robo3d.com/index.ph...stock-r1.3864/

----------


## Roxy

This circuit does have a reverse biased diode across its solenoid!   If you follow its directions you will not cook your electronics.

----------


## Fri

Okay, thanks I got it here, but haven't put the circuit together, since it cannot find a 12v out to use. Okay, if I would have read the whole story I would have seen this.
Aux 2 63 and GND right next to it. Will try that.



Thanks for your help!

----------


## Roxy

Actually....   You don't need a '12 volt out'.    That circuit has a MOS-FET that switches the power.  You just need a 12 volt power supply.  That MOS-FET is handling all the power switching for you.    In that article there is this picture:   http://i.imgur.com/Bbs3Mmg.png

It says at the top of the picture 5 volts.   But you can connect the drain of that MOS-FET to 12 volts without any worries.  Or more accurately, VDD at the top of the diagram can be 12 volts instead of 5 volts.   That MOS-FET is being turned all the way on and all the way off.  It doesn't really care how much voltage it is switching.   You can just grab 12 volts from your power supply and feed it into that circuit instead of 5 volts.

----------


## Fri

Okay, now I think I got it.

Thanks so much

----------


## Fri

I got it all working great. One thing I got I don't know why is the M114 is not working. I am using a Ramps with a current Marlin, but the m114 command doesn't do anything. Any suggestions?

----------


## Roxy

> I got it all working great. One thing I got I don't know why is the M114 is not working. I am using a Ramps with a current Marlin, but the m114 command doesn't do anything. Any suggestions?


M114 Should always be there.   The fact it isn't responding is not good!   I think I would search Marlin_main.cpp and verify that the code is present.  It should look like:



```
axis_steps_per_unit[i] = code_value();
      }
    }
  }
}


/**
 * M114: Output current position to serial port
 */
inline void gcode_M114() {
  SERIAL_PROTOCOLPGM("X:");
  SERIAL_PROTOCOL(current_position[X_AXIS]);
  SERIAL_PROTOCOLPGM(" Y:");
  SERIAL_PROTOCOL(current_position[Y_AXIS]);
  SERIAL_PROTOCOLPGM(" Z:");
  SERIAL_PROTOCOL(current_position[Z_AXIS]);
  SERIAL_PROTOCOLPGM(" E:");
  SERIAL_PROTOCOL(current_position[E_AXIS]);


  SERIAL_PROTOCOLPGM(MSG_COUNT_X);
  SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]);
  SERIAL_PROTOCOLPGM(" Y:");
  SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]);
  SERIAL_PROTOCOLPGM(" Z:");
  SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);


  SERIAL_PROTOCOLLN("");


  #ifdef SCARA
    SERIAL_PROTOCOLPGM("SCARA Theta:");
```

----------


## Fri

The code is there, and I am not sure if it is not responding. When I home all, and then do a M114 my z should report a number other than zero, but it is always on zero. M119 and other M codes work fine.

----------


## Roxy

The M114 unconditionally prints "X:"   and the number.    M119 has this code:


```
    case 119: // M119
    SERIAL_PROTOCOLLN(MSG_M119_REPORT);
      #if defined(X_MIN_PIN) && X_MIN_PIN > -1
        SERIAL_PROTOCOLPGM(MSG_X_MIN);
        SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN))
```

If the M119 command prints that stuff correctly, it uses the same SERIAL_PROTOCOLPGM() macro.

----------


## Bluexorcist

hey im trying the same thing on my printer, i managed to get it working with the marlin firmware provided in the post but i want to use the newest version of marlin do you guys know which section i need to change in the marlin_main.cpp?  because the part that is supposed to be modified is not there 

this is what is supposed to be modified:

static void engage_z_probe(int d = 100) { //lower z probe
digitalWrite(Z_PROBE_PIN, HIGH);
delay(d);
}

----------


## Roxy

> hey im trying the same thing on my printer, i managed to get it working with the marlin firmware provided in the post but i want to use the newest version of marlin do you guys know which section i need to change in the marlin_main.cpp?  because the part that is supposed to be modified is not there 
> 
> this is what is supposed to be modified:
> 
> static void engage_z_probe(int d = 100) { //lower z probe
> digitalWrite(Z_PROBE_PIN, HIGH);
> delay(d);
> }


Check out the Debug System and the Debug Flags.   And specifically, the M111 command.   You may have what you need by turning on that option in the newer releases.

----------


## Bluexorcist

> Check out the Debug System and the Debug Flags.   And specifically, the M111 command.   You may have what you need by turning on that option in the newer releases.


where do i go to check it out?

----------


## Roxy

Go into Marlin_main.cpp and search for marlin_debug_flags   That will show you where it is set and referenced.

----------

