-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensing.txt
89 lines (65 loc) · 2.05 KB
/
sensing.txt
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
'''
Python Algorithm Untuk Data Logger Pembacaan Tegangan dan Arus Listrik
Develop by : Made Agus Andi Gunawan
IDN Maker Space Algoritm Factory
'''
# Import Library
import csv
import random
import time
import sys
import board
import math
import busio
import adafruit_ads1x15.ads1015 as ADS
from matplotlib.animation import FuncAnimation
from adafruit_ads1x15.analog_in import AnalogIn
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Pemanggilan ADC modul I2C
ads = ADS.ADS1015(i2c)
# Variabel masukan analog A0-A3
chan1 = AnalogIn(ads, ADS.P0)
chan2 = AnalogIn(ads, ADS.P1)
# Definisi variabel
x_value = 0
tegangan1 = 0
nilai =0
tegangan2 = 0
samples = 200
# pembuatan header file CSV
fieldname = ["x_value", "tegangan 1", "tegangan 2", "teganganrms", "nilai", "bacaan"]
with open('data.csv', 'w') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldname)
csv_writer.writeheader()
# Perulangan pengambilan data sensor
while True:
try:
with open('data.csv', 'a') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldname)
count = int(0)
readVal = [0]*4
IrmsA = 0
ampsA = 0
maxValue = 0
voltage = float(0)
while count < samples:
count +=1
for i in range(0,4)
readVal= float(chan2.value)
if readVal > maxValue:
maxValue = readVal
print("max value ", maxValue)
info={
"x_value" : x_value,
"tegangan 1" : tegangan1,
}
csv_writer.writerow(info)
print(x_value, maxValue)
x_value += 1
tegangan1 = chan1.voltage
tegangan2 = chan2.voltage
nilai = chan2.value
except KeyboardInterrupt:
print('Program Dihentikan')
sys.exit()