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. Issue with serial communication with Arduino
Forum Update on Monday, May 27th 2025

Issue with serial communication with Arduino

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 6 Posters 5.4k 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.
  • K Offline
    K Offline
    Kira
    wrote on 8 Feb 2018, 05:48 last edited by Kira 2 Aug 2018, 05:48
    #1

    Hello i am written a program to send and receive data through serial port.
    On arduino there is program which receives the serial data and send some response.
    My problem is that when i connect arduino to my pc and send data directly I do not get any response.
    But when i open the serial monitor program and send data it works fine. After that when i try to send and receive the data from my program it also work. Irrespective of how many times i restart the program. But when i remove the arduino and connect again I have to go through the same process again.
    I am using arduino leonardo

    K 1 Reply Last reply 11 Jan 2019, 13:26
    1
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 8 Feb 2018, 06:41 last edited by
      #2

      How do you send the data directly? Can you show us your code?

      (Z(:^

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kira
        wrote on 8 Feb 2018, 11:48 last edited by
        #3

        @sierdzio : I am using the terminal example (part of qt examples):
        //Sample code starts
        void MainWindow::writeData(const QByteArray &data)
        {
        serial->flush();
        serial->write(data);

        }

        void MainWindow::readData()
        {
        QByteArray data = serial->readAll();
        qDebug()<<"Received data is:"<<data;
        ui->lbl_receiveddata->setText(data);

        //Sample code completes
        Arduino sample code is available from following location:
        http://arduinobasics.blogspot.in/2012/07/arduino-basics-simple-arduino-serial.html

        At first i thought it would be issue related to windows or arduino and i tried so i tried accessing the code with python and it works fine.

        For more detail please refer the terminal example in qt example

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 8 Feb 2018, 12:21 last edited by
          #4

          Are you sure you have all port settings set exactly the same on both sides (baud rate, parity etc.)?

          Are you sure no other device is using that port at the same time? Only single app can connect simultaneously.

          (Z(:^

          1 Reply Last reply
          1
          • K Offline
            K Offline
            Kira
            wrote on 8 Feb 2018, 13:05 last edited by
            #5

            Yes, I have checked it many times and it the port is busy it give me error message.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kira
              wrote on 8 Feb 2018, 13:47 last edited by Kira 2 Aug 2018, 13:54
              #6

              @sierdzio : And one more thing when i try to run the application by keeping the baud rate as 1200
              It gives me error of the serial port.
              And when i run samples from serial monitor everything works fine

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 8 Feb 2018, 13:54 last edited by
                #7

                To be honest, I don't know how to help. Last time I used Arduino was a few years ago, I don't remember encountering similar issues.

                (Z(:^

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Kira
                  wrote on 8 Feb 2018, 13:56 last edited by
                  #8

                  @sierdzio :Can you please share any code, if available so that i can check the scenario with it.
                  Actually the same problem is observed in qt's examples so don't know how to proceed.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 8 Feb 2018, 13:57 last edited by
                    #9

                    Hi @Kira :

                    And one more thing when i try to run the application by keeping the baud rate as 1200
                    It gives me error of the serial port.

                    You will need to show us more (initialization) code and the exact error message here...

                    void MainWindow::writeData(const QByteArray &data)
                    {
                    serial->flush();
                    serial->write(data);
                    }

                    Note: serial->flush() is not needed in most cases (the documentation also states this).

                    And if, then it would be more useful to have it after the serial->write(data);.

                    Can you verify that the data you send arrives at the Arduino?

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    1
                    • K Offline
                      K Offline
                      Kira
                      wrote on 8 Feb 2018, 14:01 last edited by
                      #10

                      @aha_1980 : You can refer to the terminal example in the qtcreator's example list
                      I am using the same example.
                      And i am using arduino leonardo, it program is in the given link.
                      Please let me know of any other detail if required

                      A 1 Reply Last reply 8 Feb 2018, 14:19
                      0
                      • K Kira
                        8 Feb 2018, 14:01

                        @aha_1980 : You can refer to the terminal example in the qtcreator's example list
                        I am using the same example.
                        And i am using arduino leonardo, it program is in the given link.
                        Please let me know of any other detail if required

                        A Offline
                        A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on 8 Feb 2018, 14:19 last edited by
                        #11

                        @Kira

                        You will need to show us [...] the exact error message here...

                        Can you verify that the data you send arrives at the Arduino?

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Kira
                          wrote on 8 Feb 2018, 14:36 last edited by
                          #12

                          @aha_1980 : I was searching on internet and came across an topic which co-relates to my issue.
                          Please have a look on the given link:
                          https://stackoverflow.com/questions/31560694/qt-serial-port-not-working

                          The serial error which i get when i connect with baud rate 1200 is as follows:

                          Critical Error: The I/0 operation has been aborted because of either a thread exit or an application request.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 8 Feb 2018, 21:32 last edited by
                            #13

                            Hi,

                            You should connect the errorOccured signal of your serial port and handle QSerialPort::ResourceError which would likely be close the port and open it again. Note that your arduino serial device might have had its name changed depending on the system.

                            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
                            1
                            • K Offline
                              K Offline
                              Kira
                              wrote on 14 Feb 2018, 04:52 last edited by
                              #14

                              @SGaist : One more thing i tried to communicate the same program using arduino uno and there is no issue with the program it works fine without any error any issue.
                              Currently i am using arduino leonardo for my project and i need to move on with the same device.
                              My python program and serial simulator program works fine with the board without giving any error and this scenario occur with qt program so just not able to figure out where exactly the problem is.

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                Kira
                                wrote on 14 Feb 2018, 09:19 last edited by
                                #15

                                @SGaist : Thanks for your response. I tried to play with the terminal examples in qt example set and got the stuff working.
                                Following are the observations:

                                1. First you have to configure the port in the settings and set the flow control to RTS/CTS.
                                  Earlier was set to noflowcontrol.
                                2. Connect the port
                                  3.Disconnect the port
                                  4.Reconnect the port
                                  Note: The above approach implies when arduino is disconnected and reconnected or fresh program is burned into the arduino.
                                  Apart from that only step 1 and 2 was sufficient.

                                In case of Arudino uno only step 1 & 2 were required even after reconnecting and burning fresh program. May be because of the hardware specifications.
                                Wondering why i have to connect, disconnect and again reconnect to get it working and only hardware flow control is working.

                                1 Reply Last reply
                                1
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 14 Feb 2018, 21:33 last edited by
                                  #16

                                  For the control flow, check your Arduino documentation regarding the serial port settings.

                                  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
                                  • K Offline
                                    K Offline
                                    Kira
                                    wrote on 15 Feb 2018, 08:36 last edited by
                                    #17

                                    Ohk thanks a lot

                                    1 Reply Last reply
                                    0
                                    • K Kira
                                      8 Feb 2018, 05:48

                                      Hello i am written a program to send and receive data through serial port.
                                      On arduino there is program which receives the serial data and send some response.
                                      My problem is that when i connect arduino to my pc and send data directly I do not get any response.
                                      But when i open the serial monitor program and send data it works fine. After that when i try to send and receive the data from my program it also work. Irrespective of how many times i restart the program. But when i remove the arduino and connect again I have to go through the same process again.
                                      I am using arduino leonardo

                                      K Offline
                                      K Offline
                                      KerrySelect
                                      wrote on 11 Jan 2019, 13:26 last edited by
                                      #18
                                      This post is deleted!
                                      1 Reply Last reply
                                      0
                                      • J Offline
                                        J Offline
                                        JensenPitt
                                        wrote on 16 Dec 2019, 13:05 last edited by
                                        #19
                                        This post is deleted!
                                        1 Reply Last reply
                                        -1

                                        • Login

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