Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtGui Serial Port & Arduino Serial Flow [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

QtGui Serial Port & Arduino Serial Flow [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 5.3k 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
    #3

    Thanks Kuzulis for your reply.

    I read the docs and examples, but it doesn't work for my case...
    Anyway, I will try one more time to do the job.

    Thanks again.

    Regards,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi and welcome to devnet,

      Why doesn't it work for you case ?

      Can you describe your setup ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi SGait,

        Thanks for your reply.

        I don't really have problems, because today I am just learning Qt5.
        It's a fantastic tool, but I am just a little bit disapointed when I saw all we need to do to just to print on a widget a serial flow...
        It's amazing !

        Well, I follow my search to see how to set my *.pro and the QSerial lib.

        The main goal for me is pretty simple:

        Sending some flow on the serial port /dev/tty (Linux) and show them through the widget LCD of Qt, and that's it :-)

        Cheers,

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          /dev/tty is generally not a serial port but the default console.

          Then you didn't try to write it 100% natively ;)

          I must say that it doesn't require that much:
          QSerialPort + QLCDNumber and a slot for processing the data coming from your Arduino

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

            Hi,

            Thank you a lot, I will try it.

            Have a nice day.

            Cheers,

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

              Hi,

              Ok, I did some test, and this my files:

              .pro

              @
              QT += core gui serialport

              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

              TARGET = Pitot
              TEMPLATE = app

              SOURCES += main.cpp
              mainwindow.cpp

              HEADERS += mainwindow.h

              FORMS += mainwindow.ui
              @

              This is the header file:
              @#ifndef MAINWINDOW_H
              #define MAINWINDOW_H

              #include <QMainWindow>

              namespace Ui {
              class MainWindow;
              }

              class MainWindow : public QMainWindow
              {
              Q_OBJECT

              public:
              explicit MainWindow(QWidget *parent = 0);
              ~MainWindow();

              private slots:

              void on_lcdNumber_overflow();
              

              private:
              Ui::MainWindow *ui;
              };

              #endif // MAINWINDOW_H
              @

              And the mainwindows.cpp:
              @
              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include <QSerialPort>
              #include <QDebug>

              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);
              connect(serial, SIGNAL(readyRead()),this,SLOT(serialReceived()));

              }

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

              void MainWindow::on_lcdNumber_overflow()
              {
              QByteArray qb;
              qb=serial->readAll();
              ui->lcdNumber->setDecMode(qb);
              qDebug() << qb;
              }
              @

              and the compilator says:

              !file:///home/tux/Capture du 2014-12-26 10:18:28.png()!

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

                Could you help me to solve this problem ?

                Thanks in advance for your time and support.

                Regards,

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

                  Ok, don't take in account my last post.
                  I solve a problem due to a pointer.

                  So, the only problem I have is the next, and this is the mainwindows.cpp:

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

                  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);
                  connect(serial, SIGNAL(readyRead()),this,SLOT(serialReceived()));

                  }

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

                  void MainWindow::on_lcdNumber_overflow()
                  {
                  QByteArray qb;
                  qb=serial->readAll();
                  ui->lcdNumber->setDecMode(qb);
                  qDebug() << qb;
                  }
                  @

                  So everything is fine but a line 35, I have a compilator problem.
                  It says:

                  /mainwindow.cpp:35: erreur : no matching function for call to 'QLCDNumber::setDecMode(QByteArray&)'
                  ui->lcdNumber->setDecMode(qb);
                  ^
                  Could you tell me why it doesn't compile ?
                  I really don't understand.

                  Thanks for your help.

                  Regards,

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

                    Hi all,

                    Finally, I finished the job ! ;-)
                    The reason why I had some problems was the ByteArray, but now it works fine.
                    The modifications I did was:

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

                    And everythings lokk fine :-)

                    So thanks for your support.

                    Regards,

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Nice !

                      Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                      Happy coding !

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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