1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| #!/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() |
Partager