Current sensor to help with 3D printer nozzle crashing
I am looking for some help with integrating a current sensor with a stepper motor. The goal is to stop or mitigate damage when the nozzle of a 3D printer crashes into the print bed. The idea is that when the stepper motor encounters a greater resistance, the current draw increases. If there were a way to detect this and cut the power, it may eliminate or reduce damage caused when the nozzle tries to go lower than the print bed.
Any one interested in helping with the project?
I'm not sure how you plan on doing this. Most (if not all) 3D printers will home and not allow it to go past the value of 0 on your Z axis. The only problem would be if the bed is not leveled properly. If that is the case then the Z gantry will most likely be in place when it strikes the bed(ie X and Y move into it).
You should be able to use a proximity sensor close to your nozzle. That's what I use as my stop for Z axis and it is programmed that when it homes it takes 9 positions and lets me know if the bed is not leveled or I can tell it to print by adjusting the Z to compensate(I don't ever do that).
I am using a capacitive type bed leveling sensor. The problem is it replaced the stock end switch, and if something goes wrong it may (does) lose the bed height. For example, every time I flash the main board the z-offset value is lost. If (when) I forget and send a G28 home command before updating z-offset the nozzle will attempt to hammer through the glass bed. By detecting an increased current draw on the z-axis stepper motor, which will only happen if the nozzle tries to go through the glass, I can interrupt the gcode with an emergency stop with an M112 command.
I hope this clarifies the goal I am after.
What printer and what firmware? Are you by chance running Marlin? Because if it is set up right, the sensor should still stop your Z axis no matter what. You might be able to upload the default value you want from your IDE to prevent this. If you have an offset, there might be a place to insert it into the code. I'm assuming this is the offset that is stored in your EEPROM. Besides, how often do you have to flash the control board? I think I've only done mine once a long time ago and haven't needed to change it since. This just seems really odd.
If you look up current sensors for arduino you should find a bunch of sensors. I don't know how you plan on sending the command to the printer though. Many printers will finish it's current command before it executes a new one sent to it. That would mean it would be too late. You would have to have an interrupt but I don't know how your setting up the printer so I don't know if you can. I would test it out without the glass and with a piece of sacrificial wood or scrap PLA.
Ideally the solution would be printer agnostic and perhaps even firmware as well. You have a good point about the gcode "buffer", so perhaps controlling a relay would be a better way to go.
As to how ofen do I flash, probably more than average. I had to replace the main board, adding ABL, then there was the update to Marlin. And... I test any optimization changes indivually and sequentially. Eventually I can expect greater stability, at the same time I do love to tinker.
Additionally, I would like to experiment with different sensors and have a solid failsafe.
All the best,
Typically the way you detect current in a line like this is with a very small resistor value (single to double digits in MILLI-ohms) in series with your stepper, then measure the differential voltage across this resistor to get your current via I = R/V. This is often too small to measure directly from a microcontroller, so it's fed through an opamp or otherwise amplified to get a detectable signal. Also note that this is a small enough resistance that a "piece of wire" may be a suitable resistor.
The more typical solution in the 3d printing world is to add encoders to the steppers and provide that input back to your controller. In this case maybe you could toss an encoder onto the z-screw independently of the motor.
"A resistor makes a lightbulb and a capacitor makes an explosion when connected wrong"
"There are two types of electrical engineers, those intentionally making antennas and those accidentally doing so."
Measuring current on all the phases of the Z stepper motor and try to determine if there an over current condition may get complicated. As I'm sure you are aware there are now stepper drivers for 3D printers that are much quieter than older versions. The method used to make the stepper move quietly will give driver current profiles much different than older versions.
It may be easier to place an additional limit switch on the Z axis that will deactivate power to the Z stepped when the head reaches the print bed. The adjustment of the of the added limit switch would be the most challenging aspect of this approach, but given its simplicity and that it could be added to any printer might make it worth considering.
Actually I like the idea of using the stock end-stop as a fail safe. I don't mind spending time calibrating it. How would I wire that in? The ABL has two wiress so, in parallel? Perhaps with a diode to prevent any cross-talk or feedback? I'm a novice with electronics, so I appreciate the help.
If you are using a capacitive sensor, assuming you are not changing its position, you can always use that. Tap the signal off to go to the micro you want to use and have the correct value saved in it. Assuming your printer sees a lower number as being closer to the bed, maybe you could pull its signal to ground and the printer would automatically stop(I do not know if this can be done without ruining anything, but I doubt it would and it sounds really good in my head). That is assuming it is analogue, digital signal would probably have to be intercepted and then relayed. Interception I would not recommend as there could be a delay and affect the actual printing and homing. That would also take care of you interfacing and kill command issue.
Either way, if you find out what values are being sent, you could either do what I suggested or use that to implement the limit switch that Ruplicator suggested. The only problem I can see with this is that the bed level could change and the limit switch would not line up. Because you changed the way the printer homes the Z axis when you installed the sensor, you would have to find a way to make it home to the limit switch first then level your bed and then set the correct value for you sensor. Also, if your bed isn't perfectly leveled for some reason it would move X or Y and scrape into it if you only kill power to the Z motors.