-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFND.py
More file actions
95 lines (76 loc) · 2.14 KB
/
FND.py
File metadata and controls
95 lines (76 loc) · 2.14 KB
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
# -*- coding:utf-8 -*-
#FND.py
import smbus
import time
import threading
bus = smbus.SMBus(1)
#FND configuration
addr_fnd = 0x20
config_port = 0x06
out_port = 0x02
data_fnd = (0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0x3E, 0xE0, 0xFE, 0xF6, 0x01,0x02,0x1A)
digit = (0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB)
out_disp = 0
#Temp/Humi configuration
addr_temp = 0x40
cmd_temp = 0xf3
soft_reset = 0xfe
ns_new = ""
stop = 0
def temp_read():
temp = 0.0
val = 0
data = [0, 0]
bus.write_byte(addr_temp, soft_reset)
time.sleep(0.05)
#temperature
bus.write_byte(addr_temp, cmd_temp)
time.sleep(0.260)
for i in range(0,2,1):
data[i] = bus.read_byte(addr_temp)
val = data[0] << 8 | data[1]
temp = -46.85 + 175.72 / 65536 * val
print ('temp : %.2f' %(temp))
tp = str(temp)
if (tp[1] != '.'):
return tp[0:2]+tp[3:5]
else:
return '0'+tp[0]+tp[2:4]
def fnd_disp():
ns_new = temp_read()
while (ns_new == ""):
time.sleep(0)
bus.write_word_data(addr_fnd, config_port, 0x0000)
while (ns_new != ""):
#ns_new = temp_read()
while True:
#ns_new = temp_read()
for i in range(0,len(ns_new),1):
if (ns_new[i] == '-'):
out_disp = data_fnd[11] << 8 | digit[0]
bus.write_word_data(addr_fnd, out_port, out_disp)
# notation of dot(.)
out_disp = data_fnd[10] << 8 | digit[1]
bus.write_word_data(addr_fnd, out_port, out_disp)
n = int(ns_new[i])
out_disp = data_fnd[n] << 8 | digit[i]
bus.write_word_data(addr_fnd, out_port, out_disp)
time.sleep(0.01)
#ns_new = temp_read()
if (stop == 1):
break
def doFND():
try:
#th = threading.Thread(target=fnd_disp)
#th.start()
while True:
ns_new = temp_read()
if ns_new != "":
fnd_disp()
except KeyboardInterrupt:
stop = 1
pass
finally:
pass
#if __name__ == '__main__':
# doFND()