Python Forum

Full Version: Arduino/If Else Condition
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
New at Python,trying to make if Else condition,You can see below:
from Tkinter import *
root = Tk()
def connectToArduino():
 
    arduino = serial.Serial(arduinoPort,   serialTransferRate)
    if(arduino.timeout = None):
    lab=Label(root, text="Connected")
    lab.grid()
    Else:
    lab=Label(root, text="Disconnected")
    return arduino, lab
   
arduino = connectToArduino()
arduino.pack()
root.mainloop()
You think,My if Else condition true?
you need to indent between 'if' and 'else' and after 'else'.
i want to make if else condition about status of arduino.How could i make if else condition about status about arduino?If status of arduino is connected,i want to have "Connected" Message.Else,Message is "Disconnected".

import serial
serialTransferRate = 115200
arduinoPort = '/dev/tty.usbmodem411'
def connectToArduino():
    arduino = serial.Serial(arduinoPort, serialTransferRate)
    if(arduino.timeout == None):
        print ("connected")
    else:
        print ("disconnected")
        arduino = connectToArduino()
The error code below:

File "python", line 12, in <module>
  File "python", line 6, in connectToArduino
SerialException: [Errno 2] could not open port /dev/tty.usbmodem411: [Errno 
2] No such file or directory: '/dev/tty.usbmodem411'
I've seen this post before: https://python-forum.io/Thread-Arduino-I...=connected
and answered here: https://python-forum.io/Thread-Tkinter-L...=connected
please don't post same question multiple times.
All posted messages are read by all mderators.
Thank you