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

QT reading Serialport of Arduino

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 3.7k 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.
  • J jsulm
    30 Nov 2021, 08:30

    @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 30 Nov 2021, 08:43 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

    J J 2 Replies Last reply 30 Nov 2021, 08:48
    0
    • M mimamrafi
      30 Nov 2021, 08:43

      @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 Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 30 Nov 2021, 08:48 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 30 Nov 2021, 08:54
      0
      • M mimamrafi
        30 Nov 2021, 08:43

        @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 Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 30 Nov 2021, 08:54 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 30 Nov 2021, 09:13
        0
        • J jsulm
          30 Nov 2021, 08:48

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

          M Offline
          M Offline
          mimamrafi
          wrote on 30 Nov 2021, 08:54 last edited by
          #11

          @jsulm I only send

          Serial.println ("test"); 
          

          in void loop

          1 Reply Last reply
          0
          • J J.Hilk
            30 Nov 2021, 08:54

            @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 30 Nov 2021, 09:13 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 1 Reply Last reply 30 Nov 2021, 09:31
            0
            • M mimamrafi
              30 Nov 2021, 09:13

              @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 Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 30 Nov 2021, 09:31 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 30 Nov 2021, 10:06
              0
              • J jsulm
                30 Nov 2021, 08:30

                @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 30 Nov 2021, 09:38 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 1 Reply Last reply 30 Nov 2021, 09:48
                0
                • K kuzulis
                  30 Nov 2021, 09:38

                  @jsulm said in QT reading Serialport of Arduino:

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

                  No. It is irrelevant.

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 30 Nov 2021, 09:48 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 J.Hilk
                    30 Nov 2021, 09:31

                    @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 30 Nov 2021, 10:06 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 2 Dec 2021, 03:33 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 J.Hilk referenced this topic on 3 Jul 2023, 14:35

                      17/17

                      2 Dec 2021, 03:33

                      • Login

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