Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Serial flow with multiples data (Arduino) [SOLVED]

Serial flow with multiples data (Arduino) [SOLVED]

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cherault
    wrote on last edited by
    #1

    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) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    serial=new QSerialPort(this);
    serial->setPortName("/dev/ttyACM0");
    serial->setBaudRate(QSerialPort::Baud9600);
    serial->setDataBits(QSerialPort::Data8);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::OneStop);
    serial->setFlowControl(QSerialPort::NoFlowControl);
    serial->open(QIODevice::ReadOnly);//mettre un bouton d'activation du port

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

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    serial->close();
    }

    void MainWindow::serialReceived()
    {
    QByteArray valeur;
    valeur = serial->readAll();
    float nb = valeur.toFloat();
    ui->lcdNumber->display(nb);
    }
    @

    Thanks for your help, time and support.

    Regards,

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

      I do not understand, what do you want?

      Please, read similar issue (as I understand): http://qt-project.org/forums/viewthread/52407/

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cherault
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cherault
            wrote on last edited by
            #5

            Thanks so much fore your help Kuzulis.

            Regards,

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved