Last time I showed you a little play-around with Arduino and two servos.
Since my aim is to use it to control a webcam built on top of the two servos I have a program with a GUI that can do some image processing. I want to be able to control my “webcam-head” via the GUI so I need to send messages to the Arduino from my Qt (surprised?:D) application. I chose QextSerialPort because a friend of mine got nice experiences with it. I work with Ubuntu but it is also available on Windows systems.
Get QextSerialPort library from here: QextSerialPort at google code
Compile it using Qt Creator so you will get libqextserial.so files (or dll-s on Windows).
The enumerator and listener examples are great so if you want something for a quick test, use them. If it compiles but you got runtime error messages like:
~/projects/qextserial/qextserialport/examples/enumerator-build-desktop/enumerator: error while loading shared libraries: libqextserialport.so.1: cannot open shared object file: No such file or directory
Or libqextserialportd.so.1 (if you are compiling in Debug mode, the library files with “d” postfix will be used. To avoid this error you will have to move the library files to somewhere in your LD_LIBRARY_PATH: in my case it is /usr/lib/. I got the idea from this thread: qt-interest/2004-01/thread00713-0.html
The code on Arduino is the same as the last time, and the code I handle this from Qt is something like this:
if(port == 0 || (port != 0 && port->isOpen()))
port = new QextSerialPort("/dev/ttyUSB0", QextSerialPort::EventDriven);
// check the baud rate on your Arduino since it has to be the same
// as set with Serial.begin(...)
if(port->open(QIODevice::ReadWrite) == true)
connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
qDebug() << "listening for data on" <portName();
qDebug() << "device failed to open:" <errorString();
int a = port->bytesAvailable();
//qDebug() << "bytes read:" << bytes.size();
// only do input if all of it has been received.
// without this the serial port transports line of messages
// with only 3 or 4 bytes at a time
qDebug() << QString::fromAscii(bytesReceived);