Pages : 1
#1 Le 26/02/2019, à 15:45
- FyFlo
Projet Chronomètre Raspberry
Bonjour,
Je suis actuellement en cour de projet en entreprise.
Grâce a une carte Raspberry, mon but est de chronométrer le temps d’étuve d’un four.
Voici mon problème :
Le chronomètre se déclenche lorsque la température dépasse le seuil de 25°C puis se s’arrête lorsque la température est inférieur à 25°C et reprend son cycle lorsque que la température repasse la consigne de 25°C.
Cependant, le chrono prend en compte le temps passé en dessous du seuil de 25°C ce que ne souhaite pas, auriez vous une astuce afin de régler ce problème ?
Je vous fourni ci-dessous le programme actuel, en vous remerciant pour votre aide et pour vos réponse.
Programme :
# before import the max6675, you must save the max6675.py file at "/usr/lib/python2.7/dist-packages"
# wiring
# Raspberry MAX6675
# GND ------ GND
# 5V ------ VCC
# pin 18 ------ SCK
# pin 22 ------ CS
# pin 16 ------ SO
import random, sys, time, pygame, datetime, max6675
from pygame.locals import *
# set the pin for communicate with MAX6675
cs = 22
sck = 18
so = 16
# max6675.set_pin(CS, SCK, SO, unit) [unit : 0 - raw, 1 - Celsius, 2 - Fahrenheit]
max6675.set_pin(cs, sck, so, 1)
FPS = 30
WINDOWWIDTH = 1280
WINDOWHEIGHT = 960
FLASHSPEED = 500 # in milliseconds
FLASHDELAY = 200 # in milliseconds
BUTTONSIZE = 200
BUTTONGAPSIZE = 20
TIMEOUT = 4 # seconds before game over if no button is pushed.
# R G B
WHITE = (255, 255, 255)
BLACK = ( 0, 0, 0)
BRIGHTRED = (255, 0, 0)
RED = (155, 0, 0)
BRIGHTGREEN = ( 0, 255, 0)
GREEN = ( 0, 155, 0)
BRIGHTBLUE = ( 0, 0, 255)
BLUE = ( 0, 0, 155)
BRIGHTYELLOW = (255, 255, 0)
YELLOW = (155, 155, 0)
DARKGRAY = ( 40, 40, 40)
bgColor = BLACK
XMARGIN = int((WINDOWWIDTH - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
YMARGIN = int((WINDOWHEIGHT - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
# Rect objects for each of the four buttons
YELLOWRECT = pygame.Rect(XMARGIN, YMARGIN, BUTTONSIZE, BUTTONSIZE)
BLUERECT = pygame.Rect(XMARGIN + BUTTONSIZE + BUTTONGAPSIZE, YMARGIN, BUTTONSIZE, BUTTONSIZE)
REDRECT = pygame.Rect(XMARGIN, YMARGIN + BUTTONSIZE + BUTTONGAPSIZE, BUTTONSIZE, BUTTONSIZE)
GREENRECT = pygame.Rect(XMARGIN + BUTTONSIZE + BUTTONGAPSIZE, YMARGIN + BUTTONSIZE + BUTTONGAPSIZE, BUTTONSIZE, BUTTONSIZE)
score = 0
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT, BEEP1, BEEP2, BEEP3, BEEP4
def terminate():
pygame.quit()
sys.exit()
def checkForQuit():
for event in pygame.event.get(QUIT): # get all the QUIT events
terminate() # terminate if any QUIT events are present
for event in pygame.event.get(KEYUP): # get all the KEYUP events
if event.key == K_ESCAPE:
terminate() # terminate if the KEYUP event was for the Esc key
#pygame.event.post(event) # put the other KEYUP event objects back
pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('Contrôle du four!')
BASICFONT = pygame.font.Font('freesansbold.ttf', 16)
BASICFONT2 = pygame.font.Font('freesansbold.ttf', 32)
BASICFONT3 = pygame.font.Font('freesansbold.ttf', 64)
BASICFONT4 = pygame.font.Font('freesansbold.ttf', 96)
infoSurf = BASICFONT.render('DV GROUP V1.0', 1, YELLOW)
infoRect = infoSurf.get_rect()
infoRect.topleft = (10, WINDOWHEIGHT - 25)
date1 = 0
tempconsigne = 25
tempmem = 0
date = 0
date2 = 0
instant = 0
instant2 = "Attente"
datedepart = datetime.datetime.now()
instant1 = (str(datedepart.hour) + ':' + str(datedepart.minute)+ ':' + str(datedepart.second))
while True: # main game loop
# read temperature connected at CS 22
a = max6675.read_temp(cs)
date = datetime.datetime.now()
instant = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
if (a >= tempconsigne) and (tempmem == 0):
tempmem =1
date1 = datetime.datetime.now()
instant2 = (str(date1.hour) + ':' + str(date1.minute)+ ':' + str(date1.second))
if (a >= tempconsigne) and (tempmem == 1):
date2 = date-date1
#instant2 = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
DISPLAYSURF.fill(bgColor)
DISPLAYSURF.blit(infoSurf, infoRect)
#affichage heure
scoreSurf = BASICFONT.render('' + str(instant), 1, WHITE)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (WINDOWWIDTH - 100, WINDOWHEIGHT - 25)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affichage heure demarrage
scoreSurf = BASICFONT2.render('Heure de départ:' + str(instant1), 1, YELLOW)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (10, 0)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affichage heure temp atteind
scoreSurf = BASICFONT2.render('Heure temp ok:' + str(instant2), 1, YELLOW)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (10, 30)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affiche text temps etuvage
scoreSurf1 = BASICFONT2.render('Temps d étuvage: ', 1, RED)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 60)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche compteur temps etuvage
scoreSurf1 = BASICFONT3.render(str(date2), 1, RED)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 85)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche text temperature four
scoreSurf1 = BASICFONT2.render('Température Four', 1, BLUE)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 150)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche temperature four
scoreSurf1 = BASICFONT3.render(str(round(a,0)) + '°C', 1, BLUE)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 180)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche consigne temperature
scoreSurf1 = BASICFONT2.render('Consigne de température', 1, GREEN)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 245)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche temperature de consigne
scoreSurf1 = BASICFONT3.render(str(round(tempconsigne,0)) + '°C', 1, GREEN)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 280)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
checkForQuit()
#max6675.time.sleep(2)
pygame.display.update()
pygame.time.wait(1000)
Hors ligne
#2 Le 26/02/2019, à 17:57
- lann
Re : Projet Chronomètre Raspberry
A vue d'oeil, je dirai qu'il faut que tu stoppes le chronomètre lorsque la température repasse sous la température de 25°
if (a <= tempconsigne) and (tempmem == 1):
Sauvegarde du temps lorsque tu as dépassé les 25°
puis lorsque tu repasses de nouveau au dessus des 25°
if (a >= tempconsigne) and (tempmem == 1):
Tu mets à jour la date de relance de la température
<Modéré>
Hors ligne
#3 Le 26/02/2019, à 18:15
- pingouinux
Re : Projet Chronomètre Raspberry
Bonjour,
Remarque :
Tu peux simplifier, en remplacant
date1 = datetime.datetime.now()
instant2 = (str(date1.hour) + ':' + str(date1.minute)+ ':' + str(date1.second))
par
date1 = datetime.datetime.now()
instant2 = date1.strftime("%H:%M:%S")
Ajouté :
Et pour obtenir 20:5:3 au lieu de 20:05:03
date1 = datetime.datetime.now()
instant2 = date1.strftime("%-H:%-M:%-S")
Dernière modification par pingouinux (Le 26/02/2019, à 20:32)
Hors ligne
#4 Le 27/02/2019, à 08:29
- FyFlo
Re : Projet Chronomètre Raspberry
lann, tes deux ligne de code sont a ajouter au programme ou a remplacer ?
pingouinus, merci pour les simplifications
Hors ligne
#5 Le 27/02/2019, à 08:49
- FyFlo
Re : Projet Chronomètre Raspberry
Donc si je comprend bien, le problème viendrais donc de cette partie du code :
while True: # main game loop
# read temperature connected at CS 22
a = max6675.read_temp(cs)
date = datetime.datetime.now()
instant = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
if (a >= tempconsigne) and (tempmem == 0):
tempmem =1
date1 = datetime.datetime.now()
instant2 = (str(date1.hour) + ':' + str(date1.minute)+ ':' + str(date1.second))
if (a >= tempconsigne) and (tempmem == 1):
date2 = date-date1
#instant2 = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
Si vous pouvez me dire qu'elle ligne de code remplacer cela m'aiderai beaucoup
Merci a vous
Hors ligne
Pages : 1