1
votes

I just installed Pyserial 2.6 and I have Python 2.7.3 unfortunately it either did not install correctly or I am not using it correctly. I installed it through terminal using the line

sudo easy_install pyserial

Unfortunately it gave me 2 warnings:

warning: no files found matching 'examples/miniterm.py'
warning: no files found matching 'test/test_io_lib.py'

Other than that it seemed to install correctly.

When I run this in Python I keep getting the farther below error

import serial
serial_input = serial.Serial('/dev/tty/.usbmodem3d241',9600)
while True:
    ser.readline()

Error:

Traceback (most recent call last):
  File "/Users/ben/Documents/Arduino_to_Python.py", line 5, in <module>
    serial_input = serial.Serial('/dev/tty/.usbmodem3d241',9600)
  File "build/bdist.macosx-10.7-intel/egg/serial/serialutil.py", line 261, in __init__
    self.open()
  File "build/bdist.macosx-10.7-intel/egg/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
SerialException: could not open port /dev/tty/.usbmodem3d241: [Errno 20] Not a directory: '/dev/tty/.usbmodem3d241'

Whatever serial port I try it never seems to work. I have tried the ones in the Arduino program Tools>Serial Port and all of the prompts at http://pyserial.sourceforge.net/shortintro.html#opening-serial-ports

Any help would be greatly appreciated. Thanks.

2
And you are certain the path does exist? Look at /dev/tty in a shell.Martijn Pieters
Does dmesg | grep usbmodem give any clues as to what the path is for the device?Martijn Pieters
I tried this from the pyserial website to no avial. Anythoughts toward what the path should be? >>> ser = serial.Serial() >>> ser.baudrate = 19200 >>> ser.port = 0 >>> ser.open() Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> ser.open() File "build/bdist.macosx-10.7-intel/egg/serial/serialposix.py", line 278, in open raise SerialException("could not open port %s: %s" % (self._port, msg)) SerialException: could not open port 0: [Errno 2] No such file or directory: '/dev/cuad0'ben
Martijn I coped it into the python shell and got a Syntax error? Any thoughts about what the correct path should be for the serial_input line?ben
See posts like See posts like arduino.cc/forum/index.php/topic,39052.0.html; you are looking for USB events to tell you the correct name of the device to open.Martijn Pieters

2 Answers

0
votes

This serial_input = serial.Serial('/dev/tty/.usbmodem3d241',9600) should be without the additional /. between /dev/tty and usbmodem3d241.

Also, open your console and go see if ttyusbmodem3d241 exists. In the console type cd /dev then ls and see if it is listed.

0
votes

Go to arduino ide-> tools from menu on top left -> ports -> look at what your port says under serial ports mine says COM3(Arduino.....) In python serial_input = serial.Serial('portName',9600)

mine was COM3 serial_input = serial.Serial('COM3',9600)

I know it's too late, but just added it anyway.