Read int from Arduino
-
wrote on 7 Nov 2013, 17:10 last edited by
Hi:
I want to read and write an int from Arduino.
I'm using "QSerialPort":http://qt-project.org/doc/qt-5.1/qtserialport/qserialport.html and so far Qt only receives "garbage" form Arduino.The code from Arduino is:
@
int myDelay = 1000;void setup()
{
Serial.begin(9600);
}void loop()
{ while (Serial.available() <= 0)
{
Serial.print(myDelay);
}
myDelay = Serial.read();
Serial.flush();
}
@This read and sends data from Qt.
Sender from Qt:
@void Dialog::enviarAtraso(int valor)
{
serial->write(QString::number(ui->atraso->value()).toLocal8Bit());
// ????
}@Reader from Qt:
@void Dialog::readResponse()
{
response->append(serial->readAll());
int x = 33; //sample value
// response to int here
// ...
// ...
ui->recebido->setText(QString::number(x));
response->clear();
}@response is a QByteArray.
Any sugestion in order to establish this communication?
Thanks -
bq. Any sugestion in order to establish this communication?
Read documentation, look examples.
-
wrote on 7 Nov 2013, 20:42 last edited by
Perhaps i did not make my self clear!
My question is about datatypes and converting them into/from QByteArray.
The communication is working fine ...
1/3