-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPi_program.py
More file actions
114 lines (61 loc) · 1.74 KB
/
Pi_program.py
File metadata and controls
114 lines (61 loc) · 1.74 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import RPi.GPIO as gpio
import time
import csv
from datetime import datetime
from datetime import date
# GPIO on Pi
DT = 5
SCK= 6
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(SCK, gpio.OUT)
# output of count without connecting the load cell, can use it to tare
def readCount():
i=0
Count=0
# print Count
# time.sleep(0.001)
gpio.setup(DT, gpio.OUT)
gpio.output(DT,1)
gpio.output(SCK,0)
gpio.setup(DT, gpio.IN)
while gpio.input(DT) == 1:
i=0
for i in range(24):
gpio.output(SCK,1)
Count = Count<<1
gpio.output(SCK,0)
#time.sleep(0.001)
if gpio.input(DT) == 0:
Count=Count+1
#print Count
gpio.output(SCK,1)
Count=Count^0x800000 # xor = ^
#time.sleep(0.001)
gpio.output(SCK,0)
return Count
#### Write to csv ####\
print("Please remove anything on the weight scale: (press enter to continue)")
c = input("")
x1 = readCount()
y1 = 0
print("Please put some weight on the weight scale (kg):")
y2 = float(input(""))
x2 = readCount()
a = (y2-y1)/(x2-x1)
b = y1 - a*x1
with open('raw_data.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Date', 'Time', 'Weight'])
while 1:
curr_date = date.today()
time_now = datetime.now()
curr_time = time_now.strftime("%H:%M:%S")
count = readCount()
w = count * a + b
result = round(w, 3)
print("Weight: ", result, "kg")
filewriter.writerow([curr_date, curr_time, result])
csvfile.flush()
time.sleep(0.5)