Python Forum
Super basic tkinter arduino issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Super basic tkinter arduino issue
#1
Hi
doing a basic read and display exercise.

Does anyone know how to do a basic print data from arduino onto
Tkinter with python?

(i dont!! lol)

ive looked everywhere on the web and cant find a source for this most are doing lots more and more stuff breaks..


with my basic python code i can read the arduino measurements.
super minamalist
import serial
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout=1)

while 1: 
    
	arduinoData = ser.readline().decode('ascii')
	print(arduinoData) 
This gives me no window

 
import serial
from tkinter import *
from time import sleep

ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout=1)  


values = []
root = Tk()
root.geometry('600x200')

cnt=0
var = StringVar()



e = Entry(root,width = 35, textvariable = var ,borderwidth = 5)
e.grid(row = 0, column = 0, columnspan = 3,padx = 10,pady = 10)
  
while 1: 
    
	arduinoData = ser.readline().decode('ascii')
	print(arduinoData) 

var.set('My Var')
root.mainloop()
Reply
#2
This is your problem:
while 1: 
     
    arduinoData = ser.readline().decode('ascii')
    print(arduinoData) 

## You will never get here!!!
var.set('My Var')
root.mainloop()
What you are trying to do is actually quite difficult. Perhaps the hardest type of programming.

You need to read the serial port while simultaneously running root.mainloop(). This means you either need to find a non-blocking way to read the serial port, or you need to read the serial port in a separate process and pass the strings to the GUIO process to be displayed.

I don't know how to do that on Arduino lol!
Reply
#3
I can live without the while

I just want the panel to display once a minute or button press
Reply
#4
(Jan-07-2021, 04:00 PM)Kurta Wrote: I can live without the while

I just want the panel to display once a minute or button press

readline() blocks waiting for a newline. This will make your GUI freeze whenever you are reading from the serial port. It is better than freezing forever, but it still does not make for a good GUI experience.

The best solution, I think, is to start a separate process to handle the serial port. The process would uses a queue to communicate with the GUI process. Your GUI application would periodically check if there is any data in the serial queue and display the data when found.

Since many Arduino applications involve communicating with hardware I would expect there to already be a solution to this problem. It would be worth you while to spend some time searching for what others have done. Just looking around for a little while I ran across these:

https://www.instructables.com/UART-Contr...ter-serial
Kurta likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,102 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
Photo tkinter issue mate 4 2,536 Dec-06-2020, 09:03 PM
Last Post: mate
  Issue in Tkinter with winfo_class() and LabelFrame ReDefendeur 1 2,741 Oct-05-2020, 05:52 AM
Last Post: Jeff900
  [Tkinter] tkinter: after issue edwin6938 1 3,397 Aug-25-2020, 04:37 PM
Last Post: Larz60+
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 2,165 Apr-13-2020, 05:48 PM
Last Post: deanhystad
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 1,739 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Issue on tkinter with buttons Reldaing 1 2,446 Jan-07-2020, 08:21 AM
Last Post: berckut72
  [Tkinter] Tkinter window issue frequency 4 3,352 Dec-24-2018, 10:49 AM
Last Post: frequency
  Tkinter positional information issue thatguy14 4 3,416 Jul-05-2018, 06:49 PM
Last Post: woooee
  [Tkinter] Tkinter widgets driving Arduino uno output pins woodcncwnc 3 4,558 Jan-29-2018, 08:21 PM
Last Post: woodcncwnc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020