1

I'm using a CMUCam4 connected to the usb port. So far I've tried this:

import serial

cam = serial.Serial("/dev/ttyUSB0",19200)
cam.write("GV \r") #call get version
result = cam.readline()

The problem is python freezes when I use cam.read(),cam.read(3) (expecting ACK or ERR), cam.readline()

Any suggestions ? I'm using Raspian Wheezy

UPDATE I've tried lenik's suggestion(using the timeout parameter) and it did help: with timeout 0 the program no longer freezes. However I can getting nothing back.

I've tried some other approaches: installing openframeworks and modifying the serialExample but again, not errors, but no data: just silence.

Eventually I've managed to get Processing 1.5.1 as well running, slow though, with the serial library (hacky .so and .jar replacing was needed), but yet again, no mesages.

I'm starting to think there's some sort of user limitation, output being piped somewhere else or something. I'm new to linux so a bit lost a the moment.

How can I read values from a serial port on the Raspberry PI ? Thanks!

1

you should set the baud rate in your serial.Serial(...) command, otherwise the camera might not recognize whatever command you're sending there. something along the lines of:

cam = serial.Serial("/dev/ttyUSB0", baudrate=9600)

Also, you may specify the timeout as a parameter, with the possible values:

timeout = None: wait forever
timeout = 0: non-blocking mode (return immediately on read)
timeout = x: set timeout to x seconds
  • sorry, forgot to add the baudrate in the code above(which I've updated). I did use the baud rate parameter in my test. Will try the timeout parameters tomorrow...well, in a few hours :) Thanks (+1) – George Profenza Sep 4 '13 at 23:52
  • Setting both baudrate and timeout parameters and arguments did the trick for me! Thanks again :) – George Profenza Sep 9 '13 at 18:27

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.