Page 1 sur 1

Température écran LCD

Posté : ven. 30 déc. 2016 21:41
par Nanard
Bonjour,

Sur mon écran LCD j'ai réussi à mettre les données de mon capteur DHT11.
Je souhaiterais compléter mon programme ci dessous avec la température de mon processeur.
Cependant, en python je ne sais pas comment l'écrire.

Je souhaite afficher au maximum en terme de caractères :
t:40.6
J'ai un LCD 2*16 et la position serait :
(0, 13)

Code : Tout sélectionner

#!/usr/bin/python
import sys
import Adafruit_DHT


from RPLCD import CharLCD

lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23])

while True:

    humidite, temperature = Adafruit_DHT.read_retry(11, 4)

    lcd.cursor_pos = (0, 0)
    lcd.write_string("Temp: %d C" % temperature)
    lcd.cursor_pos = (1, 0)
    lcd.write_string("Humidite: %d %%" % humidite)  
 
Je vous remercie par avance !

Re: Température écran LCD

Posté : sam. 7 janv. 2017 18:30
par Nanard
Bonjour à tous,

J'ai réussi à trouver la solution à ma problématique.

Pour ceux que sa intéresse :

Code : Tout sélectionner

#!/usr/bin/python
import os
import glob
import time
import sys
import Adafruit_DHT
import subprocess

from RPLCD import CharLCD

lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23])

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '10*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

#CELSIUS CALCULATION
def read_temp_c():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = int(temp_string) / 1000.0 # TEMP_STRING IS THE SENSOR OUTPUT, MAKE SURE IT'S AN INTEGER TO DO THE MATH
        temp_c = str(round(temp_c, 1)) # ROUND THE RESULT TO 1 PLACE AFTER THE DECIMAL, THEN CONVERT IT TO A STRING
        return temp_c





while True:



    humidite, temperature = Adafruit_DHT.read_retry(11, 4)

    lcd.cursor_pos = (0, 10)
    lcd.write_string("PC:%dC" % temperature)

    lcd.cursor_pos = (1, 8)
    lcd.write_string("Hum:%d %%" % humidite)

    lcd.cursor_pos = (0, 0)
    lcd.write_string("Ext:"+read_temp_c()+"C")

    lcd.cursor_pos = (1, 0)
    t = int( subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])[5:7])
    lcd.write_string("CPU:%s" %t + "C")