Issues using CMUCam on RaspberryPI

Added by George Profenza about 5 years ago

Hello,

I'm trying to use a CMUCam4 with a Raspberry PI and I'm having some issues.

First I just tried with a bit of Python:

import serial

cam = serial.Serial("/dev/ttyUSB0",baudrate=19200,timeout=0)
cam.write("GH 0 3 \r") #call get version
print "cam: " + cam.readline() #expecting a single line

I've got no errors, but got nothing back.
I've also tried to do the same thing with openFrameworks and Processing(which was trickier to setup)
with the frame rate set t 30 and got pretty much the same behaviour.

I've also downloaded the CMUCam4GUI_linux application and followed the instructions.
The current user(pi) was already added to the dialout group.

groups pi

prints:
pi adm dialout cdrom sudo aduio video plugdev games users netdev input indiecity

When i tried to run

sudo bash CMUcam4GUI.sh

I got this error:
CMUcam4GUI.sh: line 13: /home/pi/CMUcam4GUI_linux_100/./CMUcam4GUI: Permission denied

I'm not very experienced with linux so I'm a bit stuck.
Does anyone have any hints/tips I could use to get the CMUcam4 running on a Raspberry PI ?
Thanks!


Replies (16)

RE: Issues using CMUCam on RaspberryPI - Added by Kwabena Agyeman about 5 years ago

Hi,

Do 'chmod +x GMUcam4GUI' in the CMUcam4GUI directory, this will make the file executable. The CMUcam4GUI was compiled for Ubuntu, but, should run on the PI. However, some features of the CMUcam4GUI require a fast computer...

Look up the chmod command if you are having problems with it.

As for your python code... you called getHistogram. You should do "GV\r" for get version. Note, python may have just sent "\r" as the two characters and not the ASCII control character 13. Additionally, the readLine command may not wait until input comes back from the camera. I see you set the timeout at zero.. so does this mean the readline command will wait?

Finally, when you open a serial port to the CMUcam4... look to see if the red light turned off... if this is the case then the PI has but the CMUcam4 into reset by holding the DTR pin low. You can get around this by making sure the DTR pin is not connected (this the top pin the 6-pin connector) or you can just set the DTR pin high in software. Do the same thing for RTS too.

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

Thank you for your suggestions Kwabena

Used chmod but it doesn't look great:

./CMUcam54GUI
bash: .CMUcam54GUI: cannot execute binary file
sudo ./CMUcam54GUI
./CMUcam54GUI: 5: ./CMUcam54GUI: Syntax error: word unexpected (expecting ")")

I've change the write call to

cam.write("GV"+chr(13))

And yes, I notice the red LED turn off when I open the serial port.
I'm a bit confused by this:"if this is the case then the PI has but the CMUcam4 into reset by holding the DTR pin low. ". I don't have anything connected to any pins, it's just the board connected to USB.

What do you recommend ?

RE: Issues using CMUCam on RaspberryPI - Added by Kwabena Agyeman about 5 years ago

Yeah, the connection to the CMUcam4, notice there's a pin marked DTR on the CMUcam4. Make sure nothing is connected to that pin. When that pin gets pulled low (which happens when some serial programs open the serial port) the CMUcam4 is put into reset mode. When it wakes up out of reset it is briefly programmable, this is how the boot loader works. Its basically the same thing that the Arduino uses to get programmed. When you assert the DTR pin that pulls the pin low. You would need to de-assert the DTR pin.

If you want to run the CMUcam4GUI, try it run a Linux desktop or windows. The reason the executable can't run is because its an assembly application compiled for x86. I forgot that myself... ha! :)

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

OK,
spotted the DTR pin, it's at the top of the pins that I use to connect via usb (with the FTDI breakout),
so I guess I can't leave that pin unused if I want to access the cmu cam on the computer, right ?
How else can I talk to CMUCam4 from a computer and leave the DTR pin free ?

I'll setup qt on the rasbperry pi and try to compile your GUI app.

RE: Issues using CMUCam on RaspberryPI - Added by Kwabena Agyeman about 5 years ago

Good luck trying to compile on the Rasberry PI...

The CMucam4GUI does not need the DTR pin. It has code in it to make the pin go high, it resets the CMUcam4 by sending a special sequence of reset commands that are guaranteed to get the camera out of any mode and sync with it and reset the system.

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

Woohoo!
Got it running now.

Connecting with the FTDI breakou but without the DTR pin did the trick and also keeping the "frame rate" close to 30fps as per documentation. My python script looks like this now:

import threading
import serial

cam = serial.Serial("/dev/ttyUSB0",baudrate=19200,timeout=0)
cam.write("TC 20 28 30 39 24 36"+chr(13))

def readCam():
    print "r: " + cam.readline();

def setInterval(func, sec):
    def func_wrapper():
        setInterval(func, sec)
        func()
    t = threading.Timer(sec, func_wrapper)
    t.start()
    return t

setInterval(readCam,.3) #close to 30 fps (0.33ms)

The above is just tracking a very dark/black object.

I'm currently installing qt on the pi. Will try to compile the GUI tool.
Might be handy to use that for the right settings first.

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

Last update:
I've managed to compile and run CMUcam4GUI on RaspberryPI.
After I've installed Qt and configured QtCreator for desktop all
I had to do is cast a qreal to a double which was causing problems:
changed line 12067 in qcustomplot.cpp to:

clipPad = qMax(clipPad,(double)mainPen().widthF());

also changed the baudrate to 115200 in CMUcom4.h as explainined in the wiki.
I could see a warning about the baudrate in the qt creator output.

Thanks again for the support Kwabena!

RE: Issues using CMUCam on RaspberryPI - Added by Kwabena Agyeman about 5 years ago

Wow, amazing, well, that's the power of Qt - write once, deploy everywhere!

Weirdly, a qreal should be a double. That's what the qreal typecast is usually.

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

For reference I've attached the compiled binary with libQtCore and libQtGui.
Would be good if someone else can test that on another Raspberry PI.
I'm not sure I included all the libraries needed.

qreal can also be a float depending on the platform:

#if defined(QT_COORD_TYPE)
typedef QT_COORD_TYPE qreal;
#elif defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
typedef float qreal;
#else
typedef double qreal;
#endif

If someone else would like to install qt on RaspberryPI and compile the project,
here is the guide I used:
http://qt-project.org/wiki/apt-get_Qt4_on_the_Raspberry_Pi

RE: Issues using CMUCam on RaspberryPI - Added by Kwabena Agyeman about 5 years ago

So... the Raspberry Pi doesn't have double floating point math? No... it just must be the Qt library trying to make sure things go faster.

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza about 5 years ago

It does, in my code tweak I've cast to double.

My guess is the qMax(http://harmattan-dev.nokia.com/docs/library/html/qt4/qtglobal.html#qMax)
function takes two arguments of the same type but on Raspberry PI
the qreal got evaluated as a float(as you pointed out, to make sure things go faster)
and the compiler complained because qMax received
arguments or different types (double and float), so the explicit cast to double resoled the issue.

I'm guessing casting the first argument as a float rather than the second as a double would've also worked.

RE: Issues using CMUCam on RaspberryPI - Added by mono joli 11 months ago

i never face such issue. i google it and reply you back if i get some solution.
Run 3 Run 4

RE: Issues using CMUCam on RaspberryPI - Added by George Profenza 11 months ago

@Kwabena Agyeman the message above looks well dodgy!

RE: Issues using CMUCam on RaspberryPI - Added by Anna Shetty 10 months ago

Respecting the time and exertion you put into your site and nitty gritty data you offer.
photoshop online
cool math games

(1-16/16)