Serial flow with multiples data (Arduino) [SOLVED]

  • Hi all,

    I just finished a Qt program which read a serial flow from an Arduino.
    This program works well when I print just only one data from Arduino.
    But how Qt can read multiple data sent within the serial flow of the same Arduino ?

    I give you my Qt code just in case, which print only one data:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSerialPort>

    using namespace std;

    QSerialPort *serial;

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    serial=new QSerialPort(this);
    serial->open(QIODevice::ReadOnly);//mettre un bouton d'activation du port

    connect(serial, SIGNAL(readyRead()),this,SLOT(serialReceived()));


    delete ui;

    void MainWindow::serialReceived()
    QByteArray valeur;
    valeur = serial->readAll();
    float nb = valeur.toFloat();

    Thanks for your help, time and support.


  • I do not understand, what do you want?

    Please, read similar issue (as I understand):

  • Hi,

    Thanks for the link but I have not this kind of problem.

    My problem is:

    1- Arduino is coded to send three data over serial port. (Works)
    2- Qt received the flow of the serial port (Works)
    3- Qt show me just only one value over three (Doesn't work)

    So my question is:

    Does it exist a way to show these 3 values on Qt in C++ (Linux) ?
    The three values are plot on the serial terminal of the arduino like this:

    data1 data2 data3

    Actually, Qt show only data1.

    Thanks for your help

  • bq. Does it exist a way to show these 3 values on Qt in C++ (Linux) ?

    yes. just check your input stream, llike:

    void MainWindow::serialReceived()
    qDebug() << serial->bytesAvailable();

    for data1 .. data3 size. and then to parse your input stream correctly.

  • Thanks so much fore your help Kuzulis.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.