Go Down

Topic: Python does not recognize the serial port (Read 869 times) previous topic - next topic

charboing

I wrote a small program in python and hoping it will send command to my arduino uno.
The program is on window7. And it can not find the serial port. here was my program:
#############################
# Set up serial baud rate
#usbport = 'COM5'
#ser = serial.Serial(usbport, 9600, timeout=1)
#def move(command):
#    ser.write(command)

Then I found a way to check if this python can detect any port, I used this code:
#!/usr/bin/env python

import serial

# Assign Arduino's serial port address
#   Windows example
#     usbport = 'COM5'
#   Linux example
#     usbport = '/dev/ttyUSB0'
#   MacOSX example
#     usbport = '/dev/tty.usbserial-FTALLOK2'

locations=['/dev/ttyACM0', '/dev/ttyACM1','/dev/ttyACM2', '/dev/ttyACM3','/dev/ttyACM4', '/dev/ttyACM5','/dev/ttyUSB0','/dev/ttyUSB1','/dev/ttyUSB2','/dev/ttyUSB3', '/dev/ttyUSB4', '/dev/ttyUSB5', '/dev/ttyUSB6', '/dev/ttyUSB7', '/dev/ttyUSB8', '/dev/ttyUSB9', '/dev/ttyUSB10', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', 'com10', 'com11', 'com12', 'com13', 'com14', 'com15', 'com16', 'com17', 'com18', 'com19', 'com20', 'com21', 'com1', 'end']

for device in locations:
   try:
      print "Trying...",device
      serialport = serial.Serial(device, 2400, timeout = 0)
      break
   except:
      print "Failed to connect on",device
      if device == 'end':
         print "Unable to find Serial Port, Please plug in cable or check cable connections."
         exit()

I plugged in arduino usb into my pc, and run above in python using command= import thisone.py
and basically get the print out="Unable to find Serial Port, Please plug in cable or check cable connections."

Could anyone please help me here? Why python on my pc can NOT find the COM5 that connect to my arduino? Thanks.

Go Up