Skip to content

Instantly share code, notes, and snippets.

@datigrezzi

datigrezzi/serial2csv.py Secret

Created Dec 3, 2018
Embed
What would you like to do?
# 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
You can’t perform that action at this time.