2016-08-09 53 views
0

Ich möchte ein Projekt, das Wert von Arduino und malen Formen in Qt. Ich bin mir nicht sicher, ob QCustomPlot dies tun kann. Würden Sie mir bitte einen Vorschlag machen?malen in qcustomplot durch Signal von Arduino

Zum Beispiel, ich erstelle eine Qt GUI für die Eingabe der Position (x, y) zu Arduino und tun Berechnung, dann senden Arduino das Wert-Signal an Qt und die Form an der gewünschten Position. Ist es möglich?

+0

Sicher ist das möglich. Beginnen Sie hier https://github.com/dmontanari/qplotduino, dies ist ein Projekt, das all das tut – demonplus

Antwort

0

Vor ein paar Jahren mache ich so etwas mit QWT und QextSerialPort. Sie müssen Ihr Arduino mit einem seriellen por (in Windows COM1, COM2 ...) verbinden, und Sie können Daten aus dem Puffer lesen/schreiben.

Jetzt, Qt, integriert eine native Unterstützung für diese Aufgabe, überprüfen Sie QtSerialPort Support, um Ihren Port zu konfigurieren, überprüfen Sie diese Klasse QSerialPort. Wie lese ich die Daten? Verwenden QByteArray, ein Beispiel:

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

Jetzt speichern alle Bytes in einem QVector vom Typ double.

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

werden diese Daten durch QCustomPlot ploted werden. Beispiel:

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(); 

Viel Spaß!