2

I am trying to connect a Atmel XMega-A1 Xplained board to the RPi via USB and reading out data with Python (PySerial). OS is Wheezy-Raspbian. After trying a lot of different things, I'm out of suggestions. Please see if I have forgotten anything.

My question is really just "why can't I open the port?"

This is my Python code:

import serial
print "dev" #debug
dev = serial.Serial()
print "settings.." #debug
dev.port = '/dev/ttyACM0'
dev.baudrate = 9600
dev.parity = serial.PARITY_NONE
dev.bytesize = serial.EIGHTBITS
dev.stopbits = serial.STOPBITS_ONE

print "dev.open():" #debug
dev.open()
print "dev.open() = open!" #debug
value = None
while not value:
        value = dev.readline()
print value

This gives me this open error:

Traceback (most recent call last):
  File "usb2.py", line 20, in <module>
    dev.open()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyACM0: [Errno 5] Input/output error: '/dev/ttyACM0'

I am a member of the dialout group

pi@raspberrypi ~/vs $ whoami
pi
pi@raspberrypi ~/vs $ groups
pi adm dialout cdrom sudo audio video plugdev games users netdev input

Running the script with or without sudo gives the same outcome. When connecting the USB this is the outcome of dmesg:

[   57.604335] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
[   57.707605] usb 1-1.2: New USB device found, idVendor=03eb, idProduct=2122
[   57.707634] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   57.707651] usb 1-1.2: Product: XPLAINED CDC
[   57.707663] usb 1-1.2: Manufacturer: ATMEL
[   57.707675] usb 1-1.2: SerialNumber: 056007012069
[   57.780344] cdc_acm 1-1.2:1.0: ttyACM0: USB ACM device
[   57.868478] usbcore: registered new interface driver cdc_acm
[   57.868509] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

I followed this and installed picocom. Output of "picocom /dev/ttyACM0":

pi@raspberrypi ~/vs $ picocom /dev/ttyACM0
picocom v1.7

port is        : /dev/ttyACM0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        :
omap is        :
emap is        : crcrlf,delbs,


FATAL: cannot open /dev/ttyACM0: Input/output error

Again, sudo makes no difference.

This is my first post so let me know if this is too verbose. Thanks!

  • xxmbabanexx: Well, thanks! :) Update: I've tested my py-code on Windows. It works, and I can read out data. However, if I try to open the port while it's already open I will get the same Error 5. Like dev = serial.Serial('COM3',9600) dev = serial.Serial('COM3',9600). But I cannot see that the port is actually already in use on Linux. Have anyone experienced something alike? – René Neim Apr 15 '13 at 9:18
1

I figured out that the problem was with driver modules. When I connect the Xmega it automatically detect it as an USB ACM device, and load the cdc_acm driver module.

Unloading the "cdc_acm" module and loading the "usbserial" module solved the communication problem.

# Unloading cdc_acm module:
sudo rmmod cdc_acm
# Loading usbserial module:
sudo modprobe usbserial vendor=0x03eb product=0x2122

Vendor and product is given via the "lsusb -v" command. The port is no longer "/dev/ttyACM0", but "/dev/ttyUSB0".

It's worth noting that every time I connected the Xmega via the USB, the cdc_acm module was automatically loaded by the system. Even after unloading it with the "sudo rmmod cdc_acm". Solving this was not allowed by my time frame, so I made a batch script unloading cdc_acm, loading usbserial and running my python script. It also unloads the usbserial at the beginning, just in case one has already run it:

echo "Unloading usbserial module.."
sudo rmmod usbserial
echo "Unloading cdc-acm module.."
sudo rmmod cdc_acm
echo "Loading usbserial module.."
sudo modprobe usbserial vendor=0x03eb product=0x2122
echo "Done.."
python thescript.py

Ok. Since no one (at this time) had any ideas, this is how a solved my problem. Please note that I have limited Linux skills, and that this is most likely not the best method (Especially not in the long run). It did however enable me to do the communication that I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.