-
-
Save datigrezzi/f703de92e903c922a2e9d3890e09e41d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script to read data from serial port (typically sent by Arduino) | |
# The print it in terminal and save it to a csv file | |
# Iyad Aldaqre | |
# 24.11.2018 | |
import serial | |
import time | |
import csv | |
device = '/dev/cu.usbmodem14101' | |
ser = serial.Serial(device, 9600) | |
print("Connection successful with:", device) | |
gsr_list = [] | |
startTime = time.time() | |
print("Recording gsr data...") | |
print("Press Ctrl + c to stop") | |
try: | |
while True: | |
currentTime = time.time() - startTime | |
gsr_list.append([currentTime, ser.readline()]) | |
except KeyboardInterrupt: | |
if len(gsr_list) > 0: | |
with open('serial_data.csv', 'w') as f: | |
w = csv.writer(f, delimiter=";") | |
w.writerow(['ts','gsr']) # header | |
for row in gsr_list: # iterate all items | |
w.writerow(row) # write row in csv | |
print("\nSaved gsr data successful") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment