-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdigital_acquisition.py
63 lines (53 loc) · 2.31 KB
/
digital_acquisition.py
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
import RPi.GPIO as GPIO
import time
import csv
DEBUG_MODE=False
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 2 corresponding to 20 pin
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 5
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # 4
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #3
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 2 corresponding to 2^0 pin
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 5
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # 4
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #3
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 2 corresponding to 2^0 pin
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #arduino 5
def read_current():
val = GPIO.input(17)+GPIO.input(27)*2**1+GPIO.input(22)*2**2+GPIO.input(10)*2**3+GPIO.input(9)*2**4+GPIO.input(11)*2**5+GPIO.input(5)*2**6+GPIO.input(6)*2**7+GPIO.input(13)*2**8+GPIO.input(19)*2**9
voltage = val * (5.0 / 1023.0)
#Sensitivity of the sensor: 625 mV/Ipn. Ipn = 50A, so the slope is 12.5 mV/A
offset = 2.455 # Biased sensor
val = (voltage-offset)/0.0125
return val
def old_procedure():
try:
f = open("arduino.csv.txt", "w+")
writer = csv.writer(f)
head = ["value"]
writer.writerow(head)
while(True):
#print(GPIO.input(10))
# Get the value
val = GPIO.input(17)+GPIO.input(27)*2**1+GPIO.input(22)*2**2+GPIO.input(10)*2**3+GPIO.input(9)*2**4+GPIO.input(11)*2**5+GPIO.input(5)*2**6+GPIO.input(6)*2**7+GPIO.input(13)*2**8+GPIO.input(19)*2**9
writer.writerow(str(val))
print(str(val))
if(DEBUG_MODE):
print(GPIO.input(17))
print(GPIO.input(27))
print(GPIO.input(22))
print(GPIO.input(10))
print(GPIO.input(9))
print(GPIO.input(11))
print(GPIO.input(5))
print(GPIO.input(6))
print(GPIO.input(13))
print(GPIO.input(19))
print()
time.sleep(1)
except KeyboardInterrupt as k:
print("Keyboard: " + str(k))
except Exception as e:
print("Exception: " + str(e))
finally:
f.close()