| 
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -16,12 +16,15 @@ import tkinter as tk #Para la interfaz | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Variables a utilizar | 
																 | 
																 | 
																#Variables a utilizar | 
															
														
														
													
														
															
																 | 
																 | 
																global isRun #Valor booleano de programa corriendo | 
																 | 
																 | 
																global isRun #Valor booleano de programa corriendo | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																global on #Valor booleano del estatus del transistor | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																on = False #Inicializa transistor apagado | 
															
														
														
													
														
															
																 | 
																 | 
																isReceiving = False #Valor booleano de recibiendo datos | 
																 | 
																 | 
																isReceiving = False #Valor booleano de recibiendo datos | 
															
														
														
													
														
															
																 | 
																 | 
																isRun = True | 
																 | 
																 | 
																isRun = True | 
															
														
														
													
														
															
																 | 
																 | 
																dato1 = 0.0 #Variable del dato a leer desde Arduino | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																serialPort = 'COM3' #Puerto al que está conectado el Arduino | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																dato1 = 0.0 #Variable del dato convertido a float | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																serialPort = 'COM6' #Puerto al que está conectado el Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																baudRate = 9600 #Baudios configurados en Arduino | 
																 | 
																 | 
																baudRate = 9600 #Baudios configurados en Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																datos = 0.0 #Variable de dato a leer desde Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																estado = "off" #Variable de estado que se enviará al serial | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Función de lectura de datos en Arduino | 
																 | 
																 | 
																#Función de lectura de datos en Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																def leer_datos(): | 
																 | 
																 | 
																def leer_datos(): | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -32,10 +35,13 @@ def leer_datos(): | 
															
														
														
													
														
															
																 | 
																 | 
																        global isReceiving #valor booleano de recibiendo datos | 
																 | 
																 | 
																        global isReceiving #valor booleano de recibiendo datos | 
															
														
														
													
														
															
																 | 
																 | 
																        global dato1 #dato a recibir desde Arduino | 
																 | 
																 | 
																        global dato1 #dato a recibir desde Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																        print("RECIBIENDO...") | 
																 | 
																 | 
																        print("RECIBIENDO...") | 
															
														
														
													
														
															
																 | 
																 | 
																        dato1 = float(arduino.readline().decode("utf-8").strip()) #Lectura del dato y conversión a float  | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																        print(dato1) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																        var.set("TEMPERATURA: " + str(dato1) + " °C") #impresión del dato numérico en la interfaz | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																        isReceiving = True #Confirmación de que se ha recibido el dato | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        datos = arduino.readline().decode("utf-8").strip() #Lectura del dato | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        print(datos) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        if(datos != ''): #Asegurar que se haya leído un dato | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																            dato1 = float(datos) #Conversión del dato en float | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																            print(dato1) #Datos en float | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																            var.set("TEMPERATURA: " + str(dato1) + " °C") #impresión del dato numérico en la interfaz | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																            isReceiving = True #Confirmación de que se ha recibido el dato | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Función para iniciar la gráfica | 
																 | 
																 | 
																#Función para iniciar la gráfica | 
															
														
														
													
														
															
																 | 
																 | 
																def iniciarGrafica(self, muestras,lines): | 
																 | 
																 | 
																def iniciarGrafica(self, muestras,lines): | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -48,11 +54,12 @@ def conectar_serial(): | 
															
														
														
													
														
															
																 | 
																 | 
																    global arduino #Variable que va aguardar la conexión | 
																 | 
																 | 
																    global arduino #Variable que va aguardar la conexión | 
															
														
														
													
														
															
																 | 
																 | 
																    try: | 
																 | 
																 | 
																    try: | 
															
														
														
													
														
															
																 | 
																 | 
																        arduino = serial.Serial(serialPort, baudRate) #Asignación del objeto a la variable | 
																 | 
																 | 
																        arduino = serial.Serial(serialPort, baudRate) #Asignación del objeto a la variable | 
															
														
														
													
														
															
																 | 
																 | 
																        arduino.timeout = 0.5 #Tiempo a esperar para que haya datos disponibles en el puerto serie  | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        arduino.timeout = 0.1 #Tiempo a esperar para que haya datos disponibles en el puerto serie  | 
															
														
														
													
														
															
																 | 
																 | 
																        time.sleep(0.5) #Tiempo muerto para permitir la conexión | 
																 | 
																 | 
																        time.sleep(0.5) #Tiempo muerto para permitir la conexión | 
															
														
														
													
														
															
																 | 
																 | 
																        print("CONECTADO") | 
																 | 
																 | 
																        print("CONECTADO") | 
															
														
														
													
														
															
																 | 
																 | 
																        btnStart.config(state = "normal") | 
																 | 
																 | 
																        btnStart.config(state = "normal") | 
															
														
														
													
														
															
																 | 
																 | 
																        btnConectar.config(state = "disabled") | 
																 | 
																 | 
																        btnConectar.config(state = "disabled") | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        btnManual.config(state = "normal") | 
															
														
														
													
														
															
																 | 
																 | 
																    except: | 
																 | 
																 | 
																    except: | 
															
														
														
													
														
															
																 | 
																 | 
																        print("Error de conexión") | 
																 | 
																 | 
																        print("Error de conexión") | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -68,19 +75,28 @@ def iniciar_hilo(): | 
															
														
														
													
														
															
																 | 
																 | 
																def guardarGrafica(): | 
																 | 
																 | 
																def guardarGrafica(): | 
															
														
														
													
														
															
																 | 
																 | 
																    plt.savefig('miFigura.png') | 
																 | 
																 | 
																    plt.savefig('miFigura.png') | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Ventana de control Manual (ON/OFF controlado por el usuario) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#Función de control Manual (ON/OFF controlado por el usuario) | 
															
														
														
													
														
															
																 | 
																 | 
																def control1(): | 
																 | 
																 | 
																def control1(): | 
															
														
														
													
														
															
																 | 
																 | 
																    window2 = tk.Toplevel() | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window2.resizable(width = 0, height = 0) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window2.title('Control Manual') | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window2.geometry('500x300') | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    global on | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    global estado | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    global arduino | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    if on == False: #Cuando el transistor está apagado | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        on = True #Cambia la variable de condición | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        btnManual.config(bg = "#55DE1E", text = "ON") #Cambia color y texto del botón | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        estado = "on" #cambia la variable de estado | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        arduino.write(estado.encode()) #Se envía encender al serial de Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																    else: #Cuando el transistor está encendido | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        on = False #Cambia la variable de condición | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        btnManual.config(bg = "red", text = "OFF") #Cambia color y texto del botón | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        estado = "off" #Cambia la variable de estado | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																        arduino.write(estado.encode()) #Se envía apagar al serial de Arduino | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Ventana para control según una temperatura dada (Automático) | 
																 | 
																 | 
																#Ventana para control según una temperatura dada (Automático) | 
															
														
														
													
														
															
																 | 
																 | 
																def control2(): | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window3 = tk.Toplevel() | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window3.resizable(width = 0, height = 0) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window3.title('Control ON/OFF') | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																    window3.geometry('500x300') | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#def control2(): | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#    window3 = tk.Toplevel() | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#    window3.resizable(width = 0, height = 0) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#    window3.title('Control ON/OFF') | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#    window3.geometry('500x300') | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Función para pausar la gráfica | 
																 | 
																 | 
																#Función para pausar la gráfica | 
															
														
														
													
														
															
																 | 
																 | 
																def pausar(): | 
																 | 
																 | 
																def pausar(): | 
															
														
														
													
												
													
														
															
																| 
																	
																		
																			
																		
																	
																	
																		
																			
																		
																	
																	
																 | 
																@ -137,10 +153,14 @@ root.rowconfigure(3, weigh=5) | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																canvas = FigureCanvasTkAgg(fig, master=frame) | 
																 | 
																 | 
																canvas = FigureCanvasTkAgg(fig, master=frame) | 
															
														
														
													
														
															
																 | 
																 | 
																canvas.get_tk_widget().pack(padx=0, pady=0, expand=True, fill='both')  | 
																 | 
																 | 
																canvas.get_tk_widget().pack(padx=0, pady=0, expand=True, fill='both')  | 
															
														
														
													
														
															
																 | 
																 | 
																btnManual = tk.Button(frame2, text = "Manual", command = control1) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																btnManual.grid(row=0, column=0, pady=2, padx=10) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																btnOnOff = tk.Button(frame2, text = "ON/OFF", command = control2) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																btnOnOff.grid(row=0, column=1, pady=2, padx=10) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																labelBlank = tk.Label(frame1, text="") | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																labelBlank.grid(row=0, column=4, pady=2, padx=155) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																btnManual = tk.Button(frame1, text = "OFF", command = control1, bg = "red", state = "disabled") | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																btnManual.grid(row=0, column=6, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																labelState = tk.Label(frame1, text="Transistor State:") | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																labelState.grid(row=0, column=5, pady=2, padx=5) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#btnOnOff = tk.Button(frame2, text = "ON/OFF", command = control2) | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																#btnOnOff.grid(row=0, column=1, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																btnConectar = tk.Button(frame1, text = "Connect", command = conectar_serial, bg="#00F1FC") | 
																 | 
																 | 
																btnConectar = tk.Button(frame1, text = "Connect", command = conectar_serial, bg="#00F1FC") | 
															
														
														
													
														
															
																 | 
																 | 
																btnConectar.grid(row=0, column=0, pady=2, padx=10) | 
																 | 
																 | 
																btnConectar.grid(row=0, column=0, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																btnStart = tk.Button(frame1, text = "Start", command = iniciar_hilo, bg="#008C17", state="disabled") | 
																 | 
																 | 
																btnStart = tk.Button(frame1, text = "Start", command = iniciar_hilo, bg="#008C17", state="disabled") | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -150,7 +170,7 @@ btnPause.grid(row=0, column=2, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																btnResume = tk.Button(frame1, text = "Resume", command = reanudar, bg="#00F428", state="disabled") | 
																 | 
																 | 
																btnResume = tk.Button(frame1, text = "Resume", command = reanudar, bg="#00F428", state="disabled") | 
															
														
														
													
														
															
																 | 
																 | 
																btnResume.grid(row=0, column=3, pady=2, padx=10) | 
																 | 
																 | 
																btnResume.grid(row=0, column=3, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																btnDesconectar = tk.Button(frame2, text='Disconnect', command = desconectar_serial, bg="#FE5E5E") | 
																 | 
																 | 
																btnDesconectar = tk.Button(frame2, text='Disconnect', command = desconectar_serial, bg="#FE5E5E") | 
															
														
														
													
														
															
																 | 
																 | 
																btnDesconectar.grid(row=0, column=3, pady=2, padx=10) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																btnDesconectar.grid(row=0, column=0, pady=2, padx=10) | 
															
														
														
													
														
															
																 | 
																 | 
																labelData = tk.Label(frame2, textvariable=var) | 
																 | 
																 | 
																labelData = tk.Label(frame2, textvariable=var) | 
															
														
														
													
														
															
																 | 
																 | 
																labelData.grid(row=0, column=4, pady=2, padx=500) | 
																 | 
																 | 
																labelData.grid(row=0, column=4, pady=2, padx=500) | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																		
																			
																		
																	
																 | 
																@ -161,7 +181,7 @@ barraMenu.add_cascade(label="Archivo", menu=barra1) | 
															
														
														
													
														
															
																 | 
																 | 
																root.config(menu=barraMenu) | 
																 | 
																 | 
																root.config(menu=barraMenu) | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																#Animación de la gráfica (figura, función que grafica la línea, argumentos para graficar, rango de la figura) | 
																 | 
																 | 
																#Animación de la gráfica (figura, función que grafica la línea, argumentos para graficar, rango de la figura) | 
															
														
														
													
														
															
																 | 
																 | 
																anim = animation.FuncAnimation(fig, iniciarGrafica, fargs=(muestras, lines), interval = tiempoMuestreo) | 
																 | 
																 | 
																 | 
															
														
														
													
														
															
																 | 
																 | 
																 | 
																 | 
																 | 
																anim = animation.FuncAnimation(fig, iniciarGrafica, fargs=(muestras, lines), interval = tiempoMuestreo, cache_frame_data=False) | 
															
														
														
													
														
															
																 | 
																 | 
																
 | 
																 | 
																 | 
																
 | 
															
														
														
													
														
															
																 | 
																 | 
																root.geometry('1000x600') | 
																 | 
																 | 
																root.geometry('1000x600') | 
															
														
														
													
														
															
																 | 
																 | 
																root.mainloop() | 
																 | 
																 | 
																root.mainloop() | 
															
														
														
													
												
													
														
															
																| 
																	
																	
																	
																 | 
																
  |