QSerial - Can't read Arduino serial data
-
Hello!
This is my first project using Qt and Arduino together. I'm trying to read and write data using a GUI and Arduino Uno, but I don't know what is happening.
I want to click on a pushButton and receive the data that is on Serial. My code is not accessing readSerial and I believe that the problem is on the SIGNAL(readyRead()).
void MainWindow::on_pushButton_clicked() { arduino_is_available = false; arduino_port_name = ""; arduino = new QSerialPort; foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){ if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){ if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){ if(serialPortInfo.productIdentifier() == arduino_uno_product_id){ arduino_port_name = serialPortInfo.portName(); arduino_is_available = true; } } } } if(arduino_is_available){ // open and configure the serialport arduino->setPortName(arduino_port_name); arduino->open(QSerialPort::ReadWrite); arduino->setBaudRate(QSerialPort::Baud9600); arduino->setDataBits(QSerialPort::Data8); arduino->setParity(QSerialPort::NoParity); arduino->setStopBits(QSerialPort::OneStop); arduino->setFlowControl(QSerialPort::NoFlowControl); QObject::connect(arduino, SIGNAL(readyRead()), this, SLOT(readSerial())); }else{ // give error message if not available QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!"); } } void MainWindow::readSerial(){ qDebug() << "Teste 1"; QByteArray daraSerial = arduino->readAll(); serialBuffer += QString::fromStdString(daraSerial.toStdString()); //std::cout << serialBuffer.toStdString(); qDebug() << "Teste 2"; qDebug() << serialBuffer; qDebug() << daraSerial; }
My Arduino code is just a loop with Serial.print("a"); and a delay.
I have no idea how to solve this. I read some posts on the forum and didn't find something that solves my problem.
What am I doing wrong?
QObject::connect(arduino, SIGNAL(readyRead()), this, SLOT(readSerial())); is returning true.
Thank you!
-
@LuizSabbagh
what Qt version are you using ? if it's below 12.6 or 13.2 you'll have to update, as the Serialport module had a bug in some versions. -
I'm using 5.12.5. I'll try to update.