Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Feb 26, 2023
2 parents 288b579 + aad643b commit f68dff7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rpi_arduino/serial/serial_loop_arduino.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import serial
import numpy as np
import time
import sys


data = np.array([])
time_ms = np.array([])
i = 0

ser = serial.Serial('COM3', 9600)
welcome_message0 = ser.readline().strip().decode("utf-8")
print(welcome_message0)
welcome_message1 = ser.readline().strip().decode("utf-8")
print(welcome_message1)
time_per_point_ms = welcome_message1[20:]

while True:
try:
voltage = ser.readline().strip().decode("utf-8")

data = np.append(data, np.round(float(voltage),10))
time_ms = np.append(time_ms, int(int(time_per_point_ms)*i))

print(data)
print(time_ms)

np.save(r"C:\Users\dpean\Desktop\arduino_voltages.npy",data)
np.save(r"C:\Users\dpean\Desktop\arduino_time.npy",time_ms)
i += 1
except KeyboardInterrupt:
sys.exit()
except:
"Failed..."
i += 1

0 comments on commit f68dff7

Please sign in to comment.