#!/usr/bin/env python3 ######################################################################## # Filename : I2CLCD1602.py # Description : Use the LCD display data # Author : freenove # modification: 2018/08/03 ######################################################################## from PCF8574 import PCF8574_GPIO from Adafruit_LCD1602 import Adafruit_CharLCD from time import sleep, strftime from datetime import datetime import RPi.GPIO as GPIO import time #from os import path import os GPIO.setmode(GPIO.BCM) jecris = 0 LEDV = 17 #LEDR = 13 INPT = 18 INPT2 = 23 from datetime import datetime datetime.now() GPIO.setwarnings(False) appui = True tutu=0 global tito tito=("eee") global titoa titoa=("eee") now = datetime.now() PCF8574_address = 0x27 # I2C address of the PCF8574 chip. PCF8574A_address = 0x3F # I2C address of the PCF8574A chip. # Create PCF8574 GPIO adapter. if os.path.isfile('/media/pi/8Elise/MonFichier.txt') == False : f = open('/media/pi/8Elise/MonFichier.txt','w') def temp_ref1() : now = datetime.now() heure = now.strftime('%Y-%m-%d %H:%M:%S.%f') virgule() global secon_ref1 secon_ref1 = (int (now.strftime('%M') )* 60)+(int (now.strftime('%S')))+tutu print (secon_ref1) print (heure) def temp_ref2() : now = datetime.now() heure = now.strftime('%Y-%m-%d %H:%M:%S.%f') virgule() global secon_ref2 secon_ref2 = (int (now.strftime('%M') )* 60)+(int (now.strftime('%S')))+tutu print (secon_ref2) print (heure) def temp_ecoul1() : now = datetime.now() heure = now.strftime('%Y-%m-%d %H:%M:%S.%f') virgule() global seco1 seco1 = (int (now.strftime('%M') )* 60)+(int (now.strftime('%S')))+tutu print (seco1) print (heure) def temp_ecoul2() : now = datetime.now() heure = now.strftime('%Y-%m-%d %H:%M:%S.%f') virgule() global seco2 print (seco2) print (heure) def jecri() : global f f = open('/media/pi/8Elise/MonFichier.txt','a') jecris = 0 f.write(tito +'\n') def virgule(): now = datetime.now() toto = now.strftime('%S.%f') print(now.strftime('%S.%f')) titi = int( (toto[3:9])) global tutu tutu=titi/1000000 print (tutu) def get_cpu_temp(): # get CPU temperature and store it into file "/sys/class/thermal/thermal_zone0/temp" tmp = open('/sys/class/thermal/thermal_zone0/temp') cpu = tmp.read() tmp.close() return '{:.2f}'.format( float(cpu)/1000 ) + ' C' def get_time_now(): # get system time return datetime.now().strftime(' %H:%M:%S') def loop(): mcp.output(3,1) # turn on LCD backlight lcd.begin(16,2) # set number of LCD lines and columns global titoa while titoa == ('eee'): #lcd.clear() lcd.setCursor(0,0) # set cursor position lcd.message( 'CPU: ' + get_cpu_temp()+' '+'\n' )# display CPU temperature lcd.message( get_time_now() ) # display the time sleep(1) lcd.setCursor(0,0) # set cursor position #lcd.message( 'ce que je veux'+'\n' )# display CPU temperature lcd.message( str((3600/(seco1-secon_ref1)))+'\n' )# display CPU temperature lcd.message( get_time_now() ) # display the time sleep(1) titoa = ('rrr') def destroy(): lcd.clear() virgule() secon_ref1 = (int (now.strftime('%M') )* 60)+(int (now.strftime('%S')))+tutu secon_ref2 = secon_ref1 seco1 = secon_ref1 seco2 = secon_ref1 temp_ref1() temp_ref2() print('robert') jecri() GPIO.setup(LEDV, GPIO.OUT) GPIO.output(LEDV, False) GPIO.setup(INPT, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(INPT2, GPIO.IN, pull_up_down=GPIO.PUD_UP) COMPTEUR1 = 0 COMPTEUR2 = 0 try: mcp = PCF8574_GPIO(PCF8574_address) except: try: mcp = PCF8574_GPIO(PCF8574A_address) except: print ('I2C Address Error !') exit(1) lcd = Adafruit_CharLCD(pin_rs=0, pin_e=2, pins_db=[4,5,6,7], GPIO=mcp) loop() while appui: if GPIO.input(INPT)==0: temp_ecoul1() COMPTEUR1 += 1 print (str(COMPTEUR1)+" 1 ") print(" watt produit : " + str((3600/(seco1-secon_ref1)))) f.write(" watt produit : "+str((3600/(seco1-secon_ref1)))+'\n') loop() time.sleep(0.36) temp_ref1() jecris += 1 if (jecris > 10): f.close() jecri() titoa = ('eee') #appui = False #loop() # Create LCD, passing in MCP GPIO adapter. if GPIO.input(INPT2)==0: temp_ecoul2() COMPTEUR2 += 1 print (str(COMPTEUR2) +" 2 ") print(" watt conso : "+str((3600/(seco2-secon_ref2)))) tito =" watt conso : "+str(round(3600/(seco2-secon_ref2),2)) time.sleep(0.36) temp_ref2() jecris +=1 if (jecris >10): f.close() jecri() titoa = ('eee') # f.close() if __name__ == '__main__': print ('Program is starting ... ') try: loop() except KeyboardInterrupt: destroy()