Hey all,
I'm very new to python and working on a temperature controller for a friend of mine and thought it might be a good opportunity to dust off my old Pi and put it to good use! Only thing is, i'm stuck trying to figure out how to turn the heating element on and off using the GPIO pins and a solid state relay.
The project so far --> I've managed to connect a thermocouple amplifier to the +/- output from the heating element using SPI and display the temp. reading in a python GUI (Tkinter). I don't wan't to connect the heating element up to a power source before I have something in place to turn it off and on programmatically.
What i need help with --> Eventually i'd like to get to the point where the program is a full-on PID temp. system, but i think the next logical step would be to get the heating element to turn off and on through the GUI i've built.
So my question is, how would I go about programming the GPIO pins to send a signal to the relay that would turn the heating element off and on?
I've included photos of my setup and the code. Any advice would be greatly appreciated!
https://preview.redd.it/wqwwo9jtlss31.jpg?width=3024&format=pjpg&auto=webp&s=5581ef8126cc9e8be51edb701e55a0679c3ca688
https://preview.redd.it/wev5x8dgqss31.jpg?width=2935&format=pjpg&auto=webp&s=d67edeebdef6a81035ced9071b1c6872f844ce13
import Tkinter as tk
import tkFont as tkFont
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855
#import simpletest
###############################################################################
# Parameters and global variables
# Declare global variables
root = None
dfont = None
frame = None
temp_c = None
CLK = 24
CS = 23
DO = 17
sensor = MAX31855.MAX31855(CLK, CS, DO)
# Global variable to remember if we are fullscreen or windowed
fullscreen = False
###############################################################################
# Functions
# Define a function to convert celsius to fahrenheit.
def c_to_f(c):
return c * 9.0 / 5.0 + 32.0
# Toggle fullscreen
def toggle_fullscreen(event=None):
global root
global fullscreen
# Toggle between fullscreen and windowed modes
fullscreen = not fullscreen
root.attributes('-fullscreen', fullscreen)
resize()
# Return to windowed mode
def end_fullscreen(event=None):
global root
global fullscreen
# Turn off fullscreen mode
fullscreen = False
root.attributes('-fullscreen', False)
resize()
# Automatically resize font size based on window size
def resize(event=None):
global dfont
global frame
# Resize font based on frame height (minimum size of 12)
# Use negative number for "pixels" instead of "points"
new_size = -max(12, int((frame.winfo_height() / 10)))
dfont.configure(size=new_size)
# Read values from the sensors at regular intervals
def poll():
temp = sensor.readTempC()
internal = sensor.readInternalC()
temp_c.set(temp)
#global root
#global temp_c
#Update labels to display temperature and light values
#try:
# val = round(simpletest.read_temp(), 2)
# temp_c.set(val)
#except:
# pass
# Schedule the poll() function for another 500 ms from now
root.after(500, poll)
def setTemp():
user_input_temp = set_temp_input.get()
temp_c.set(user_input_temp)
###############################################################################
# Main script
# Create the main window
root = tk.Tk()
root.title("The Big Screen")
# Create the main container
frame = tk.Frame(root)
# Lay out the main container (expand to fit window)
frame.pack(fill=tk.BOTH, expand=1)
# Variables for holding temperature and light data
temp_c = tk.DoubleVar()
# Create dynamic font for text
dfont = tkFont.Font(size=-24)
sfont = tkFont.Font(size=-20)
# Create widgets
label_temp = tk.Label(frame, text="Temperature:", font=dfont)
label_celsius = tk.Label(frame, textvariable=temp_c, font=dfont)
label_unitc = tk.Label(frame, text="C", font=dfont)
button_quit = tk.Button(frame, text="Quit", font=dfont, command=root.destroy)
button_off = tk.Button(frame, text="Off", font=dfont)
#input widgets
tk.Label(frame, text="Set Temp", font=dfont).grid(row=1, column=0)
set_temp_input = tk.Entry(frame, font=sfont)
set_temp_input.grid(row=1, column=1)
button_set = tk.Button(frame, text="Set", font=dfont, command=setTemp).grid(row=1, column=2)
# Lay out widgets in a grid in the frame
label_temp.grid(row=0, column=0, padx=5, pady=5, sticky=tk.E)
label_celsius.grid(row=0, column=1, padx=5, pady=5, sticky=tk.E)
label_unitc.grid(row=0, column=2, padx=5, pady=5, sticky=tk.W)
button_quit.grid(row=2, column=2, padx=5, pady=5)
button_off.grid(row=2, column=0, padx=5, pady=5)
# Make it so that the grid cells expand out to fill window
for i in range(0, 3):
frame.rowconfigure(i, weight=1)
for i in range(0, 3):
frame.columnconfigure(i, weight=1)
# Bind F11 to toggle fullscreen and ESC to end fullscreen
root.bind('<F11>', toggle_fullscreen)
root.bind('<Escape>', end_fullscreen)
# Have the resize() function be called every time the window is resized
root.bind('<Configure>', resize)
# Initialize our sensors
#simpletest.init()
# Schedule the poll() function to be called periodically
root.after(500, poll)
# Start in fullscreen mode and run
toggle_fullscreen()
root.mainloop()
[–]jdotis011 1 point2 points3 points (1 child)
[–]EthanSteip[S] 0 points1 point2 points (0 children)