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. QT reading Serialport of Arduino
Forum Updated to NodeBB v4.3 + New Features

QT reading Serialport of Arduino

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 4.0k Views
  • 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.
  • jsulmJ jsulm

    @mimamrafi said in QT reading Serialport of Arduino:

    it is the command to open the serial port right?

    Yes, it should be AFTER you set the parameters (like setFlowControl).

    M Offline
    M Offline
    mimamrafi
    wrote on last edited by mimamrafi
    #8

    @jsulm yes, I have been open it and the output is true, but my issue is the arduino send nothing to serial when I debug the QT first. If I open the serial monitor and close it again then debug the QT, it works properly

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • M mimamrafi

      @jsulm yes, I have been open it and the output is true, but my issue is the arduino send nothing to serial when I debug the QT first. If I open the serial monitor and close it again then debug the QT, it works properly

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #9

      @mimamrafi I don't know how your Arduino side is working, so can't comment

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • M mimamrafi

        @jsulm yes, I have been open it and the output is true, but my issue is the arduino send nothing to serial when I debug the QT first. If I open the serial monitor and close it again then debug the QT, it works properly

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #10

        @mimamrafi said in QT reading Serialport of Arduino:

        yes, I have been open it and the output is true

        yes, thats obvious, but did you open it after setting the settings ? e.g:

        void SerialPortManager::openSerialPort()
        {
        arduino->setPortName("COM8");
        arduino->setBaudRate(QSerialPort::Baud9600);
        arduino->setDataBits(QSerialPort::Data8);
        arduino->setParity(QSerialPort::NoParity);
        arduino->setStopBits(QSerialPort::OneStop);
        arduino->setFlowControl(QSerialPort::NoFlowControl);
        
        arduino->open(QIODevice::ReadWrite);
        }
        

        assuming of course, those are the same settings as the other program uses.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        M 1 Reply Last reply
        0
        • jsulmJ jsulm

          @mimamrafi I don't know how your Arduino side is working, so can't comment

          M Offline
          M Offline
          mimamrafi
          wrote on last edited by
          #11

          @jsulm I only send

          Serial.println ("test"); 
          

          in void loop

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @mimamrafi said in QT reading Serialport of Arduino:

            yes, I have been open it and the output is true

            yes, thats obvious, but did you open it after setting the settings ? e.g:

            void SerialPortManager::openSerialPort()
            {
            arduino->setPortName("COM8");
            arduino->setBaudRate(QSerialPort::Baud9600);
            arduino->setDataBits(QSerialPort::Data8);
            arduino->setParity(QSerialPort::NoParity);
            arduino->setStopBits(QSerialPort::OneStop);
            arduino->setFlowControl(QSerialPort::NoFlowControl);
            
            arduino->open(QIODevice::ReadWrite);
            }
            

            assuming of course, those are the same settings as the other program uses.

            M Offline
            M Offline
            mimamrafi
            wrote on last edited by
            #12

            @J-Hilk Hey, I've got a clue. I'm using Arduino leonardo, I don't know why it didn't send the serial to QT without open the serial monitor. When I try Arduino UNO, it works properly without open the serial monitor first

            J.HilkJ 1 Reply Last reply
            0
            • M mimamrafi

              @J-Hilk Hey, I've got a clue. I'm using Arduino leonardo, I don't know why it didn't send the serial to QT without open the serial monitor. When I try Arduino UNO, it works properly without open the serial monitor first

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #13

              @mimamrafi try adding a sleep/delay at the end of your Arduino loop, see if that improves things.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              M 1 Reply Last reply
              0
              • jsulmJ jsulm

                @mimamrafi said in QT reading Serialport of Arduino:

                it is the command to open the serial port right?

                Yes, it should be AFTER you set the parameters (like setFlowControl).

                K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on last edited by
                #14

                @jsulm said in QT reading Serialport of Arduino:

                Yes, it should be AFTER you set the parameters (like setFlowControl).

                No. It is irrelevant.

                J.HilkJ 1 Reply Last reply
                0
                • K kuzulis

                  @jsulm said in QT reading Serialport of Arduino:

                  Yes, it should be AFTER you set the parameters (like setFlowControl).

                  No. It is irrelevant.

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #15

                  @kuzulis I was about to vehemently deny this, but then I noticed the setters have boolean return type.

                  I was only going on the notes from https://doc.qt.io/qt-5/qserialport.html#open
                  that says it sets the settings during open().

                  did this change in one of the newer versions? apparently not. At least not as far back as 5.12


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @mimamrafi try adding a sleep/delay at the end of your Arduino loop, see if that improves things.

                    M Offline
                    M Offline
                    mimamrafi
                    wrote on last edited by
                    #16

                    @J-Hilk No, it still print nothing. Maybe, I will switch to arduino uno. It's hardware issue, not the QT. Thanks for help

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mimamrafi
                      wrote on last edited by
                      #17

                      Hai everyone. I found some clues about this topic. The serial communication have to enable the DTR (Data Terminal Ready). So this is my current code that I used

                      void SerialPortManager::openSerialPort()
                      {
                         arduino->setPortName("COM8");
                         arduino->open(QIODevice::ReadWrite);
                         arduino->setBaudRate(QSerialPort::Baud9600);
                         arduino->setDataBits(QSerialPort::Data8);
                         arduino->setParity(QSerialPort::NoParity);
                         arduino->setStopBits(QSerialPort::OneStop);
                         arduino->setFlowControl(QSerialPort::NoFlowControl);
                         arduino->setDataTerminalReady(true);
                      }
                      

                      Actually, I don't know why its working, but some of tutorial it's not a problem without writing setDataTerminalReady

                      1 Reply Last reply
                      3
                      • J.HilkJ J.Hilk referenced this topic on

                      • Login

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