0

I would like to do a project that output value from Arduino and paint shapes in Qt. I am not sure if QCustomPlot can do this. Would you please give me some suggestion?

For example, I create a Qt GUI for entering the position(x,y) to Arduino and do calculation, then Arduino send the value signal to Qt and paint the shape on the position I want. Is it possible?

1

1 Answer 1

0

A few years ago, i do something like that using QWT and QextSerialPort. You have to connect your Arduino using a serial por (in Windows COM1, COM2...), and you will be able to read/write data from the buffer.

Now, Qt, integrates a native support for this task, check QtSerialPort Support, to configure your port check this class QSerialPort. How to read the data? Use QByteArray, an example:

 QByteArray responseData = serial->readAll();
 while(serial->waitForReadyRead(100))
       responseData += serial->readAll();

Now store all the bytes in a QVector of type double.

QVector<double> data;
QDataStream stream(line);
stream >> data;

This data will be ploted by QCustomPlot. Example:

int numSamples = data.size();
QVector<double> x(numSamples), y(numSamples); // initialize with entries 0..100
for (int i=0; i<numSamples; ++i)
{
  x[i] = i/50.0 - 1; // x goes from -1 to 1
  y[i] = data[i]; // In this line copy the data from your Arduino Buffer and apply what you want, maybe some signal processing
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-1, 1);
customPlot->yAxis->setRange(0, 1);
customPlot->replot();

Enjoy!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.