Professional Documents
Culture Documents
5 SC
5 SC
pyplot as plt
import serial
import time
start_time = time.time()
try:
data = serial_port.readline().decode('utf-8').strip()
if data:
value = int(data)
values.append(value)
timestamps.append(time.time() - start_time)
ax.clear()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Value')
plt.pause(plot_interval)
except ValueError:
pass
ax.clear()
values.clear()
timestamps.clear()
start_time = time.time()
try:
data = serial_port.readline().decode('utf-8').strip()
if data:
value = int(data)
values.append(value)
timestamps.append(time.time() - start_time)
ax.clear()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Value')
plt.pause(plot_interval)
except ValueError:
pass
serial_port = serial.Serial('COM3', 9600) # Replace 'COM3' with your Arduino's serial port
fig, ax = plt.subplots()
values = []
timestamps = []
plot_interval = 0.1 # 100ms interval