Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino/If Else Condition
#1
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?
Reply
#2
you need to indent between 'if' and 'else' and after 'else'.
Reply
#3
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'
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  else condition not called when if condition is false Sandz1286 10 6,031 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 8,289 Jun-01-2020, 06:00 PM
Last Post: penahuse

Forum Jump:

User Panel Messages

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