Continuous data streaming Arduino to Python -
i trying python gui window using tkinter continuously display data streaming arduino uno board acting voltmeter. code i've got, window display 1 data point, , once window gets closed, new window opens next available data point. here's code i've been using:
import serial tkinter import * ser = serial.serial('/dev/tty.usbmodem621') ser.baudrate = 9600 while 1 == 1: reading = ser.readline() root = tk() w = label(root, text = reading) w.pack() root.mainloop()
i'm using macbook pro, , pyserial package serial communications. how window refresh itself?
i think problem you're creating new root every loop iteration. try code:
import serial tkinter import * time import sleep ser = serial.serial('/dev/tty.usbmodem621') ser.baudrate = 9600 def update(): while 1: reading.set(ser.readline()) root.update() sleep(1) root=tk() reading = stringvar() w = label(root, textvariable = reading) w.pack() root.after(1,update) root.mainloop()
this sets "mainloop" call "update" function after millisecond , uses reference variable "reading" rather actual value of it, allowing updated.
i hope helps.
Comments
Post a Comment