Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while (Serial.available()
#1
Hi. I'm receiving serial data from an Arduino over USB the data comes at anytime, could be 30 minutes between messages. I have the following while loop that does the job but it prints an empty line ever loop.  On the Arduino I can do "while (Serial.available()" How could this be done in Python?

Thanks.

while 1:
        try:
            msg = ser.readline()
            msg=msg.decode('utf-8')
            print(msg)
            time.sleep(1)
        except ser.SerialTimeoutException:
            print("Data could not be read")
        time.sleep(1)
Reply


Messages In This Thread
while (Serial.available() - by holt24 - Jan-23-2017, 06:26 PM
RE: while (Serial.available() - by DougArndt - Feb-09-2017, 05:20 PM
RE: while (Serial.available() - by holt24 - Feb-10-2017, 11:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,355 Aug-24-2023, 07:56 AM
Last Post: gowb0w

Forum Jump:

User Panel Messages

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