-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitalino_test.py
executable file
·51 lines (41 loc) · 1.08 KB
/
bitalino_test.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
import time
import asyncio
import pandas as pd
from bitalino import BITalino
from pathlib import Path
import matplotlib.pyplot as plt
from tqdm import tqdm
import numpy as np
macAddress = "98:D3:81:FD:61:E3"
running_time = 20
batteryThreshold = 30
acqChannels = [0, 1, 2, 3, 4, 5]
samplingRate = 100
nSamples = 100
def main():
device = BITalino(macAddress)
device.battery(batteryThreshold)
print(device.version())
device.start(samplingRate, acqChannels)
start = time.time()
end = time.time()
samples = []
try:
while True:
# Read samples
data = device.read(nSamples)
for row in data:
samples.append(row)
print(data[-1])
print("> ", int(end - start), end=" | ")
end = time.time()
except KeyboardInterrupt:
print("Exiting")
finally:
# Stop acquisition
device.stop()
# Close connection
device.close()
pd.DataFrame(samples).to_csv(Path(__file__).parent / f"recording_{start}.csv")
if __name__ == "__main__":
main()