Two Button Panel
We calculate the final price from your selected file. You review and accept it before payment.
Saved on this device.
Two button panel I'm using to turn a relay on and off with Octoprint.
- Rating
- 5 / 5
- Likes
- 8
- Downloads
- 48
- Makes
- 1
- Views
- 687
- Reviews
- 1
Updated at source:
Model information
- Source
- Printables
- Category
- Electronics
- License
- Creative Commons — Attribution — Noncommercial — Share Alike
EDIT - I no longer use Octoprint(PrusaConnect works great). There is a script below to just run on an Raspberry Pi.
This is a two button panel I designed for the front of my IKEA LACK enclosure to control a relay for a power strip via my Raspberry Pi running Octoprint.
Included step file for remixing button faces if desired.
Fits in 40mm x 19mm hole. Friction fit.
Uses (2) Micro Tactile Push buttons - 6x6x4.3 buttons in an assortment or separately.
This button panel triggers system commands via the Octoprint plugin Physical Button to turn the relay trigger pin on and off. I have a relay box controlling power to a power strip for fans/lights which was already setup with the Octoprint plugin PSU Control.
On: raspi-gpio set 22 dh
Off: raspi-gpio set 22 dl
To route wires in to the enclosure, I had to drill a hole up from the inside to route my wires to. Cover the front in painters tape and paper so you protect the finish while using a jigsaw to cut the hole marked with tape.
Code:#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
GPIO.cleanup() # Clean up any previous GPIO settings
Pin configuration
INPUT_PIN_1 = 37 # Physical pin 37 - I on button input
INPUT_PIN_2 = 35 # Physical pin 35 - O off button input
OUTPUT_PIN_1 = 7 # Physical pin 7 - Power Strip Relay control output
OUTPUT_PIN_2 = 33 # Physical pin 33 - LACK servo duct control output
GPIO setup
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(INPUT_PIN_1, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up resistor
GPIO.setup(INPUT_PIN_2, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up resistor
GPIO.setup(OUTPUT_PIN_1, GPIO.OUT) # Output pin
GPIO.setup(OUTPUT_PIN_2, GPIO.OUT) # Output pin
Variable to store the state of OUTPUT_PIN_1
output_pin_state = GPIO.LOW
GPIO.output(OUTPUT_PIN_1, output_pin_state) # Initialize OUTPUT_PIN_1 to LOW
GPIO.output(OUTPUT_PIN_2, output_pin_state) # Initialize OUTPUT_PIN_2 to LOW
try:
print("Press Button 1 to set OUTPUT_PIN_1 HIGH, Button 2 to set it LOW.")
while True:
# Check if Button 1 is pressed
if GPIO.input(INPUT_PIN_1) == GPIO.LOW: # Button pressed (pulled to ground)
output_pin_state = GPIO.HIGH
GPIO.output(OUTPUT_PIN_1, output_pin_state)
GPIO.output(OUTPUT_PIN_2, output_pin_state)
print("Button 1 pressed: OUTPUT_PIN_1 set to HIGH")
# Check if Button 2 is pressed
if GPIO.input(INPUT_PIN_2) == GPIO.LOW: # Button pressed (pulled to ground)
output_pin_state = GPIO.LOW
GPIO.output(OUTPUT_PIN_1, output_pin_state)
GPIO.output(OUTPUT_PIN_2, output_pin_state)
print("Button 2 pressed: OUTPUT_PIN_1 set to LOW")
time.sleep(0.1) # Small delay to reduce CPU usage
except KeyboardInterrupt:
print("Exiting program...")
finally:
GPIO.cleanup() # Reset GPIO settings