NUM_OF_SAMPLES = 1000 import serial s = serial.Serial(port="/dev/ttyACM0") def read(): data = [] for i in range(NUM_OF_SAMPLES): line = s.readline().rstrip().decode("ascii") if line != "": #line format is e.g. "measured: 4111" data.append(int(line.split(":")[1])) return data data_untouched = read() data_touched = read() s.close() plot(data_untouched) #blue plot(data_touched) #green min(data_untouched) - max(data_touched[300:-1])