Merge pull request #8588 from Staars/serial

Update serial-plotter.py, more infos in the code, small refactoring
This commit is contained in:
Theo Arends 2020-05-31 11:26:51 +02:00 committed by GitHub
commit 672e2993b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 12 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
""" """
serial-plotter.py - for Tasmota serial-plotter.py - for Tasmota
@ -20,7 +20,8 @@
Requirements: Requirements:
- Python - Python
- pip3 matplotlib - pip3 install matplotlib pyserial
- for Windows: Full python install including tkinter
- a Tasmotadriver that plots - a Tasmotadriver that plots
Instructions: Instructions:
@ -32,8 +33,7 @@ Instructions:
AddLog_P2(LOG_LEVEL_INFO, PSTR("PLOT: %u, %u, %u,"),button_index+1, _value, Button.touch_hits[button_index]); AddLog_P2(LOG_LEVEL_INFO, PSTR("PLOT: %u, %u, %u,"),button_index+1, _value, Button.touch_hits[button_index]);
Usage: Usage:
set serial config in code ./serial-plotter.py --port /dev/PORT --baud BAUD (or change defaults in the script)
./serial-plotter.py
set output in tasmota, e.g.; TouchCal 1..4 (via Textbox) set output in tasmota, e.g.; TouchCal 1..4 (via Textbox)
""" """
@ -44,6 +44,10 @@ from matplotlib.widgets import TextBox
import time import time
import serial import serial
import argparse import argparse
import sys
print("Python version")
print (sys.version)
#default values #default values
port = '/dev/cu.SLAB_USBtoUART' port = '/dev/cu.SLAB_USBtoUART'
@ -164,25 +168,25 @@ def handle_close(evt):
ser.close() ser.close()
print('Closed serial plotter') print('Closed serial plotter')
def submit(text):
print (text)
ser.write(text.encode() + "\n".encode())
ani = animation.FuncAnimation(fig, update, None, fargs=[line1, line2], ani = animation.FuncAnimation(fig, update, None, fargs=[line1, line2],
interval=10, blit=True, init_func=init) interval=10, blit=True, init_func=init)
ax.set_xlabel('Last 200 Samples') ax.set_xlabel('Last 200 Samples')
ax.set_ylabel('Values') ax.set_ylabel('Values')
plt.subplots_adjust(bottom=0.25)
ax.legend(loc='lower right', ncol=2)
fig.canvas.mpl_connect('close_event', handle_close) fig.canvas.mpl_connect('close_event', handle_close)
def submit(text):
print (text)
ser.write(text.encode() + "\n".encode())
plt.subplots_adjust(bottom=0.25)
axbox = plt.axes([0.15, 0.05, 0.7, 0.075]) axbox = plt.axes([0.15, 0.05, 0.7, 0.075])
text_box = TextBox(axbox, 'Send:', initial='') text_box = TextBox(axbox, 'Send:', initial='')
text_box.on_submit(submit) text_box.on_submit(submit)
ax.legend(loc='lower right', ncol=2)
if ser.is_open==True: if ser.is_open==True:
plt.show() plt.show()