arduino:pms5003
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| arduino:pms5003 [2020/11/30 21:52] – created aistis | arduino:pms5003 [2020/12/14 22:29] (current) – aistis | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| {{: | {{: | ||
| + | <code python> | ||
| + | import serial | ||
| + | import matplotlib.pyplot as plt | ||
| + | import numpy as np | ||
| + | from struct import unpack | ||
| + | s = serial.Serial(port=' | ||
| + | plt.ion() | ||
| + | fig = plt.figure() | ||
| + | plt.grid() | ||
| + | plt.title(' | ||
| + | |||
| + | zz = np.array(0) | ||
| + | |||
| + | y1 = np.array(np.nan) | ||
| + | y2 = np.array(np.nan) | ||
| + | y3 = np.array(np.nan) | ||
| + | |||
| + | ax = fig.add_subplot(111) | ||
| + | line1, = ax.plot(zz, y1, ' | ||
| + | line2, = ax.plot(zz, y2, ' | ||
| + | line3, = ax.plot(zz, y3, ' | ||
| + | fig.show() | ||
| + | fig.legend() | ||
| + | |||
| + | |||
| + | while True: | ||
| + | res = s.read(size=32) | ||
| + | all_data = unpack('> | ||
| + | # byte, byte, | ||
| + | print(all_data) | ||
| + | |||
| + | y1 = np.append(y1, | ||
| + | y2 = np.append(y2, | ||
| + | y3 = np.append(y3, | ||
| + | |||
| + | x = np.arange(y1.shape[0]) | ||
| + | line1.set_xdata(x) | ||
| + | line2.set_xdata(x) | ||
| + | line3.set_xdata(x) | ||
| + | line1.set_ydata(y1) | ||
| + | line2.set_ydata(y2) | ||
| + | line3.set_ydata(y3) | ||
| + | fig.canvas.draw() | ||
| + | fig.canvas.flush_events() | ||
| + | plt.pause(0.05) | ||
| + | v1 = np.min([np.nanmin(y1), | ||
| + | v2 = np.max([np.nanmax(y1), | ||
| + | |||
| + | ax.set(xlim=(x.min()-1, | ||
| + | |||
| + | s.close() | ||
| + | </ | ||
| + | |||
| + | {{: | ||
arduino/pms5003.1606765940.txt.gz · Last modified: by aistis
