From b9718589aed96029d2b90b1946c610d94ed9670b Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Thu, 11 Feb 2021 15:01:29 +0100 Subject: [PATCH] =?UTF-8?q?finallement=20c=E2=80=99est=20rpi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projet_bière/main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 projet_bière/main.py diff --git a/projet_bière/main.py b/projet_bière/main.py new file mode 100644 index 0000000..0a3ad77 --- /dev/null +++ b/projet_bière/main.py @@ -0,0 +1,35 @@ +import os +import glob +import time + +# On active le capeteur dans le système +os.system('modprobe w1-gpio') +os.system('modprobe w1-therm') + +# On trouve où sont les valeurs du capteurs +dossier_base = '/sys/bus/w1/devices/' +dossier_capteur = glob.glob(base_dir + '28*')[0] +fichier_capteur = dossier_capteur + '/w1_slave' + +def lecture_temp_brute(): + """Cette fonction retourne la valeur du capteur sans traitement""" + with open(fichier_capteur, 'r') as f: + lines = f.readlines() + return lines + +def lecture_temp(): + """Cette fonction calcule la température à partir des mesures brutes""" + lines = lecture_temp_brute() + while lines[0].strip()[-3:] != 'YES': + time.sleep(0.2) + lines = lecture_temp_brute() + equals_pos = lines[1].find('t=') + if equals_pos != -1: + temp_string = lines[1][equals_pos+2:] + temp_c = float(temp_string) / 1000.0 + return temp_c + +# Programme principal +while True: + print(read_temp()) + time.sleep(1)