On/Off Button mount for Makerselect v2/wanhao duplicator. by mkanoap 3d model
Warning. This content is not moderated and could be offensive.
m4
3dmdb logo
Thingiverse
On/Off Button mount for Makerselect v2/wanhao duplicator. by mkanoap

On/Off Button mount for Makerselect v2/wanhao duplicator. by mkanoap

by Thingiverse
Last crawled date: 3 years, 1 month ago
I have my monoprice Maker select v2 printer connected via a relay as described in thing 1428478 so I can turn it on and off remotely from octoprint. This is great, but I wanted a local way to turn it on or off without having to use a browser or the power switch. Turning it off via the power switch means that it can't be turned back on via octoprint, and turning it off via octoprint means it can't be turned back on with the power switch.
So I designed the button mount to attach a push button switch to the side of the printer. The button is wired to the raspberry pi to provide another input that can be used to trigger a script to toggle the printer state.
It screws into the two screws near the top on the right side. You will need two (2) M3 screws at least 8mm long to replace the short screws. I used 10mm screws left over from the z-brace mod. You will also need a push button with a shaft no wider than 16mm and a collar/nut between 16mm and 25mm. I pulled my button from my collection, but it was like this one from adafruit.
Those two screws hold the top brace in place, so I would take care to never remove them both at once.
Installation instructions
Solder two wires to the switch.
Measure and cut wires to desired length, adding an inch or two for routing via the channel in the bottom of the button holder.
Thread button switch into large hole on button holder, and secure with the nut that comes with the switch.
Unscrew the top screw from the printer.
Secure the top of the holder to the printer using a longer M3 screw to replace the one you took out. Tighten it enough to secure the printer, but still let the button holder swivel.
Remove the second short screw.
Route the wires in the channel on the button holder and swivel the holder until the bottom hole lines up.
Screw the second longer screw to the bottom hole.
Making sure that the wires are coming out of the channel and are not pinched, tighten down both screws.
Connect other end of the wires to your Raspberry pi or whatever the switch is going to control. I used Pin 26 and Ground
software setup
I already had scripts to start or stop the printer by toggling pin 19 of the raspberry pi which was connected to the relay, as described in jeffeb3's thing 1428478. Now I needed to read the pin I wired up (pin 26, paradoxically right by pin 19) and toggle the printer state. Here is how I did it, adjust these steps to match your setup:
I made the following script to read pin 19 and toogle the power state. It runs the same scripts that octoprint does to power the printer on or off. That way if I choose to change the behavior of one of them, the toggle script will pick up the change.
#!/bin/bash
state=`gpio -g read 19`
echo "state is $state"
if [ "$state" -eq "0" ]
then
/home/pi/scripts/printer_on.sh
echo "turning printer on"
else
/home/pi/scripts/printer_off.sh
echo "turning printer off"
fi
Once I had verified that this worked, I had to trigger it whenever the button shorts the button pin (26 in my case) to ground.
Configure the pin to be input -- gpio export 26 in
Configure the internal pullup resistor, so it reads 1 when the button is NOT pressed -- gpio mode 26 up
Test to see if the button works by reading the pin with the button pressed and not pressed -- gpio read 26
To watch the pin I downloaded and compiled gpio-watch program. gpio-watch has a mode where it will watch for a rising edge (transition from 0 to 1) and "debounce" the signal by waiting to see if the signal stays the same before showing the change. This is to keep the button from triggering multiple times during the transition between the switch being fully engaged and disengaged. The debounce time the software is compiled with was inadequate on my raspberry pi 3, I had to increase it several times before it reliably triggered only once per button press.
dowload the zip file and expand it
Edit "main.c" and change the line that says #define DEBOUNCE_INTERVAL 100000L to #define DEBOUNCE_INTERVAL 100000000L (or whatever value works for you).
Compile the software -- make
install it -- sudo make install
After gpio-watch is configured to watch a pin, it will run a script with the same name as a pin in /etc/gpio-watch. So in my case, it runs /etc/gpio-watch/26.
#!/bin/sh
#echo "Something happened! Pin=$1, value=$2"
/home/pi/scripts/printer_toggle.sh
After that script is in place, you can test it with gpio-watch 26:switch. Note that this will only work if you have configured the pin as detailed above.
Finally, you have to set the pi to set up the pins at startup and to run the gpio-watch process in the background. Add this to rc.local:
/usr/bin/gpio export 26 in
/usr/bin/gpio mode 26 up
/usr/bin/gpio-watch 26:switch &
Now enjoy turning your printer on and off with the press of a button, while still being able to control it from octoprint.

Tags